Skip to main content

OpCode

Enum OpCode 

Source
#[repr(u8)]
pub enum OpCode {
Show 63 variants Constant = 0, Undefined = 1, Null = 2, True = 3, False = 4, Add = 5, Sub = 6, Mul = 7, Div = 8, Mod = 9, Negate = 10, BitAnd = 11, BitOr = 12, BitXor = 13, BitNot = 14, ShiftLeft = 15, ShiftRight = 16, UShiftRight = 17, StrictEqual = 18, StrictNotEqual = 19, Equal = 20, NotEqual = 21, LessThan = 22, LessEqual = 23, GreaterThan = 24, GreaterEqual = 25, Not = 26, TypeOf = 27, Void = 28, UnaryPlus = 29, GetVar = 30, SetVar = 31, DeclareVar = 32, DeclareLet = 33, DeclareConst = 34, InitVar = 35, InitBinding = 36, GetLocal = 37, SetLocal = 38, InitLocal = 39, Jump = 40, JumpIfFalse = 41, JumpIfTrue = 42, LoopStart = 43, Pop = 44, Dup = 45, Dup2 = 46, PushScope = 47, PopScope = 48, GetProp = 49, SetProp = 50, GetElem = 51, SetElem = 52, Call = 53, CallMethod = 54, Return = 55, Halt = 56, PreIncVar = 57, PreDecVar = 58, PostIncVar = 59, PostDecVar = 60, GetVarForUpdate = 61, MakeClosure = 62,
}
Expand description

Bytecode opcodes for the stack-based VM.

Variants§

§

Constant = 0

Push a constant from the constant pool onto the stack.

§

Undefined = 1

Push undefined onto the stack.

§

Null = 2

Push null onto the stack.

§

True = 3

Push true onto the stack.

§

False = 4

Push false onto the stack.

§

Add = 5

Pop two values, push their sum.

§

Sub = 6

Pop two values, push their difference.

§

Mul = 7

Pop two values, push their product.

§

Div = 8

Pop two values, push their quotient.

§

Mod = 9

Pop two values, push their remainder.

§

Negate = 10

Pop one value, push its numeric negation.

§

BitAnd = 11

Bitwise AND.

§

BitOr = 12

Bitwise OR.

§

BitXor = 13

Bitwise XOR.

§

BitNot = 14

Bitwise NOT.

§

ShiftLeft = 15

Left shift.

§

ShiftRight = 16

Signed right shift.

§

UShiftRight = 17

Unsigned right shift.

§

StrictEqual = 18

Strict equality (===).

§

StrictNotEqual = 19

Strict inequality (!==).

§

Equal = 20

Abstract equality (==).

§

NotEqual = 21

Abstract inequality (!=).

§

LessThan = 22

Less than.

§

LessEqual = 23

Less than or equal.

§

GreaterThan = 24

Greater than.

§

GreaterEqual = 25

Greater than or equal.

§

Not = 26

Logical NOT.

§

TypeOf = 27

typeof operator — pops value, pushes type string.

§

Void = 28

void operator — pops value, pushes undefined.

§

UnaryPlus = 29

Unary + — converts to number.

§

GetVar = 30

Get a global/local variable by name (operand: constant pool index of name string).

§

SetVar = 31

Set a variable by name (operand: constant pool index of name string). The value to assign is on top of the stack.

§

DeclareVar = 32

Declare a var binding (operand: constant pool index of name string).

§

DeclareLet = 33

Declare a let binding (operand: constant pool index of name string).

§

DeclareConst = 34

Declare a const binding (operand: constant pool index of name string).

§

InitVar = 35

Initialize a binding with the value on top of the stack.

§

InitBinding = 36

Initialize a let/const binding with the value on top of the stack.

§

GetLocal = 37

Get a local slot by index (operand: local slot index).

§

SetLocal = 38

Set a local slot by index (operand: local slot index).

§

InitLocal = 39

Initialize a local slot (operand: local slot index).

§

Jump = 40

Unconditional jump (operand: absolute offset).

§

JumpIfFalse = 41

Jump if top of stack is falsy (operand: absolute offset). Pops the value.

§

JumpIfTrue = 42

Jump if top of stack is truthy (operand: absolute offset). Pops the value.

§

LoopStart = 43

Marker for loop start (used by break/continue resolution).

§

Pop = 44

Pop and discard the top of the stack.

§

Dup = 45

Duplicate the top of the stack.

§

Dup2 = 46

Duplicate the top two stack values (a,b -> a,b,a,b).

§

PushScope = 47

Push a new block scope.

§

PopScope = 48

Pop a block scope.

§

GetProp = 49

Get a property: pop object and push object.property. Operand: constant pool index of property name.

§

SetProp = 50

Set a property: stack has [value, object]. Operand: constant pool index of property name.

§

GetElem = 51

Get a computed property: stack has [key, object].

§

SetElem = 52

Set a computed property: stack has [value, key, object].

§

Call = 53

Call a function. Operand: argument count. Stack: [arg_n, …, arg_1, callee]

§

CallMethod = 54

Call a method. Operand: argument count. Stack: [arg_n, …, arg_1, object] Second operand: constant pool index of method name.

§

Return = 55

Return from the current function/script. Pops return value from stack.

§

Halt = 56

Halt execution (end of script).

§

PreIncVar = 57

Pre-increment a variable (++x). Operand: constant pool index of name.

§

PreDecVar = 58

Pre-decrement a variable (–x). Operand: constant pool index of name.

§

PostIncVar = 59

Post-increment a variable (x++). Operand: constant pool index of name.

§

PostDecVar = 60

Post-decrement a variable (x–). Operand: constant pool index of name.

§

GetVarForUpdate = 61

Get a variable for compound update. Operand: constant pool index of name.

§

MakeClosure = 62

Create a closure from a function template. Operand: index into the chunk’s functions table. Pushes the resulting function object onto the stack.

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 StructuralPartialEq for OpCode

Auto Trait Implementations§

§

impl Freeze for OpCode

§

impl RefUnwindSafe for OpCode

§

impl Send for OpCode

§

impl Sync for OpCode

§

impl Unpin for OpCode

§

impl UnwindSafe for OpCode

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.