More Language Design

Posted by ludamad on April 8, 2009, 6:41 p.m.

I've decided that my code is going to be interpreted using bytecode, which will be a lot faster than my previous plan of using Abstract Syntax Trees.

Here's a tentative feature:

Subfunctions:

function Main()

{

subfunction SetAto3()

{

a = 3;

}

SetAto3();

print(a);//prints '3'

}

Here's the basics of the keyword 'subfunction':

-It must be nested in a function or subfunction

-Subfunctions cannot be stored in variables like normal functions, because they are not called like regular functions (they instead share stack variables with their parent functions, they must know their parent functions at compile-time).

-Normal functions can be nested in functions and subfunctions. These can be stored in variables.

Generators:

A little bit the opposite of subfunctions, generates instead of sharing a stackframe create one completely for themselves.

Generators are very different compared to normal functions, calling them does nothing but return a value, and what they return is used as a function

generator GenerateMemoizer(function)(args){

a = {};

while (True){

if ( a[args] == Null )//if it isn't in the map

a[args] = Call(function, args);

yield a[args];//after the yield, args is updated by more input

}

}

The syntax here is a bit confusing. There are essentially two sets of arguments, one for the generator, and one for the array of arguments passed to the generated function. yield value; is like return except the generated function still exists after it. It merely waits till the next call.

One might use this with, for example:

generatedFunc = GenerateMemoizer(SomeFunction);

generatedFunc(arguments, we, would, pass, to, SomeFunction);//they are stored in an array called 'args' in the generated function

Finally, the Call function is a builtin that calls a function that allows for calling to functions by using an array as the argument list.

Comments

Rez 15 years, 7 months ago

Args are for pirates. Seriously though, you're doing God's work, luda. thumbsup.gif

TDOT 15 years, 7 months ago

Even though some of this is a bit over my head, I love reading about your language dev :D

Can't wait to see something made with it.

Cpsgames 15 years, 7 months ago

I like how you're approaching this. Looks like a good method, hope it all goes well.

Xxypher 15 years, 7 months ago

What are you hoping to achieve with this code?

Also, I have grown to hate you. I am not kidding.

ludamad 15 years, 7 months ago

With this code? You mean this language? I'm developing it for a game based on AI scripting.

Xxypher 15 years, 7 months ago

Nice.

sirxemic 15 years, 7 months ago

For some reason your language only makes sense for a part… For example, I don't get it why you are adding specific 'subfunctions'. But if you want, please tell me why you chose to implement that.