On 15/05/2016 9:57 PM, Martin Nowak wrote:
On 05/15/2016 01:58 PM, Daniel Murphy wrote:
The biggest advantage of bytecode is not the interpreter speed, it's
that by lowering you can substitute VarExps etc with actual references
to memory without modifying the AST.
By working with something lower level than the AST, you should end up
with something much less complex and with fewer special cases.
Which is a bad assessment, you can stick variable indexes into
VarDeclaration (we already do that) and thereby access them in O(1).
Converting control flow and references into byte code is far from
trivial, we're talking about another s2ir and e2ir here.
For simple types that's true. For more complicated reference types...
Variable indexes are not enough, you also need heap memory, but slices
and pointers (and references) can refer to values either on the heap or
the stack, and you can have a slice of a member static array of a class
on the stack, etc. Then there are closures...
Neither e2ir or s2ir are actually that complex. A lot of the mess there
comes from the backend IR interface being rather difficult to work with.
We can already save a big chunk of complexity by not having to
translate the frontend types. E.g. implementing the logic in the
interpreter to correctly unwind through destructors is unlikely to be
simpler than lowering to an IR.