Skip to main content

Opcode

Enum Opcode 

Source
#[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.

Implementations§

Source§

impl Opcode

Source

pub fn from_u8(b: u8) -> Option<Opcode>

Decode byte to opcode. Safe for b in 0..=36 (matches #[repr(u8)] discriminants).

Source

pub fn instruction_size(self, code: &[u8], ip: usize) -> Option<usize>

Size in bytes of this instruction at ip (including operands). Returns None if truncated.

Trait Implementations§

Source§

impl Clone for Opcode

Source§

fn clone(&self) -> Opcode

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Opcode

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Opcode

Source§

fn eq(&self, other: &Opcode) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for Opcode

Source§

impl Eq for Opcode

Source§

impl StructuralPartialEq for Opcode

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.