Complete Bytecode Opcode Reference
An exhaustive guide to every 32-bit instruction opcode emitted by the PyLua code generator and executed by the virtual machine in src/runtime/lvm.c.
1. 32-Bit Instruction Formats
Every instruction is exactly 32 bits wide, encoded into one of four basic formats:
Format iABC: [ B: 8 bits | k: 1 bit | C: 8 bits | A: 8 bits | Op: 7 bits ]
Format iABx: [ Bx: 17 bits unsigned | A: 8 bits | Op: 7 bits ]
Format iAsBx: [ sBx: 17 bits signed | A: 8 bits | Op: 7 bits ]
Format isJ: [ sJ: 25 bits signed jump offset | Op: 7 bits ]
2. Data Movement & Constant Loading
| Opcode |
Format |
Semantics |
Description |
| OP_MOVE |
iABC |
R[A] := R[B] |
Copies the value from virtual register B to register A. |
| OP_LOADI |
iAsBx |
R[A] := sBx |
Loads an immediate 17-bit signed integer directly into register A. |
| OP_LOADF |
iAsBx |
R[A] := (lua_Number)sBx |
Loads an immediate float directly into register A. |
| OP_LOADK |
iABx |
R[A] := K[Bx] |
Loads a constant from the prototype's constant table K. |
| OP_LOADNIL |
iABC |
R[A]..R[A+B] := nil |
Clears a range of \(B+1\) registers to nil. |
| OP_LOADTRUE |
iABC |
R[A] := true |
Assigns boolean true to register A. |
| OP_LOADFALSE |
iABC |
R[A] := false |
Assigns boolean false to register A. |
3. Tables, Upvalues & Environment
| Opcode |
Format |
Semantics |
Description |
| OP_GETTABUP |
iABC |
R[A] := UpValue[B][K[C]] |
Loads a field from an upvalue table (commonly used for global variable access via _ENV[var]). |
| OP_SETTABUP |
iABC |
UpValue[A][K[B]] := RK(C) |
Sets a field in an upvalue table (e.g. _ENV["score"] = 100). |
| OP_GETTABLE |
iABC |
R[A] := R[B][R[C]] |
Dynamic table lookup: reads t[key] where both table and key are registers. |
| OP_SETTABLE |
iABC |
R[A][R[B]] := RK(C) |
Dynamic table assignment: assigns t[key] = val. |
| OP_GETFIELD |
iABC |
R[A] := R[B][K[C]] |
Optimized string field lookup: reads t.fieldName. |
| OP_SETFIELD |
iABC |
R[A][K[B]] := RK(C) |
Optimized string field assignment: assigns t.fieldName = val. |
| OP_NEWTABLE |
iABC |
R[A] := {} |
Allocates a new table pre-sized with array and hash capacities. |
4. Arithmetic & Bitwise Math
| Opcode |
Semantics |
Opcode |
Semantics |
| OP_ADD |
R[A] := R[B] + R[C] |
OP_ADDI |
R[A] := R[B] + sC (Immediate integer) |
| OP_SUB |
R[A] := R[B] - R[C] |
OP_MUL |
R[A] := R[B] * R[C] |
| OP_DIV |
R[A] := R[B] / R[C] |
OP_IDIV |
R[A] := R[B] // R[C] (Floor div) |
| OP_BAND |
R[A] := R[B] & R[C] |
OP_BOR |
R[A] := R[B] | R[C] |
| OP_BXOR |
R[A] := R[B] ~ R[C] |
OP_SHL |
R[A] := R[B] << R[C] |
| OP_SHR |
R[A] := R[B] >> R[C] |
OP_UNM |
R[A] := -R[B] (Unary negation) |
5. Branches, Calls & Closures
| Opcode |
Format |
Description |
| OP_JMP |
isJ |
Unconditional relative PC jump with 25-bit signed offset. |
| OP_EQ / OP_LT / OP_LE |
iABC |
Relational test: compares two registers, skips the next instruction if condition is false. |
| OP_CALL |
iABC |
Invokes function at R[A] passing \(B-1\) parameters, accepting \(C-1\) return values. |
| OP_TAILCALL |
iABC |
Executes tail call in-place by reusing the current call frame. |
| OP_RETURN |
iABC |
Returns values from the active function to caller. |
| OP_CLOSURE |
iABx |
Instantiates a runtime LClosure from prototype P[Bx]. |
| OP_FORLOOP |
iABx |
Increments numeric for-loop index and loops back if limit not reached. |