-
Notifications
You must be signed in to change notification settings - Fork 0
IR Reference
TechnoJo4 edited this page Jan 12, 2021
·
2 revisions
The IR is represented by tuples (actually just normal lua array-like tables), the first item being the instruction (usually abbreviated inst, sometimes called type).
Operand type notation used in this document:
-
IR
: An IR instruction tuple -
Int
: An integer -
Const
: An (integer) index into the constant table -
[]
after a type means that the operand is an array of the type. -
...
after a type means that all or all remaning operands are of the type.
Instruction | Operands | Description |
---|---|---|
NIL | None | Constant nil
|
TRUE | None | Constant true
|
FALSE | None | Constant false
|
CONST | Index (Const) | Constant from constant table. |
GETTABLE | Table (IR), Index (IR) | Index into a table. |
SETTABLE | Table (IR), Index (IR), Value (IR) | Set the index into a table to a value. |
GETLOCAL | Index (Int) | Gets a local |
SETLOCAL | Index (Int), Value (IR) | Sets a local |
GETUPVAL | Index (Int) | Gets a upvalue |
SETUPVAL | Index (Int), Value (IR) | Sets a upvalue |
GETGLOBAL | Index (Const) | Gets a global |
SETGLOBAL | Index (Const), Value (IR) | Sets a global |
ADD | Left (IR), Right (IR) | Addition |
SUB | Left (IR), Right (IR) | Substraction |
MUL | Left (IR), Right (IR) | Multiplication |
DIV | Left (IR), Right (IR) | Division |
MOD | Left (IR), Right (IR) | Modulo |
POW | Left (IR), Right (IR) | Power (Exponentiation) |
CONCAT | Values (IR...) | Concatenation |
UNM | Value (IR) | Unary Minus (Negative) |
NOT | Value (IR) | Logical Not |
LEN | Value (IR) | Length |
OR | Left (IR), Right (IR) | "Logical" OR (not really, like lua or ) |
AND | Left (IR), Right (IR) | "Logical" AND (not really, like lua and ) |
EQ | Left (IR), Right (IR) | Equality |
NEQ | Left (IR), Right (IR) | Inequality |
LT | Left (IR), Right (IR) | Less Than |
LTEQ | Left (IR), Right (IR) | Less Than or Equals |
GT | Left (IR), Right (IR) | Greater Than |
GTEQ | Left (IR), Right (IR) | Greater Than or Equals |
CALL | Call Target (IR), Number of expected Returns (Int), Arguments (IR...) | Function call |
NAMECALL | Table (IR), Index (Const), Number of expected Returns (Int), Arguments (IR...) | Method call (function call through table, e.g. a:b(arg) ) |
RETURN | Values (IR...) | Return |
POP | Int... or IR... | Deallocate a register in the bytecode emitter. Used to discard expression statement results and for locals at end of scopes. |
PUSH | Int... or IR... | Allocate a register in the bytecode emitter. Used for locals. |
CLOSE | Int... | Closes locals (at the end of scopes). |
CONDITIONAL | Condition (IR), True Branch (IR), False Branch (IR) | Conditional Expression |
LOOP | Statements (IR[]) | Loop |
IF | Condition (IR), True Branch (IR[]), False Branch (IR[]) | If Statement |
BREAK | None | Break Statement |
CLOSURE | Index into prototype table (Int) | Gets a closure value |