Making a JIT interpreter with LuaJIT
rjpower.org
rjpower.org
> Still, it’s somewhat surprising how easy it was to generate our ‘JIT’ interpreter — the code isn’t much bigger then the original version. Perhaps with some more scaffolding/helper libraries, this could be a viable way to create fast interpreters for new languages?
This is one of the many things that Terra excels at and is intended for: http://terralang.org/ I'm personally using it for dynarecing code in emulators now; works great.
This seems like a fairly useful technique, provided the given bytecode file isn't terribly big (since you're uh...converting it into string representation), and that the bytecode isn't some run-once-throw-away code, otherwise you spend more time converting it into Lua code and JIT-ing it.
Having said that, I wonder if it'd be even less of a hassle by skipping the bytecode part. Just transpile the source written in your custom language straight into Lua code, and have that code JIT'ed instead. Many high level structures/information would be preserved, allowing JIT to do an even better job perhaps?
In this case, the bytecode is what you start with :)
Going straight from a parse tree to Lua could work, but locks you into the possibly slow code-generation approach. Having an intermediate level (high level bytecode, or even an interpreter over the AST) would be more flexible -- you could choose when to switch over the compiled version.