Jump to content

[WIP] Jebnix - A kOS Alternative


woodywood245

Recommended Posts


// Binary search on an already sorted array of strings for the index of the hit, or return -1 if no hit found:
// assume the following variables exist before starting:
// char needle[] = "some string I'm looking for";
// char *haystack[] is a sorted array of the strings being searched
// int haystackSize is the length of the haystack array.
// int min, max. middle, cmp;
for( min=0, max=haystackSize ;
min <= max || cmp != 0 ;
(cmp<0 ? max = min + middle : min = min + middle) )
{
middle = ((max-min)+1) / 2;
cmp = strcmp( needle, haystack[middle] );
}
if( cmp == 0 ) {
// hit was found at index "middle".
} else {
// hit was not found.
}

Be warned, this is going to be really ugly, and is, admittedly, more of a hack of the language than anything else.


//set needle to "some string I'm looking for".
//declare haystack[].
//set haystackSize to haystack:length.
//declare min.
//declare max.
//declare middle.
//declare cmp.

// OPERATORS IN USE:
// Assignment: both TO and = work.
// Equivalence: both = and == work. I prefer ==.
// Ternary operator: iif(x,y,z) is equivalent to (x ? y : z). I have not implemented this yet, but it is planned, just not listed in the official wishlist. This is really a function built into the language (as opposed to a library function).
// And operator: & and AND both work for boolean and bitwise AND.
// Or operator: | and OR both work for boolean and bitwise OR.
// Not-equal operator: != for not equal.

for set max to haystackSize. min
from 0 to max | cmp != 0
step 0. iif(cmp < 0, set max to min + middle., set min to min + middle.)
{
set middle to ((max - min) + 1) / 2.
set cmp to needle == haystack[middle].
if cmp == 0
{
// hit was found at index "middle"
}
else
{
// hit was not found
}
}

// loop is equivalent to
set max to haystackSize. // commands found before FROM are treated like ordinary commands.
set min to 0. // the last expression before FROM is assigned the expression after FROM.
while min <= max | cmp != 0 // the <= is implied by comparing initial values of min and (max || cmp != 0). This can be changed via a convoluted hack: for min from 0 to min & min < max
{
set middle to ((max - min) + 1) / 2.
set cmp to needle == haystack[middle].
if cmp == 0 // in KerboScript++, booleans and integers are interchangeable. Non-zero is always true, and zero is always false. However, assigning an integer from a true boolean does not guarantee any particular non-zero integer.
{
// hit was found at index "middle"
}
else
{
// hit was not found
}
set min to min + 0. // this cycle isn't wasted, because it's executed in the same cycle as the line below. LOOOONG story.
iif(cmp < 0, set max to min + middle., set min to min + middle.).
}

It's possible. It's ugly as heck and requires quite a few hacks. My parser may know its way around error messages, but all-in-all it's pretty dumb and does as many things statically as possible, mostly in the name of language simplicity. Why anyone would want to do that type of thing in this language, I don't know. All-in-all, I don't recommend it. But like I said, it is possible.

One day, I will build the language to compile to bytecode, but not today. Right now, it just kind of goes with the flow.

So, in short, is the for-loop I designed intended to do this type of thing? No. It's just supposed to be a way to increment through a series of values. It CAN do things that are more complicated than that, but why you'd want it to is beyond me.

By the way:


// infinite for-loop
// equivalent of: for (; { }

for x from x to x { }

// or
for x from true to true { }

// or
for x from 0 to 0 { }

// or... you get the idea

// even better:
while (true) {}

Link to comment
Share on other sites

Woody, are you getting any time to code or is your time spent just answering questions about specifics of a mod that has not yet been released?

"All right, there's a thousand things that have to happen in order. We are on number eight. You're talking about number six hundred and ninety-two." indeed...

Would it be too much to ask that we let woody get on with writing his mod and intensively question him about it *after* release?

Link to comment
Share on other sites

Woody, are you getting any time to code or is your time spent just answering questions about specifics of a mod that has not yet been released?

"All right, there's a thousand things that have to happen in order. We are on number eight. You're talking about number six hundred and ninety-two." indeed...

Would it be too much to ask that we let woody get on with writing his mod and intensively question him about it *after* release?

It's much harder to change something after it's already been finished. If the designer has a major misunderstanding about something rather important, for example thinking that this type of for loop covers 100% of all the same cases that for loops in any other language do, the time to clear that up is not *after* the implementation is done.

Woodywood has made it clear in the most recent post now that he does in fact understand that this loop is not as versitile as the loops in the languages he mentioned, but that this is okay and it's an intentional design goal.

That was NOT what it looked like in the earlier post, where he claimed this style of loop does all the same stuff that the for loops in other languages do. That would have been a pretty big design error if that's what his actual intention was. If that's not really his intention after all then it's less of a problem.

And no, the right time to hash this stuff out is NOT later on after it's already been decided.

Link to comment
Share on other sites

Woody, are you getting any time to code or is your time spent just answering questions about specifics of a mod that has not yet been released?

In short, no, I haven't had any time to code over this last week.

The FOR loop isn't on my current list of things to be coded. I design each component in five phases: conceptualizing, preliminary design, detailed design, coding, and testing.

Testing: WHILE loops

Currently coding: Input/Interrupts

Detailed design: Static/dynamic arrays

Preliminary design: FOR loops and FOREACH loops

Conceptualizing: Basic encapsulation

Either way, I hadn't exactly planned on hammering out a detailed specification of the FOR loop quite yet, which is why it sounds like it's all over the place and this is now the only place I have anything written down for it. The way I look at it, unless it's coded AND written in the official documentation AND in the final release, it's not set in stone.

In fact, there are things I'm adding that aren't in the list on the first post, because they are so far down the line that it will be a few weeks before I get to it.

This is the thing:

I'm adding for loops. I'm HOPING to make them work like C-style loops, and if you really go crazy and want them to, they probably can. That's not what they're designed for though, and you can tell simply from the syntax that its whole job is to increment in various ways through a set of numbers. KerboScript has always been a "toy" language designed to make rockets fly, that's easy enough for anyone to pick up. Everyone should just be happy with the idea that for loops are going to be included.

Arguing over which language to implement, and arguing over the detailed implementation of a feature that is two weeks away from implementation just wastes your time and mine, and delays the release of this mod.

"All right, there's a thousand things that have to happen in order. We are on number eight. You're talking about number six hundred and ninety-two." indeed...

Would it be too much to ask that we let woody get on with writing his mod and intensively question him about it *after* release?

Link to comment
Share on other sites

Spring break is upon us, and so that means I'm taking a big break from everything, including writing this mod. Alas, I have another project that is far more demanding of my time and energy that I must work on this week: planning my wedding. Therefore, I shall continue work again next week.

I likely will not be responding to things on the thread until the weekend, but I will be answering PMs.

Thanks for your support everyone!

Link to comment
Share on other sites

I'm adding for loops. I'm HOPING to make them work like C-style loops, and if you really go crazy and want them to, they probably can.

Not with what you've proposed.

Arguing over which language to implement, and arguing over the detailed implementation of a feature that is two weeks away from implementation just wastes your time and mine, and delays the release of this mod.

I'm sorry if I came off that way. You can design it however you like. My motivation was less to tell you how to implement it and more to get you to stop spreading misinformation about some other programming languages that I really like. The claim that the for loop in C, C++ and Java is incapable of doing things beyond the simple counter mechanism that for loops tend to be used for in other languages is very false. And it matters because the for loop in C/C++/java tends to be a bit less structured and formal and therefore can be a bit sloppy and error-prone. It would look like bad language design if it was made that sloppy with no benefit. Therefore hand-waving away that benefit and pretending it doesn't exist is unfair.

I wasn't telling you how to write your language. I was defending other languages I like from false claims.

Edited by Steven Mading
Link to comment
Share on other sites

Alas, I have another project that is far more demanding of my time and energy that I must work on this week: planning my wedding.

Real life can really get in the way of KSP time :D Good luck and have fun.

Link to comment
Share on other sites

Spring break is upon us, and so that means I'm taking a big break from everything, including writing this mod. Alas, I have another project that is far more demanding of my time and energy that I must work on this week: planning my wedding. Therefore, I shall continue work again next week.

I likely will not be responding to things on the thread until the weekend, but I will be answering PMs.

Thanks for your support everyone!

Congratulations on your upcoming wedding!

Link to comment
Share on other sites

  • 2 weeks later...

Well, I put in a little bit of work tonight, mostly to do with what I was working on before break. I leave you, however, with a feature that I finished a few weeks ago, and I'm quite happy with: simplified plugin function registration.

The old kOS function registration looked something like this:

vessel.parts.ForEach(part => part.SendMessage("RegisterkOSExternalFunction", new object[] { "test", this, "TestFunction", 0 }));

I hated it. It was long, unreadable, and nightmarish.

This is the new function registration method:

Functions.RegisterFunction("test", 0, new Func<string>(TestFunction));

This utilizes a static function in Jebnix.Functions. The Functions class stores all functions that are registered with Jebnix inside a Dictionary, using a unique name and a Delegate.

The RegisterFunction function syntax is:

public static bool RegisterFunction(string name, int paramCount, Delegate ptr)

where:

name - Script-side function name

paramCount - the number of parameters the function has

ptr - A Delegate that points to your function

By the way, you can call other external functions from your plugin. This is how the standard library works!

Here's a full class that I use to test this:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Jebnix;
using Jebnix.stdlib;
using Jebnix.Types;

namespace ExternalFunctionTest
{
public class Class1
{
const string TEST_NAMESPACE = "test";

public Class1()
{
Functions.RegisterFunction("test", 0, new Func<string>(TestFunction));
Functions.RegisterFunction("librarytest", 1, new Action<Value>(LibraryPrintTest));
Functions.RegisterFunction("getnumber", 0, new Func<double>(GetNumber));
Functions.RegisterFunction("externaltest", 0, new Action(ExternalCallTest));
}

/// <summary>
/// Returns "This is a test function."
/// </summary>
/// <returns></returns>
public string TestFunction()
{
return "This is a test function.";
}

/// <summary>
/// Prints "This is a library test." to the screen via stdio, along with the string value given.
/// </summary>
public void LibraryPrintTest(Value value)
{
stdio.PrintLine("This is a library test. " + value.StringValue);
}

/// <summary>
/// Prints "This is an invocation test" to the screen via the registered function "stdio_println_1".
/// </summary>
public void ExternalCallTest()
{
Functions.InvokeMethod(Functions.STDIO, "println", "This is an invocation test.");
}

/// <summary>
/// Returns the number 10.
/// </summary>
/// <returns></returns>
public double GetNumber()
{
return 10;
}
}
}

Link to comment
Share on other sites

I have a random question for those of you that have modded before. I have the thought of using an existing DLL that I wrote a few years back as part of this project, in order to make things a lot easier. This is the problem: the code for that project is closed-source. Obviously, as I wrote it, I could easily make it open-source, but I'd rather not.

Does anyone know if I can use the library in question, or will I have to make portions of it open-source?

Link to comment
Share on other sites

Does anyone know if I can use the library in question, or will I have to make portions of it open-source?

The short answer is no, as your mod falls in the plugin category and these rules apply.

Sorry, that means you have to provide the sourcecode for any part of it.

If you can make the sourcecode for just the portion of that DLL that goes in the plugin, that's fine, as long as anybody may have a successful compile of your plugin from the sourcecode provided, without need to link to your closed DLL.

Link to comment
Share on other sites

The short answer is no, as your mod falls in the plugin category and these rules apply.

Sorry, that means you have to provide the sourcecode for any part of it.

If you can make the sourcecode for just the portion of that DLL that goes in the plugin, that's fine, as long as anybody may have a successful compile of your plugin from the sourcecode provided, without need to link to your closed DLL.

Alrighty, thanks! If I use a portion of my external library, I will probably make that portion open-source.

Link to comment
Share on other sites

  • 4 weeks later...

A few major life changes have gotten in the way of working on this project over the last few weeks, but I'm back at it again. I'm currently performing a major rewrite of the type system by doing away with the Value class and creating several new classes that essentially act as wrappers around the .Net types. I'm not sure if this concept is going to work, so I've split the code into a branch specifically for this rewrite. The rewrite will not affect the language design. It will allow for a broadened ability to use custom types and structures.

Types will have functions associated with them that will be able to be called directly from the language. Types will also have properties that can be accessed the same way. The same goes for structures.

The new Jebnix classes will be:

  • JObject - Abstract class representing all value types
  • JObject<T> - Abstract class for single-value types
  • ValueArray - Inherits JObject and ICollection<JObject>, represents a collection of JObjects.
  • JBoolean - Inherits JInteger, represents a boolean type
  • JFloat - Inherits JObject<double>, represents a double-precision floating-point.
  • JInteger - Inherits JObject<int>, represents an integer
  • JString - Inherits JObject<string>, represents a string
  • OrderedPair - Inherits JObject, represents an ordered pair structure

Obviously, more structures, like Vector, Rotation, Quaternion, Heading, Body, etc, etc will be available upon release.

Link to comment
Share on other sites

A few major life changes have gotten in the way of working on this project over the last few weeks, but I'm back at it again.

While reading the first part of your post (and after almost a month without updates), I had a feeling you were going to leave this project. Really glad instead to find you are back :).

Link to comment
Share on other sites

Beautiful thread :) I also hope that it will be possible to integrate the functionality into probe cores, since some people including me are reluctant having crafts that are depending on mod parts.

Also, liking the idea of an auto-pilot that is not considered as cheating because you can write the script yourself, which is obviously more fun :)

I have heard several lectures about compiler design and software engineering, too bad that I have never learned C# or KSP modding...

Link to comment
Share on other sites

I've got a question that I've been bouncing around in my head for the last few weeks: how important is it to everyone to have an interactive/immediate mode in Jebnix?

Personally, I virtually never do anything in kOS that isn't already coded in a file somewhere, so the most I do in the console is use the RUN command.

I've been thinking about getting rid of the interactive mode in Jebnix and replacing it with a small set of utilities. What does you think?

Link to comment
Share on other sites

I am working on a part for the Open Part Mod that I thought would work really well as a kOS/Jebnix module. Some of you may even recognize what I got the inspiration from!

(You can ignore the artifacts on the ribbon cable, those are a product of double-sided polygons which KSP does not have)

QfJocln.png

Link to comment
Share on other sites

I've been thinking about getting rid of the interactive mode in Jebnix and replacing it with a small set of utilities. What does you think?

I typically use it to work out how commands are supposed to work exactly. Having to go back and forth to a file can be tiresome when just trying permutations of a line until you get it right.

Link to comment
Share on other sites

I typically use it to work out how commands are supposed to work exactly. Having to go back and forth to a file can be tiresome when just trying permutations of a line until you get it right.

Would a combination of good documentation and a built-in editor with a "Run Now" button help?

Link to comment
Share on other sites

Would a combination of good documentation and a built-in editor with a "Run Now" button help?

Good documentation certainly helps (although I seem to invariably wrestle with unfamiliar commands). As an avid IDE user, a built in editor feels a bit redundant, although any form of quickly running a command would be helpful of course :)

I will typically just stuff a couple of permutations of a command into the console until it stops spitting errors - let's call it educated brute forcing. I am not saying that is the ideal or only solution, but I seem to do that in other languages too. I must admit I have been very busy lately, so things might have changed without me noticing.

Link to comment
Share on other sites

Good documentation certainly helps (although I seem to invariably wrestle with unfamiliar commands). As an avid IDE user, a built in editor feels a bit redundant, although any form of quickly running a command would be helpful of course :)

I will typically just stuff a couple of permutations of a command into the console until it stops spitting errors - let's call it educated brute forcing. I am not saying that is the ideal or only solution, but I seem to do that in other languages too. I must admit I have been very busy lately, so things might have changed without me noticing.

The primary reason I've been toying with the idea of getting rid of the interactive mode is that I've also been toying around with the idea of changing the language from interpreted to compiled. It would significantly simplify the project, as writing an interpreter is like writing a compiler that must track program state at the same time, and it can get ugly for certain things. I have a lot of more experience writing virtual machines and compilers than writing interpreters, and while this project is going as well as I hoped, I'd like it to be finished sooner rather than later. While the kOS situation has improved with other projects, the complete and utter lack of good documentation on those projects is driving me up the wall. I think I'd rather run my own system.

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...