|
4 | 4 |
|
5 | 5 | ## Opcode Table |
6 | 6 |
|
7 | | -| Opcode | Operand(s) | Stack | Notes | |
8 | | -| ---------------------- | ---------------------------------- | ----: | ----- | |
9 | | -| **OP_CONSTANT** | `index` | +1 | | |
10 | | -| **OP_NIL** | | +1 | | |
11 | | -| **OP_TRUE** | | +1 | | |
12 | | -| **OP_FALSE** | | +1 | | |
13 | | -| **OP_ADD** | | -2 +1 | | |
14 | | -| **OP_SUBTRACT** | | -2 +1 | | |
15 | | -| **OP_MULTIPLY** | | -2 +1 | | |
16 | | -| **OP_DIVIDE** | | -2 +1 | | |
17 | | -| **OP_MODULO** | | -2 +1 | | |
18 | | -| **OP_NEGATE** | | -1 +1 | | |
19 | | -| **OP_NOT** | | -1 +1 | | |
20 | | -| **OP_PRINT** | | | | |
21 | | -| **OP_RETURN** | | | | |
22 | | -| **OP_EQUAL** | | -2 +1 | | |
23 | | -| **OP_GREATER** | | -2 +1 | | |
24 | | -| **OP_LESS** | | -2 +1 | | |
25 | | -| **OP_POP** | | -1 | | |
26 | | -| **OP_DEFINE_GLOBAL** | `index` | | | |
27 | | -| **OP_GET_GLOBAL** | `index` | | | |
28 | | -| **OP_SET_GLOBAL** | `index` | | | |
29 | | -| **OP_GET_LOCAL** | `slot` | | | |
30 | | -| **OP_SET_LOCAL** | `slot` | | | |
31 | | -| **OP_JUMP_IF_FALSE** | `jumpOffset` | | | |
32 | | -| **OP_JUMP_IF_NOT_NIL** | `jumpOffset` | | | |
33 | | -| **OP_JUMP** | `jumpOffset` | | | |
34 | | -| **OP_LOOP** | `jumpOffset` | | | |
35 | | -| **OP_CLOSE_UPVALUE** | | | | |
36 | | -| **OP_GET_UPVALUE** | `slot` | | | |
37 | | -| **OP_SET_UPVALUE** | `slot` | | | |
38 | | -| **OP_GET_PROPERTY** | `index` | | | |
39 | | -| **OP_SET_PROPERTY** | `index`, `index` | | | |
40 | | -| **OP_CLASS** | `index` | | | |
41 | | -| **OP_METHOD** | `index` | | | |
42 | | -| **OP_INVOKE** | `index`, `argCount` | | | |
43 | | -| **OP_CALL** | `argCount` | | | |
44 | | -| **OP_CLOSURE** | `index`, `isLocal`, `upvalueIndex` | | | |
45 | | -| **OP_FIELD** | `index` | | | |
46 | | -| **OP_ARRAY** | `itemCount` | -n +1 | | |
47 | | -| **OP_INDEX_GET** | | -2 +1 | | |
48 | | -| **OP_INDEX_SET** | | -3 +1 | | |
| 7 | +| Opcode | Operand(s) | Stack | Notes | |
| 8 | +| ----------------------- | ---------------------------------- | ----: | -------------------------------------------------------------------- | |
| 9 | +| **OP_CONSTANT** | `index` | +1 | | |
| 10 | +| **OP_NIL** | | +1 | | |
| 11 | +| **OP_TRUE** | | +1 | | |
| 12 | +| **OP_FALSE** | | +1 | | |
| 13 | +| **OP_ADD** | | -2 +1 | | |
| 14 | +| **OP_SUBTRACT** | | -2 +1 | | |
| 15 | +| **OP_MULTIPLY** | | -2 +1 | | |
| 16 | +| **OP_DIVIDE** | | -2 +1 | | |
| 17 | +| **OP_MODULO** | | -2 +1 | | |
| 18 | +| **OP_NEGATE** | | -1 +1 | | |
| 19 | +| **OP_NOT** | | -1 +1 | | |
| 20 | +| **OP_PRINT** | | | | |
| 21 | +| **OP_RETURN** | | | | |
| 22 | +| **OP_EQUAL** | | -2 +1 | | |
| 23 | +| **OP_GREATER** | | -2 +1 | | |
| 24 | +| **OP_LESS** | | -2 +1 | | |
| 25 | +| **OP_POP** | | -1 | | |
| 26 | +| **OP_DEFINE_GLOBAL** | `index` | | | |
| 27 | +| **OP_GET_GLOBAL** | `index` | | | |
| 28 | +| **OP_SET_GLOBAL** | `index` | | | |
| 29 | +| **OP_GET_LOCAL** | `slot` | | | |
| 30 | +| **OP_SET_LOCAL** | `slot` | | | |
| 31 | +| **OP_JUMP_IF_FALSE** | `jumpOffset` | | | |
| 32 | +| **OP_JUMP_IF_NOT_NIL** | `jumpOffset` | | | |
| 33 | +| **OP_JUMP** | `jumpOffset` | | | |
| 34 | +| **OP_LOOP** | `jumpOffset` | | | |
| 35 | +| **OP_CLOSE_UPVALUE** | | | | |
| 36 | +| **OP_GET_UPVALUE** | `slot` | | | |
| 37 | +| **OP_SET_UPVALUE** | `slot` | | | |
| 38 | +| **OP_GET_PROPERTY** | `index` | | | |
| 39 | +| **OP_SET_PROPERTY** | `index`, `index` | | | |
| 40 | +| **OP_CLASS** | `index` | | | |
| 41 | +| **OP_METHOD** | `index` | | | |
| 42 | +| **OP_INVOKE** | `index`, `argCount` | | | |
| 43 | +| **OP_CALL** | `argCount` | | | |
| 44 | +| **OP_CLOSURE** | `index`, `isLocal`, `upvalueIndex` | | | |
| 45 | +| **OP_FIELD** | `index` | | | |
| 46 | +| **OP_ARRAY** | `itemCount` | -n +1 | | |
| 47 | +| **OP_INDEX_GET** | | -2 +1 | | |
| 48 | +| **OP_INDEX_SET** | | -3 +1 | | |
| 49 | +| **OP_CLOSE_BLOCK_EXPR** | `upvalueCount` | -n +1 | Cleans upvalues while leaving block expression return value on stack | |
49 | 50 |
|
50 | 51 | ### Operand Encodings |
51 | 52 |
|
|
55 | 56 | | **slot** | `uint8_t` | Slot number in the current call frame (local or upvalue). | |
56 | 57 | | **argCount** | `uint8_t` | For `OP_CLOSURE` only: tells whether the captured variable lives in the immediate surrounding function (`1`) or is itself an upvalue (`0`). | |
57 | 58 | | **itemCount** | `uint8_t` | For `OP_ARRAY` only: determines how many values on the stack go in to the array | |
| 59 | +| **upvalueCount** | `uint8_t` | For `OP_CLOSE_BLOCK_EXPR` only: determines how many upvalues to discard | |
58 | 60 | | **isLocal** | `uint8_t` | (0 or 1) For `OP_CLOSURE` only: tells whether the captured variable lives in the immediate surrounding function (`1`) or is itself an upvalue (`0`). | |
59 | 61 | | **upvalueIndex** | `uint8_t` | Index of the local or upvalue being captured (used together with the byte above). | |
60 | 62 | | **jumpOffset** | `uint16_t` | Relative jump distance measured from the **next instruction** after the offset field. (big‑endian: high byte first) | |
|
0 commit comments