By default, NTGML compiles instructions for a stack-based virtual machine
So, for example, the following
function scr_test() { var i = 1; i += 2; return i; }
would output instructions along the lines of
push(1) local.i = pop() push(local.i) push(2) add() local.i = pop() push(local.i) return
The good thing about this approach is that the VM can do just about anything that "real" GML can do and a few other tricks too (like the wait operator).
The bad thing about this approach is that GML is a dynamically typed language so doing high-performance tasks like this in it isn't The Best.
As the first line of defense, the recent versions of NTGML will merge common sequences of instructions into one larger instructions, so if you do /debugbc
and run the above program, a .gmlbc
file next to the mod will spot something like the following:
#define scr_test // locals: { 0: "i" } 0 L2 c6 { tag : "local = const", val : 1, ind : 0, name : "i" } 1 L3 c4 { tag : "local += number", ind : 0, name : "i", num : 2, op : 16 } 2 L4 c9 local_hx(i: 0, name: "i") 3 L4 c2 return_hx
As you can see here, both i = 1
and i += 2
were merged into specialized instructions, which helps a bit with computationally intense code.
But still that's not enough, which brings us to...