#[repr(u8)]pub enum Opcode {
Show 37 variants
Nop = 0,
LoadConst = 1,
LoadVar = 2,
StoreVar = 3,
Pop = 4,
Dup = 5,
Call = 6,
Return = 7,
Jump = 8,
JumpIfFalse = 9,
JumpBack = 10,
BinOp = 11,
UnaryOp = 12,
GetMember = 13,
SetMember = 14,
GetIndex = 15,
SetIndex = 16,
NewArray = 17,
NewObject = 18,
LoadGlobal = 19,
StoreGlobal = 20,
Closure = 21,
PopN = 22,
LoadThis = 23,
Throw = 24,
EnterTry = 25,
ExitTry = 26,
ConcatArray = 27,
MergeObject = 28,
CallSpread = 29,
GetMemberOptional = 30,
ArraySortNumeric = 31,
ArraySortByProperty = 32,
ArrayMapIdentity = 33,
ArrayMapBinOp = 34,
ArrayFilterBinOp = 35,
LoadNativeExport = 36,
}Expand description
Stack-based bytecode opcodes.
Variants§
Nop = 0
No operation
LoadConst = 1
Push constant from constants table (operand: u16 index)
LoadVar = 2
Load variable from scope (operand: u16 name index)
StoreVar = 3
Store top of stack to variable (operand: u16 name index)
Pop = 4
Discard top of stack
Dup = 5
Duplicate top of stack
Call = 6
Call function with n args (operand: u16 arg count). Callee and args on stack.
Return = 7
Return from function. Top of stack is return value.
Jump = 8
Unconditional jump forward (operand: u16 byte offset)
JumpIfFalse = 9
Pop top; if falsy, jump forward (operand: u16 byte offset)
JumpBack = 10
Unconditional jump backward (operand: u16 byte offset)
BinOp = 11
Binary operation (operand: u8 BinOp variant). Pops left, right; pushes result.
UnaryOp = 12
Unary operation (operand: u8 UnaryOp variant). Pops operand; pushes result.
GetMember = 13
Get property: obj.prop (operand: u16 prop name index). Pops obj; pushes value.
SetMember = 14
Set property: obj.prop = val (operand: u16 prop name index). Pops obj, val.
GetIndex = 15
Get index: obj[idx]. Pops obj, idx; pushes value.
SetIndex = 16
Set index: obj[idx] = val. Pops obj, idx, val.
NewArray = 17
Create array with n elements (operand: u16 count). Elements on stack.
NewObject = 18
Create object with n key-value pairs (operand: u16 count). Keys and vals interleaved.
LoadGlobal = 19
Load from global scope (operand: u16 name index)
StoreGlobal = 20
Store to global scope (operand: u16 name index)
Closure = 21
Create closure: push function (operand: u16 chunk index for nested function)
PopN = 22
Pop and discard n values (operand: u16 count)
LoadThis = 23
Load this or receiver (for method calls)
Throw = 24
Throw: pop value, unwind to catch handler, push value, jump
EnterTry = 25
EnterTry: push handler (catch offset u16). Catch offset = bytes from end of this insn.
ExitTry = 26
ExitTry: pop try handler
ConcatArray = 27
Concat arrays: pop right, pop left, push left.concat(right). For spread.
MergeObject = 28
Merge objects: pop right, pop left, push Object.assign({}, left, right). For object spread.
CallSpread = 29
Call with spread: pop args array, pop callee, call callee(…args).
GetMemberOptional = 30
Get property optional: like GetMember but returns Null if obj is null or prop missing.
ArraySortNumeric = 31
Pop array, sort numerically in place (operand: u8 0=asc, 1=desc), push array. Fast path for arr.sort((a,b)=>a-b) / arr.sort((a,b)=>b-a).
ArraySortByProperty = 32
Pop array, sort by numeric property (operands: u16 prop_name_const_idx, u16 0=asc/1=desc). Fast path for arr.sort((a,b)=>a.prop-b.prop).
ArrayMapIdentity = 33
arr.map(x => x) - identity, returns array clone.
ArrayMapBinOp = 34
arr.map(x => x op const) or arr.map(x => const op x). Operands: u8 binop, u16 const_idx, u8 param_left (0=param on left e.g. x2, 1=param on right e.g. 2x).
ArrayFilterBinOp = 35
arr.filter(x => x op const) or arr.filter(x => const op x). Operands: u8 binop, u16 const_idx, u8 param_left. Keeps elements where result is truthy.
LoadNativeExport = 36
Load built-in module export. Operands: u16 spec_const_idx, u16 export_name_const_idx. Pushes Value.