Lua.Compiler.Bytecode (Lua v1.0.0-rc.3)
View SourceBytecode encoder for Lua.Compiler.Prototype.
Walks the structured instruction stream of a prototype and emits a dense
tuple-of-tuples encoding suitable for Lua.VM.Dispatcher. Integer opcode
tags occupy slot 1 of each opcode tuple; operands follow in fixed slots.
Returns {:ok, prototype} with bytecode populated when every instruction
in the prototype falls within the dispatcher's coverage. Returns
:fallback the first time an uncovered opcode is encountered — the caller
keeps the prototype as-is, and the interpreter handles it.
Sub-prototypes are compiled independently. A parent that contains an uncovered opcode falls back to interpretation even when its sub-prototypes successfully compile, and vice versa.
Summary
Functions
Compile a prototype, populating its bytecode field on success.
True when proto and every prototype nested within it carry a bytecode
encoding — i.e. nothing in the tree fell back to the interpreter.
Functions
@spec compile(Lua.Compiler.Prototype.t()) :: Lua.Compiler.Prototype.t()
Compile a prototype, populating its bytecode field on success.
Sub-prototypes are compiled recursively; each is independent. A failure in one sub-prototype does not block another from being compiled.
The parent prototype only gains a bytecode encoding if every instruction in its own body is supported. If the parent falls back, sub-prototype encodings are still preserved on the children.
@spec fully_compiled?(Lua.Compiler.Prototype.t()) :: boolean()
True when proto and every prototype nested within it carry a bytecode
encoding — i.e. nothing in the tree fell back to the interpreter.
Use this after compile/1 to assert dispatcher coverage. A false result
means at least one prototype contains an opcode the encoder still rejects
(today: :goto / :label).
@spec op_load_constant() :: pos_integer()