Node:Dispatch, Previous:Data handling, Up:Concepts
Understanding this section is probably not necessary for using Vmgen, but it may help. You may want to skip it now, and read it if you find statements about dispatch methods confusing.
After executing one VM instruction, the VM interpreter has to dispatch
the next VM instruction (Vmgen calls the dispatch routine NEXT
).
Vmgen supports two methods of dispatch:
switch
statement, with one case
for each VM instruction. The VM
instruction opcodes are represented by integers (e.g., produced by an
enum
) in the VM code, and dispatch occurs by loading the next
opcode, switch
ing on it, and continuing at the appropriate
case
; after executing the VM instruction, the VM interpreter
jumps back to the dispatch code.
Threaded code can be twice as fast as switch dispatch, depending on the interpreter, the benchmark, and the machine.