Skip to main content

Instruction Set Architecture (ISA): Assembly to IL Translation

The IL is the architecture-independent instruction set every target lifts into. A lifter never emits x86 or Lua opcodes; it emits these, and everything downstream: the IR, every pass, every emitter - only ever sees this. That is what lets one pipeline serve unrelated targets: allow a new front-end to produce these opcodes and it inherits the whole optimizer.

This page is the opcode reference. It defines the operand notation, the operand sizes, and then every opcode with its meaning and operand layout. For how a lifter actually emits them through the DSL, see Writing a Lifter.

Opcode Table Reference

Opcode Legend

This legend defines the syntax and notation used for opcodes, hints, and operands within the table.

Operand Types

  • r?? (Register): Represents a specific CPU or virtual machine register.
  • ?? (Kvalue / Constant): A value pulled from the constant pool.
  • ?? (Integer / Double): A raw numeric literal value.
  • +/-?? (Jump): Relative instruction offset. When generated, this indicates the number of instructions to skip forward (+) or backward (-).
  • u?? (Upvalue ID): Unique identifier for a captured upvalue.
  • ?? (Global ID): Unique identifier for a global variable.
  • true/false (Boolean): Explicit boolean literal values.
  • upvalue_kind (Upvalue Kind): Defines the capture type (see the separate upvalue_kind documentation).
  • c?? (Closure ID): Unique identifier for a function closure.
  • ?? (Val / Intptr): An integer-sized pointer or generic value holder.
  • ?? (Virtual Function): Pointer or identifier for a virtual function.
  • ?? (Table Size): Allocated or initial size definition for a table.

Operand Sizes

The operand size corresponds to the standard C types:

NotationActual SizeDescription
sizeof(int8_t)1 Byte8-bit signed integer
sizeof(int16_t)2 Bytes16-bit signed integer
sizeof(int32_t)4 Bytes32-bit signed integer
sizeof(int64_t)8 Bytes64-bit signed integer

Optable

OpcodeDescriptionOperands
OP_NOPNothingNone
OP_LOADBOOLLoads a boolean to the destination registerDest(Register), Source(Boolean)
OP_LOADINTLoads an integer to the destination registerDest(Register), Source(Integer)
OP_LOADNONELoads a None to the destination registerDest(Register)
OP_LOADKVALLoads a kvalue to the destination registerDest(Register), Source(Kvalue)
OP_LOADGLOBALLoads a global to the destination registerDest(Register), Source(GlobalID)
OP_GETTABUPVALUELoads a kvalue from structure to the destination registerDest(Register), Source(Kvalue)
OP_SETGLOBALSet globalSource(Register), Dest(GlobalID)
OP_MOVEMoveDest(Register), Source(Register)
OP_ADDArith/Bitwise (+)Dest(Register), Source(Register), Value(Register)
OP_SUBArith/Bitwise (-)Dest(Register), Source(Register), Value(Register)
OP_MULArith/Bitwise (*)Dest(Register), Source(Register), Value(Register)
OP_DIVArith/Bitwise (/)Dest(Register), Source(Register), Value(Register)
OP_MODArith/Bitwise (%)Dest(Register), Source(Register), Value(Register)
OP_POWArith/Bitwise (^)Dest(Register), Source(Register), Value(Register)
OP_ANDArith/Bitwise (&)Dest(Register), Source(Register), Value(Register)
OP_XORArith/Bitwise (~)Dest(Register), Source(Register), Value(Register)
OP_SHLArith/Bitwise (<<)Dest(Register), Source(Register), Value(Register)
OP_SHRArith/Bitwise (>>)Dest(Register), Source(Register), Value(Register)
OP_IDIVArith/Bitwise (//)Dest(Register), Source(Register), Value(Register)
OP_ORArith/Bitwise (|)Dest(Register), Source(Register), Value(Register)
OP_ADDKArith/Bitwise Kvalue (+)Dest(Register), Source(Register), Value(Kvalue)
OP_SUBKArith/Bitwise Kvalue (-)Dest(Register), Source(Register), Value(Kvalue)
OP_MULKArith/Bitwise Kvalue (*)Dest(Register), Source(Register), Value(Kvalue)
OP_DIVKArith/Bitwise Kvalue (/)Dest(Register), Source(Register), Value(Kvalue)
OP_MODKArith/Bitwise Kvalue (%)Dest(Register), Source(Register), Value(Kvalue)
OP_POWKArith/Bitwise Kvalue (^)Dest(Register), Source(Register), Value(Kvalue)
OP_ANDKArith/Bitwise Kvalue (&)Dest(Register), Source(Register), Value(Kvalue)
OP_XORKArith/Bitwise Kvalue (~)Dest(Register), Source(Register), Value(Kvalue)
OP_SHLKArith/Bitwise Kvalue (<<)Dest(Register), Source(Register), Value(Kvalue)
OP_SHRKArith/Bitwise Kvalue (>>)Dest(Register), Source(Register), Value(Kvalue)
OP_IDIVKArith/Bitwise Kvalue (//)Dest(Register), Source(Register), Value(Kvalue)
OP_ORKArith/Bitwise Kvalue (|)Dest(Register), Source(Register), Value(Kvalue)
OP_ADDNArith/Bitwise Integer (+)Dest(Register), Source(Register), Value(Integer)
OP_SUBNArith/Bitwise Integer (-)Dest(Register), Source(Register), Value(Integer)
OP_MULNArith/Bitwise Integer (*)Dest(Register), Source(Register), Value(Integer)
OP_DIVNArith/Bitwise Integer (/)Dest(Register), Source(Register), Value(Integer)
OP_MODNArith/Bitwise Integer (%)Dest(Register), Source(Register), Value(Integer)
OP_POWNArith/Bitwise Integer (^)Dest(Register), Source(Register), Value(Integer)
OP_ANDNArith/Bitwise Integer (&)Dest(Register), Source(Register), Value(Integer)
OP_XORNArith/Bitwise Integer (~)Dest(Register), Source(Register), Value(Integer)
OP_SHLNArith/Bitwise Integer (<<)Dest(Register), Source(Register), Value(Integer)
OP_SHRNArith/Bitwise Integer (>>)Dest(Register), Source(Register), Value(Integer)
OP_IDIVNArith/Bitwise Integer (//)Dest(Register), Source(Register), Value(Integer)
OP_ORNArith/Bitwise Integer (|)Dest(Register), Source(Register), Value(Integer)
OP_LENUnary (#)Dest(Register), Source(Register)
OP_NOTUnary (not)Dest(Register), Source(Register)
OP_MINUSUnary (-)Dest(Register), Source(Register)
OP_BITNOTUnary (~)Dest(Register), Source(Register)
OP_PLUSUnary (+)Dest(Register), Source(Register)
OP_REFUnary (&)Dest(Register), Source(Register)
OP_CCALLC function and closure callDest(Register), Arguement count(Val), Return count(Val)
OP_VCALLVirtual function call (clears virtual function arg stack once executed)Dest(Register), Virtual function(ID), Arg count(Val), Return count(Val)
OP_VPUSHPushes arguement to virtual function stackDest(Register)
OP_SELFLoads function in table to a registerDest(Register), Source(Register), Kvalue(Kvalue)
OP_RETURNReturn from a functionStart register(Register), Return count(Val)
OP_CONCATString concatationDest(Register), Start register(Val), End register(Val)
OP_JUMPJump to a addressTarget(Jump)
OP_CMPWrites two compare registers to a cmp flagCompare(Register), Compare(Register)
OP_CMPKWrites compare register and a kvalue to cmp flagCompare(Register), Compare(Kvalue)
OP_CMPNWrites compare register and an integer to cmp flagCompare(Register), Compare(Val)
OP_CMPBWrites compare register and a boolean to cmp flagCompare(Register), Compare(Boolean)
OP_CMPNONEWrites compare register and a none object to cmp flagCompare(Register)
OP_CMPSWrites one compare register to cmp flagCompare(Register)
OP_CMPSKWrites one compare kvalue to cmp flagCompare(Kvalue)
OP_CMPSNWrites one compare integer to cmp flagCompare(Val)
OP_CMPSNONEWrites one compare none object to cmp flagNone
OP_JUMPIFJump if cmp flagJump address(jump)
OP_JUMPIFNOTJump if not cmp flagJump address(jump)
OP_JUMPIFEQUALJump if == comparative to cmp flagJump address(jump)
OP_JUMPIFNOTEQUALJump if != comparative to cmp flagJump address(jump)
OP_JUMPIFLESSJump if < comparative to cmp flagJump address(jump)
OP_JUMPIFLESSEQUALJump if <= comparative to cmp flagJump address(jump)
OP_JUMPIFGREATERJump if > comparative to cmp flagJump address(jump)
OP_JUMPIFGREATEREQUALJump if >= comparative to cmp flagJump address(jump)
OP_SETIFSet true or false if cmp flagDest(Register)
OP_SETIFNOTSet true or false if not cmp flagDest(Register)
OP_SETIFEQUALSet true or false if == comparative to cmp flagDest(Register)
OP_SETIFNOTEQUALSet true or false if != comparative to cmp flagDest(Register)
OP_SETIFLESSSet true or false if < comparative to cmp flagDest(Register)
OP_SETIFLESSEQUALSet true or false if <= comparative to cmp flagDest(Register)
OP_SETIFGREATERSet true or false if > comparative to cmp flagDest(Register)
OP_SETIFGREATEREQUALSet true or false if >= comparative to cmp flagDest(Register)
OP_SETUPVALUESet UpvalueSource(Register), Upvalue ID(UpvalueID)
OP_GETUPVALUEGet UpvalueDest(Register), Upvalue ID(UpvalueID)
OP_DESTROYUPVALUESDestroy all upvalues with targetNone
OP_DESTROYUPVALUESADestroy upvalues with targetStart(Register)
OP_ADDUPVALUESets upvalue for prev closure instruction (Follows closure instruction)Type(UpvalueKind), Source(Register)
OP_INITInitsNone
OP_BITCASTCast register to n amounts of bitsDest(Register), Source(Register), Bits(Val u16), precision(Val u8), Unsigned(Boolean)
OP_GETVARIADICGets variadicsDest(Register), Amount(Val)
OP_SETTABLESet tableSource(Register), Table(Register), Index(Register)
OP_GETTABLEGet tableDest(Register), Table(Register), Index(Register)
OP_SETTABLENSet tableSource(Register), Table(Register), Index(Val)
OP_GETTABLENGet tableDest(Register), Table(Register), Index(Val)
OP_SETTABLEKSet tableSource(Register), Table(Register), Index(Kvalue)
OP_GETTABLEKGet tableDest(Register), Table(Register), Index(Kvalue)
OP_INITFORLOOPNInits numeric for loopDest(Register), Maximum/target value register(Register), Incrementation value register(Register), Loop iteration location(Jump)
OP_INITFORLOOPGInits generic for loopStart value register(Register)(+3), Variable count (Value), Loop iteration location(Jump)
OP_INITFORLOOPSPECIALInits abstract special generic for loopDest/Start(Register), End(Register), Step(Register), Variables(Registers), Loop iteration location(Jump)
OP_NEWCLOSURECreates new closureDest(Register), Closure ID(ClosureID)
OP_REFCLOSUREGets closure from kvalueDest(Register), Closure(Kvalue)
OP_NEWTABLECreates new tableDest(Register), Exact table size(Table_Size), Exact array size(Table_Size)
OP_REFTABLEGets table from kvalueDest(Register), Table(Kvalue) (Exact size, node)
OP_NEWTABLEACreates new tableDest(Register), Approximate table size(Table_Size), Approximate array size(Table_Size)
OP_REFTABLEAGets table from kvalueDest(Register), Table(Kvalue) (Approximate size, node)
OP_SETLISTAppends elements in a tableDest table(Register), Start register(Register), Exact table size(Val), Index(Val)
OP_FORLOOPGFor loop genericStart register(Register), Loop variable count(Val), Jump back(Jump)
OP_FORLOOPNFor loop numericStart value register(Register), Maximum/target value register(Register), Incrementation value register(Register), Jump back(Jump)
OP_POPTOPPops register from top of the stackNone
OP_POPARGAdds argument to poparg flag to get popped when next OP_CALL instruction is hitIgnore Register(Register)
OP_MEMSETSets memoryTarget(Register), Source(Register), Bits(Val u16)
OP_MEMREADReads memoryDest(Register), Source(Register), Bits(Val u16)
OP_SETFLAGAppends flag to flag stackFlags ID ENUM(Val)
OP_SALLOCStack allocates n bytesDest(Register), Bytes(Val)
OP_GETSTACKGets stack pointerDest(Register), ID(Val)
OP_SETSTACKSet stack pointerDest(Register), ID(Val)
OP_STACKPUSHPushes register contents to the given stackStack ID(VAL), Source(Register)
OP_STACKPOPPops register contents from the given stackStack ID(VAL), Source(Register)
OP_POPTOPSTACKPops top from given stackStack pointer(Register)
OP_CLOGIC_ANDPerforms condition logic if sources are truthy puts result in destDest(Register), Source(Register), Source(Register)
OP_CLOGIC_ORPerforms condition logic if either sources are truthy puts result in destDest(Register), Source(Register), Source(Register)
OP_PENDPsuedo-instruction (Pending analysis)Userdata(Register), * Userdata(Val), * Userdata(Val), * Userdata(Val)
OP_MARKPsuedo-instruction (Marks spot)None
OP_MOBJ_CASTCasts register to object from object mapDest(Register), Source(Register), Index(Val)
OP_NCTOR_MOBJSee if source is object from object map if not constructDest(Register), Source(Register), Index(Val)
OP_SCALLCall to symbol tableID(Val)
OP_FLAGSETSet flag with sourceID(Val), Source(Reg)
OP_FLAGREADRead flag to destDest(Register), Source(Val)
OP_CREATE_STACKCreates new stack (overrides current)Dest(Register)
OP_PRETURNReturn from page functionValid Flag, Jump target (Register), Jump page ID (Integral)
OP_STARTPAGEFUNCStarts page function, not effected by isolateID(Val)
OP_ENDPAGEFUNCEnds page function, not effected by isolateID(Val)
OP_PCALLCall to page functionID(Val), Reg(Register), Entry(Val)
OP_PJUMPJump to pageID(Val)
OP_SEGREGATENext instruction any native flags set will be offsetOFFSET(Val)
OP_COMBINEPsuedo-instruction (Flag to combine data from previous instruction to next)None
OP_FLAGJUMPIf flag (ID) is true jump to pageID(Val), ID(Val)
OP_ICALLIf register(reg) == ID(Val) callReg(Register), ID(Val)
OP_TAG_STARTSet tagName(Kvalue)
OP_TAG_KVSet next tag key value pairKey(Kvalue), Value(Kvalue)
OP_TAG_ENDEnd current tagNone
OP_METADATAMeta data, user handled instructionName(Kvalue), Data(Kvalue)
OP_ENTRY_POINTEntry pointNone
OP_COMMANDInternal command refer to command tableCommand (Kvalue), Arg count (Val)
OP_BITREADRead bits (Index starts at 0)[MIN, MAX] and interpret resultDest(Register), Source(Register), Min(Register), Max(Register), Cast_bits(Val u16), Unsigned(Boolean)
OP_BITWRITEWrites bits (Index starts at 0)[MIN, MAX] to the first sourceDest(Register), Lvalue(Register), Source(Register), Min(Register), Max(Register), Cast_bits(Val u16), Unsigned(Boolean)
OP_BITWRITEAWrites bits assign (Index starts at 0)[MIN, MAX] to the Dest bufferDest(Register), Source(Register), Min(Register), Max(Register)
OP_ANNOTATE_PREVImplement annotation to previous instructionStr (Kvalue)
OP_AMTAmountNone