3 ms·
Ast will usually include original/runtime names and need recursion where the bytecode is mostly flat. For example for an assignment you'll have ast like (assig
by viraptor 8y ago
Ast will usually include original/runtime names and need recursion where the bytecode is mostly flat.
For example for an assignment you'll have ast like (assign (foo 5)). This will have to look up "assign", run it, look up "foo" in the frame, and assign 5 to it. All of that will operate on pointers to different parts of the heap and kill your CPU cache too.
With bytecode, a lot of it will be already reduced to (for example) a machine with stack, so the assignment will be closer to: read the op (jump address in an array, so already in cache), dispatch via a small lookup table, put 5 in slot 2 (names already rewritten to stack indices) in the current frame.
- hyperpallium 8y agoThanks, cache locality makes sense. Though for looking up operators/keywords etc, preprocessing this step doesn't feel like cheating to me (though strictly, it's something more than an AST).
- mamcx 8y agoI'm thinking how viable is marry both. Make flattened AST that still allow to keep the easy of an AST walker yet with more dense representation?
- munificent 8y agoThat's basically what bytecode is. :) You can think of a stack-based bytecode as basically an in-order serialization of a tree.
- mamcx 8y agoBut byte code "destroy" the control flow/memory model of the host, and is necessary to recreate it with GOTOS and stacks or registers?
- tekknolagi 8y agoSo you want bytecode + CFG?
- mamcx 8y agoProbably. One thing with an AST walker is that the "walker" part come for free. Your control flow need minimal to none conversion and could leverage the host for it. With byte code, some stuff look easier and the performance boost is nice, but need to commit fully to become an "abstract machine". Thats cool if the host language not match the control flow you want, but is extra work otherwise.