Skip to main content

Module opcodes

Module opcodes 

Source
Expand description

Opcode definitions and instruction encoding/decoding for the Lua 5.4 VM.

C source: reference/lua-5.4.7/src/lopcodes.c (the luaP_opmodes table) and reference/lua-5.4.7/src/lopcodes.h (the OpCode/OpMode enums, field-size constants, and instruction accessor macros — the header merges into this file, per PORTING.md §1).

Structs§

Instruction
A single Lua bytecode instruction (unsigned 32-bit word).

Enums§

OpCode
The opcode enum is owned by lua-vm (the VM hot path decodes against it directly); lua-code re-exports it so codegen and the VM share one definition. OpCode::from_u32 is the canonical decoder. TODO(multiversion, Step 0 deferred): this OpCode is a DUPLICATE of the canonical one in lua-code/src/opcodes.rs:87. The Step-0 plan wanted them consolidated to one owner (lua-code) with lua-vm depending on it, but that creates a DEPENDENCY CYCLE: lua-code/Cargo.toml already depends on lua-vm, so lua-vm cannot depend back on lua-code. Consolidating therefore requires moving the canonical OpCode/OP_MODES/Instruction definitions DOWN into lua-types (which lua-types/src/opcode.rs already reserves) and pointing both lua-vm and lua-code at it — plus reconciling variant-name skew between the two copies (lua-vm uses BXOrK/BXOr, lua-code uses BXorK/BXor; lua-vm also has LoadKx/GetUpval aliases) and the InstructionExt decode trait that lives here. That is a larger refactor than the Step-0 scaffold; deferred to keep 5.4 green. Duplicate sites: lua-vm/src/vm.rs:45 (this enum) vs lua-code/src/opcodes.rs:87 (canonical).
OpMode
Instruction addressing mode.

Constants§

LFIELDS_PER_FLUSH
Number of list items to accumulate before a SETLIST instruction.
MAXARG_A
MAXARG_AX
MAXARG_B
MAXARG_BX
MAXARG_C
MAXARG_S_J
MAXINDEXRK
Maximum RK index (for debugging only).
NO_REG
Sentinel “no register” value that fits in 8 bits.
NUM_OPCODES
Total number of opcodes.
OFFSET_S_BX
OFFSET_S_C
OFFSET_S_J
POS_A
POS_AX
POS_B
POS_BX
POS_C
POS_K
POS_OP
POS_S_J
SIZE_A
SIZE_AX
SIZE_B
SIZE_BX
SIZE_C
SIZE_OP
SIZE_S_J

Functions§

get_op_mode
Extract the OpMode for an opcode.
int_to_s_c
Encode a signed integer into an unsigned C-field value.
s_c_to_int
Decode a C-field unsigned value to a signed integer.
test_a_mode
True if this opcode writes to register A.
test_it_mode
True if this opcode uses L->top as set by the previous instruction (B == 0 case).
test_mm_mode
True if this opcode is a metamethod call.
test_ot_mode
True if this opcode sets L->top for the next instruction (C == 0 case).
test_t_mode
True if this opcode is a test (the next instruction must be a jump).