You can implement them with a jump table, so the interpreter is fast (typically 50% native speed or more). Bytecodes are instruction sets for virtual stack machines where each opcode is one byte. Compiling the AST to bytecode and interpreting the bytecode. It's very slow, because something like 'a = b' involves three AST nodes and so you need at least three function calls for a trivial assignment. This is how JavaScript was implemented in browsers until a couple of years ago. Whenever you run a bit of code, you do a traversal of the tree and execute each node in turn.
0 Comments
Leave a Reply. |