🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Script Engine question

Started by
3 comments, last by stflo 21 years, 3 months ago
I''ve been working on a scripting engine and something kind of confuses me. Right now the source code is tokenized then parsed into a nice syntax tree with the help of a symbol table, then converted into bytecode before finally passed to a virtual machine (nothing unusual). But it''s seems to me like a waste to convert the syntax tree into bytecode. I know this is necessary when compiling a real programming language into machine language, but in my case wouldn''t be as efficient to build a virtual machine that can read the syntax tree directly? I might even be faster, since it wouldn''t require a stack. I would also make control structures and functions a lot easier to handle. Overall it wouldn''t be hard to implement. All the tutorials I''ve read convert the scripts to bytecode, which is why I''m hesitating. Tell me what you think, thanx.
Advertisement
Bytecode can be cached, which is useful for loops or any other situation where the code is executed more than once.
If the VM executes the syntax tree, it will be imposible(without some serious asm trickery) for the VM state to be savable & loadable. Nor can you pause execution of the script, without pausing the thread the script is hosted in.

Since you cant pause & resume the script without using threads, this will seriously complicate how your scripts are biuld.

Also using this design, it is posible for the script to hang your game by getting stuck in an infinite loop.

Think of it being similar to using blocking & non-blocking IO.

If the VM is blocking, the script MUST be writen as non-blocking or it will hang the app.

If the VM is non-blocking, it doesnt matter if the script is non-blocking or blocking.

[edited by - ggs on March 21, 2003 8:20:40 AM]
Executing a syntax tree would most likely require some form of recursion, but you can execute bytecode with a simple loop which will generally be faster. For simple expressions, it won''t make any real difference, but for complex ones it can make a huge difference.

Also, on flipcode ''code of the day'' there are some libraries that let you create actual machine code, which you could use instead of byte code to make your langauge really fast =-)
"Walk not the trodden path, for it has borne it's burden." -John, Flying Monk
thanks, i''ll just stick to bytecode then.

This topic is closed to new replies.

Advertisement