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-codere-exports it so codegen and the VM share one definition.OpCode::from_u32is the canonical decoder. TODO(multiversion, Step 0 deferred): thisOpCodeis a DUPLICATE of the canonical one inlua-code/src/opcodes.rs:87. The Step-0 plan wanted them consolidated to one owner (lua-code) withlua-vmdepending on it, but that creates a DEPENDENCY CYCLE:lua-code/Cargo.tomlalready depends onlua-vm, solua-vmcannot depend back onlua-code. Consolidating therefore requires moving the canonicalOpCode/OP_MODES/Instructiondefinitions DOWN intolua-types(whichlua-types/src/opcode.rsalready reserves) and pointing bothlua-vmandlua-codeat it — plus reconciling variant-name skew between the two copies (lua-vmusesBXOrK/BXOr,lua-codeusesBXorK/BXor;lua-vmalso hasLoadKx/GetUpvalaliases) and theInstructionExtdecode 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) vslua-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
OpModefor 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->topas 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->topfor the next instruction (C == 0 case). - test_
t_ mode - True if this opcode is a test (the next instruction must be a jump).