2 ms·
At the heart of the Lua and Python interpreters, there's an evaluation function, written in C, that does something like this: void evaluate() { whi
by ufo 2y ago
At the heart of the Lua and Python interpreters, there's an evaluation function, written in C, that does something like this:
void evaluate() {
while (1) {
instr = get_next_bytecode_instruction()
switch(instr.type) {
// run the instruction
}
}
}
The question is how to run a CALL bytecode instruction. One way is to use the C stack: call evaluate() recursively. The other way is to have the interpreter maintain its own call stack and the CALL instruction is responsible for updating said call stack. This way the interpreter stays in the same while(1) loop the whole time.
Using the C stack can be faster, because you take advantage of the native instruction pointer & return address instead of emulating them in C. But it can also be slower if calling evaluate() is slow.