When designing a byte code interpreter, is there a consensus these days on whether stack or three address format (or something else?) is better? I’m looking at these considerations:
-
The objective language is a dynamic language fairly similar to Javascript.
-
Performance is important, but development speed and portability are more so for the moment.
-
Therefore the implementation will be strictly an interpreter for the time being; a JIT compiler may come later, resources permitting.
-
The interpreter will be written in C.
Take a look at the OCaml bytecode interpreter – it’s one of the fastest of its kind. It is pretty much a stack machine, translated into a threaded code on loading (using the GNU computed goto extension). You can generate a Forth-like threaded code as well, should be relatively easy to do.
But if you’re keeping a future JIT compilation in mind, make sure that your stack machine is not really a full-featured stack machine, but an expression tree serialisation form instead (like .NET CLI) – this way you’d be able to translate your “stack” bytecode into a 3-address form and then into an SSA.