Lua.Compiler.Bytecode (Lua v1.0.0-rc.0)

View Source

Bytecode 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(proto)

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.

op_add()

op_call_one()

op_divide()

op_equal()

op_floor_divide()

op_get_field()

op_get_global()

op_get_upvalue()

op_greater_equal()

op_greater_than()

op_less_equal()

op_less_than()

op_load_boolean()

op_load_constant()

@spec op_load_constant() :: pos_integer()

op_load_env()

op_load_nil()

op_modulo()

op_move()

op_multiply()

op_negate()

op_not()

op_not_equal()

op_power()

op_return_one()

op_return_zero()

op_source_line()

op_subtract()

op_test()