Convert nested interpreter calls into a single loop #20
Previously, each frame of a Lua function was run in its own interpreter. While this made the implementation simpler (and possibly more elegant), it did mean the Lua stack depth was bound by Java's (which wasn't very high, due to the 3-4 calls needed to execute a function).
Instead, we convert an interpreter into a nested loop, with the outer one setting up the function from the current frame, and the inner one acting mostly the same as before. However, instead of using
We don't currently support running metamethods inside the same interpreter, but I think that is acceptable - Lua is the same, and it would mean we have to inline most of
As far as performances goes, it's rather hard to tell. I've tried to run an awful lot of benchmarks, but they're a) hazy at best and b) some have improved, some have got worse. It appears that call-heavy code has become worse, though I'm not entirely sure why - it's something I'd like to resolve before merging, but is not entirely a blocker.
Our value of Short.MAX_VALUE is pretty arbitrary, but is pretty close to Lua's limit with an average-large (30) number of variables.
While we may lose out on some performance gain from them previously being intrinsics, the throwing of ArithemticException was causing serious performance regressions in very specific code paths. The included code (primes.lua) would cause an overflow (throwing an exception), and then modulus it (making it wrap back to an integer again). As a result, this code ran in over 14s (almost instantly after this patch and on master).
A wee bit ugly, but should still be faster than coercing to and from a double.