Re:Which Interpreters Are Faster, AST or Bytecode?
by rightbyte on Friday October 20, 2023 @08:19AM
(#37955102)
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.
[ Parent
| on HN ]
Re:Which Interpreters Are Faster, AST or Bytecode?
by infradig on Friday October 20, 2023 @09:52AM
(#37956004)
It's called a flattened AST.
Re:Which Interpreters Are Faster, AST or Bytecode?
by lapinot on Friday October 20, 2023 @08:05PM
(#37962845)
Afaik 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