Skip to main content

Opcode

Enum Opcode 

Source
#[repr(u8)]
pub enum Opcode {
Show 44 variants Constant = 0, Add = 1, Pop = 2, Sub = 3, Mul = 4, Div = 5, True = 6, False = 7, Equal = 8, NotEqual = 9, GreaterThan = 10, LessThan = 11, Minus = 12, Bang = 13, CondJump = 14, Jump = 15, Unit = 16, SetGlobal = 17, GetGlobal = 18, Vector = 19, Map = 20, Index = 21, Call = 22, ReturnValue = 23, Return = 24, GetLocal = 25, SetLocal = 26, GetBuiltin = 27, Closure = 28, GetFree = 29, CurrentClosure = 30, Convert = 31, Construct = 32, GetField = 33, MatchTag = 34, Mod = 35, BitAnd = 36, BitOr = 37, BitXor = 38, Shl = 39, Shr = 40, MakeRange = 41, MakeRangeInclusive = 42, Tuple = 43,
}
Expand description

Bytecode operation codes.

Each opcode represents a single VM instruction. Opcodes are encoded as single bytes, with optional operands following in big-endian format.

Variants§

§

Constant = 0

Push a constant onto the stack. Operands: u16 - index into the constant pool

§

Add = 1

Add two values from the stack. Operands: none

§

Pop = 2

Pop value from the stack. Operands: none

§

Sub = 3

Subtract two values from the stack. Operands: none

§

Mul = 4

Multiply two values from the stack. Operands: none

§

Div = 5

Divide two values from the stack. Operands: none

§

True = 6

Push true onto the stack. Operands: none

§

False = 7

Push false onto the stack. Operands: none

§

Equal = 8

Test equality of two stack values. Operands: none

§

NotEqual = 9

Test inequality of two stack values. Operands: none

§

GreaterThan = 10

Test if first value is greater than second. Operands: none

§

LessThan = 11

Test if first value is less than second. Operands: none

§

Minus = 12

Negate a value (unary minus). Operands: none

§

Bang = 13

Logical NOT operation. Operands: none

§

CondJump = 14

Conditional jump: pop value and jump to target address if not truthy. Operands: u16 - jump target address

§

Jump = 15

Unconditional jump to target address. Operands: u16 - jump target address

§

Unit = 16

Push the unit value () onto the stack. Operands: none

§

SetGlobal = 17

Store a value in a global binding. Operands: u16 - global variable index

§

GetGlobal = 18

Load a value from a global binding. Operands: u16 - global variable index

§

Vector = 19

Build a vector from the top N stack elements. Operands: u16 - number of elements

§

Map = 20

Build a map from the top N stack elements (key-value pairs). Operands: u16 - total number of elements (keys + values)

§

Index = 21

Index into a vector or map. Pops index and container, pushes result. Operands: none

§

Call = 22

Call a function. Pops function and arguments from the stack. Operands: u8 - number of arguments

§

ReturnValue = 23

Return from a function with a value on top of the stack. Operands: none

§

Return = 24

Return from a function with no explicit return value (implicit unit ()). Operands: none

§

GetLocal = 25

Load a local binding onto the stack. Operands: u8 - local variable index

§

SetLocal = 26

Store a value in a local binding. Operands: u8 - local variable index

§

GetBuiltin = 27

Load a built-in function onto the stack. Operands: u8 - builtin function index

§

Closure = 28

Create a closure from a compiled function and captured free variables. Operands: [u16, u8] - constant pool index of the function, number of free variables

§

GetFree = 29

Load a free variable from the current closure’s captured environment. Operands: u8 - free variable index

§

CurrentClosure = 30

Push the current closure onto the stack for recursive self-reference. Operands: none

§

Convert = 31

Convert a numeric value to a different numeric type. Operands: u8 - target type tag (see TypeTag)

§

Construct = 32

Construct a struct or enum variant from the top N stack elements.

Operands: [u16, u8]

  • u16: packed type index encoding (registry_index << 8) | variant_tag. The high 8 bits select the entry in the type registry; the low 8 bits carry the variant tag (0 for structs, 0..255 for enum variants).
  • u8: number of field values to pop from the stack.
§

GetField = 33

Read a field from a struct on top of the stack. Operands: u16 - field index

§

MatchTag = 34

Read the variant tag from an enum on top of the stack (peek, no pop). If the tag matches, execution continues to the next instruction; otherwise the instruction pointer jumps to the mismatch target.

Operands: [u16, u16]

  • u16: expected variant tag. Tags are limited to 0..255 by MAX_ENUM_VARIANTS but encoded as u16 for operand-width uniformity with other two-byte operands.
  • u16: jump target address on mismatch.
§

Mod = 35

Compute the remainder of two values from the stack. Operands: none

§

BitAnd = 36

Bitwise AND of two values from the stack. Operands: none

§

BitOr = 37

Bitwise OR of two values from the stack. Operands: none

§

BitXor = 38

Bitwise XOR of two values from the stack. Operands: none

§

Shl = 39

Left shift of two values from the stack. Operands: none

§

Shr = 40

Right shift of two values from the stack. Operands: none

§

MakeRange = 41

Construct a half-open Range from two i64 values on the stack. Pops end then start, pushes Value::Range(start, end). Operands: none

§

MakeRangeInclusive = 42

Construct an inclusive RangeInclusive from two i64 values on the stack. Pops end then start, pushes Value::RangeInclusive(start, end). Operands: none

§

Tuple = 43

Build a tuple from the top N stack elements. Operands: u16 - number of elements

Implementations§

Source§

impl Opcode

Source

pub const fn name(self) -> &'static str

Returns the name of this opcode for disassembly.

Source

pub const fn operand_widths(self) -> &'static [usize]

Returns the operand widths for this opcode.

Each element in the returned slice represents the byte width of an operand. For example, &[2] means one 2-byte operand.

Source

pub const fn from_byte(byte: u8) -> Option<Self>

Attempts to convert a byte to an opcode.

Source

pub const fn to_byte(self) -> u8

Converts this opcode to its byte representation.

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 Hash for Opcode

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. 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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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.