Expand description
Opcode definitions and instruction encoding/decoding for the Lua 5.4 VM.
Ports src/lopcodes.c (the luaP_opmodes table) and src/lopcodes.h
(the OpCode/OpMode enums, field-size constants, and instruction
accessor macros). Per PORTING.md §1, headers merge into their consuming
.rs.
C source preserved inline as `
Structs§
- Instruction
- A single Lua bytecode instruction (unsigned 32-bit word).
Enums§
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).