4 ms·
You can more or less massage an AST walker into being a bytecode VM. Just place the function pointer in the node together with its fields and write all the node
by rightbyte 3y ago
You can more or less massage an AST walker into being a bytecode VM. Just place the function pointer in the node together with its fields and write all the nodes to an array in some likely execution order. You now got bytecode but with function pointers as opcodes.
- infradig 3y agoIt's called a flattened AST.
- lapinot 3y agoAfaik the important difference between "ast walker" and "bytecode vm" is that the former is recursive, that is, it will more or less use the host call-stack as user call-stack, while a bytecode vm manages its own datastructures and is basically a while loop. But you can definitely go from a recursive interpreter to a bytecode vm by doing a CPS transform of your interpreter and defunctionalizing it. See eg https://dl.acm.org/doi/10.1145/888251.888254 https://dl.acm.org/doi/10.1145/888251.888254