Working on a new language engine for microScript v2
I have been working on microScript v2 this week. I wanted to validate the general principle of a new microScript engine, which works as an interpreter, based on a stack machine and an intermediate language representation. I started doing some benchmarks to check whether I was getting good performance. From the start, the performance was quite good (much better than microScript v1 interpreter) but still significantly behind transpiled microScript v1. I worked on it, made many smaller optimizations... until I realized one possible optimization was to mix interpreted instructions with transpiled chunks of code, without losing the benefits of the new engine architecture (I will detail some of the benefits below).
The final result is that the engine is working beautifully. microScript v2 will not be exactly as fast as transpiled v1, but it will be very close (actually, on FireFox it is slightly faster! But not on Chrome). The language itself should include all of microScript v1 (thus your existing projects are ready for it!), with a few new language features (binary operators, multi-line comments, type checking...)
The benefits of the new architecture will be:
- no more "timeout" restrictions ; you can write and run code computing for minutes or forever without problem
- opens the possibility to pause execution for a certain amount of time, like a
sleepfunction, e.g. waiting 1 second before doing something. This has been requested a lot.
- opens the possibility to run threads or coroutines for parallel tasks
- opens the possibility to set breakpoints (for a future step by step debugger)
- opens the possibility to record profiling data (find where most of the CPU time is spent in your code)
- makes it easy to publish your game with obfuscated code (some people asked for this too)
- is a solid foundation for a future native microScript engine written in C or C++
Regarding paused execution, scheduling tasks and threads, I am trying to find a nice syntax. I am considering the following:
sleep(1000) // pauses execution for 1 second in 5000 do // schedules execution of all the enclosed code when the delay of 5 seconds is elapsed callSomeFunction() count += 1 end thread = do // shortcut to start a thread without delay, identical to "in 0 do ... end" makeSomeHeavyComputationInParallel() end thread.pause() // pause the thread thread.resume() // resume the thread thread.stop() // terminate the thread ; the thread cannot be executed anymore
Let me know what you think of all this!