Lua.VM.Dispatcher (Lua v1.0.0-rc.2)

View Source

Hand-written executor over the dense bytecode produced by Lua.Compiler.Bytecode.

The dispatcher exists to test the hypothesis that integer-tagged opcode dispatch over a tuple-encoded instruction stream measurably outperforms the existing list-of-tagged-tuples interpreter. It implements a narrow subset of opcodes — arithmetic, comparison, logical ops, conditional :test, single-result :call, single-value :return, plus the surrounding plumbing (constants, moves, env/upvalue/global lookups). Anything the bytecode encoder rejects keeps its prototype on the interpreter via the bytecode-compiler's :fallback cascade.

Inter-mode calls grow the Erlang stack by one frame at the boundary. Dispatcher → dispatcher chains stay flat through frames. Mixed-mode programs (compiled prototype calling an interpreted one, or vice versa) pay a single recursive call at the transition; the recursion is bounded by the number of mode switches, not the call depth within a single mode.

Summary

Functions

Execute a compiled prototype against args and state.

Execute a compiled prototype with explicit upvalues.

Functions

execute(proto, args, state)

@spec execute(Lua.Compiler.Prototype.t(), [term()], Lua.VM.State.t()) ::
  {[term()], Lua.VM.State.t()}

Execute a compiled prototype against args and state.

execute(proto, args, upvalues, state)

@spec execute(Lua.Compiler.Prototype.t(), [term()], tuple(), Lua.VM.State.t()) ::
  {[term()], Lua.VM.State.t()}

Execute a compiled prototype with explicit upvalues.

Used from the interpreter's :call opcode and from Executor.call_function/3 when the callee is a :compiled_closure carrying upvalue cells.