BlitzScript3D

Blitz3D Forums/Blitz3D Programming/BlitzScript3D

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Today I added function support! Functions now compile perfectly, supporting both Local and Static variables. It supports blitz's style of functions (with or without parenthisis enclosing parameters).

The way it works is actually simple. Before a function is called, all Local variables of the function are "pushed", all the parameter values are "pushed", the execution pointer is pushed to the call stack, and it "jmps" to the function. Within the function, it "pops" the parameters into the function's parameter's variables. When it returns ("pops" the execution pointer off the call stack), it "pops" back all the functions local variables.

I probably didn't explain that very well, but it basically uses the stack to store the parameters, and to restore variables when using recursion techniques.

Unfortunately, I didn't add overloading support. It turns out it wasn't as easy as it seemed. To add function overloading I would have to add a third file parse pass, and I didn't think the advantages of overloadible functions justify the added compile time delay. Currently, one pass reads in variable and type declarations, and the second pass compiles the actual code. I've timed it and it compiles at about 50-70 KB of code per second.

So, it looks like conditional loops like "For..Next", "While..Wend", and "Repeat..Until" are next, then I'll be pretty much done with the compiler, and I'll begin work on the VM :)

skyfire1: Noel says you won't need it probably because he doesn't personally see any use for it. That's perfectly fine, except I would encourage you to research the advantages/disadvantages of a scripting engine in your project. I am making my own scripting engine because I think many aspects of my game would benifit from it greatly (especially AI), in addition to the fun I have programming things like this :)