Skip to main content

OpCode

Enum OpCode 

Source
#[repr(u8)]
pub enum OpCode {
Show 57 variants Constant = 0, Null = 1, True = 2, False = 3, Add = 10, Sub = 11, Mul = 12, Div = 13, Negate = 14, Not = 20, And = 21, Or = 22, Implication = 23, Equal = 30, NotEqual = 31, Less = 32, Greater = 33, LessEqual = 34, GreaterEqual = 35, Interpolate = 40, GetLocal = 50, SetLocal = 51, GetUpvalue = 52, SetUpvalue = 53, PushWith = 54, PopWith = 55, LookupWith = 56, MakeAttrs = 60, GetAttr = 61, HasAttr = 62, UpdateAttrs = 63, SelectOrDefault = 64, DynGetAttr = 65, DynHasAttr = 66, DynSelectOrDefault = 67, MakeList = 70, Concat = 71, MakeClosure = 80, Call = 81, Return = 82, TailCall = 83, Jump = 90, JumpIfFalse = 91, JumpIfTrue = 92, Assert = 100, Throw = 101, Pop = 110, Dup = 111, GetLocalAttr = 120, GetLocalCall = 121, PushBuiltins = 130, CallBuiltin = 131, MakeThunk = 140, Force = 141, PatchThunkUpvalues = 142, MakeLazyThunk = 143, Import = 150,
}
Expand description

Bytecode instructions for the Nix VM.

Each variant occupies exactly one byte (#[repr(u8)]). Inline operands (constant pool index, jump offset, element count) follow the opcode in the bytecode stream as 16-bit little-endian values.

Variants§

§

Constant = 0

Push a constant from the constant pool. Operand: u16 constant index.

§

Null = 1

Push null.

§

True = 2

Push true.

§

False = 3

Push false.

§

Add = 10

Pop two values, push their sum (int+int, float+float, int+float).

§

Sub = 11

Pop two values, push their difference.

§

Mul = 12

Pop two values, push their product.

§

Div = 13

Pop two values, push their quotient. Errors on division by zero.

§

Negate = 14

Pop one value, push its arithmetic negation.

§

Not = 20

Pop one bool, push its logical negation.

§

And = 21

Pop two bools, push logical AND (short-circuit handled at compile time).

§

Or = 22

Pop two bools, push logical OR (short-circuit handled at compile time).

§

Implication = 23

Pop two values, push a -> b (logical implication: !a || b).

§

Equal = 30

Pop two values, push true if equal.

§

NotEqual = 31

Pop two values, push true if not equal.

§

Less = 32

Pop two values, push true if left < right.

§

Greater = 33

Pop two values, push true if left > right.

§

LessEqual = 34

Pop two values, push true if left <= right.

§

GreaterEqual = 35

Pop two values, push true if left >= right.

§

Interpolate = 40

Pop N string parts, concatenate into one string. Operand: u16 part count.

§

GetLocal = 50

Push a local variable by stack slot index. Operand: u16 slot index (relative to current frame’s stack base).

§

SetLocal = 51

Set a local variable by stack slot index. Operand: u16 slot index.

§

GetUpvalue = 52

Push an upvalue from the current closure’s upvalue array. Operand: u8 upvalue index.

§

SetUpvalue = 53

Set an upvalue in the current closure’s upvalue array. Operand: u8 upvalue index.

§

PushWith = 54

Push the TOS value onto the with-scope stack.

§

PopWith = 55

Pop from the with-scope stack.

§

LookupWith = 56

Look up a name in the with-scope stack (innermost first). Operand: u16 constant index for the variable name string.

§

MakeAttrs = 60

Pop N key-value pairs (key on top, value below), construct attrset. Operand: u16 pair count.

§

GetAttr = 61

Pop attrset and key (string constant index), push attrset.key. Operand: u16 constant index for the key name.

§

HasAttr = 62

Pop attrset and key (string constant index), push bool. Operand: u16 constant index for the key name.

§

UpdateAttrs = 63

Pop two attrsets, push merged result (right overrides left, //).

§

SelectOrDefault = 64

Pop attrset, key constant, and default value, push value or default. Stack order (top to bottom): default, attrset. Operand: u16 constant index for the key name.

§

DynGetAttr = 65

Dynamic attribute access: pop string key, pop attrset, push attrset.key. No inline operand — key comes from the stack at runtime.

§

DynHasAttr = 66

Dynamic hasattr: pop string key, pop attrset, push bool. No inline operand — key comes from the stack at runtime.

§

DynSelectOrDefault = 67

Dynamic select-or-default: pop default, key, attrset; push value or default. Stack order (top to bottom): default, key (string), attrset. No inline operand — key comes from the stack at runtime.

§

MakeList = 70

Pop N values, construct a list. Operand: u16 element count.

§

Concat = 71

Pop two lists, push concatenated result (++).

§

MakeClosure = 80

Create a closure from a sub-chunk. Operand: u16 constant index pointing to the function’s Chunk. Followed by u16 upvalue count, then for each upvalue: u8 (1 = local, 0 = upvalue of enclosing), u16 index.

§

Call = 81

Pop function and argument, call the function.

§

Return = 82

Return from the current call frame.

§

TailCall = 83

Pop function and argument, tail-call: reuse the current frame. Semantically identical to Call but does not grow the call stack.

§

Jump = 90

Unconditional jump. Operand: u16 absolute target offset.

§

JumpIfFalse = 91

Pop condition; if false, jump to target. Operand: u16 absolute target offset.

§

JumpIfTrue = 92

Pop condition; if true, jump to target. Operand: u16 absolute target offset.

§

Assert = 100

Pop condition; if false, raise AssertionFailed.

§

Throw = 101

Pop a string from stack and raise Throw(msg). Used for deferred search path errors caught by tryEval.

§

Pop = 110

Discard the top of the stack.

§

Dup = 111

Duplicate the top of the stack.

§

GetLocalAttr = 120

Fused GetLocal + GetAttr: push stack[base+slot].key. Operands: u16 local slot, u16 key constant index.

§

GetLocalCall = 121

Fused GetLocal + Call: call stack[base+slot] with TOS as arg. Operand: u16 local slot.

§

PushBuiltins = 130

Push the builtins attribute set onto the stack.

§

CallBuiltin = 131

Call a builtin function by index. Operand: u16 builtin index, u16 arg count.

§

MakeThunk = 140

Create a thunk wrapping a sub-chunk (lazy value). Operand: u16 constant index, u16 upvalue count, then for each upvalue: u8 is_local, u16 index.

§

Force = 141

Force the top of stack: if it is a thunk, evaluate and replace.

§

PatchThunkUpvalues = 142

Patch upvalues of a thunk in a local slot. Operand: u16 slot, u16 upvalue count, then for each: u8 is_local, u16 index.

§

MakeLazyThunk = 143

Create a lazy thunk from a source span (deferred compilation). Operand: u16 source_constant_idx, u32 offset, u32 length, u16 base_dir_constant_idx, u16 upvalue count, then for each upvalue: u8 is_local, u16 index.

§

Import = 150

Pop a path from the stack, import the file, push the result.

Implementations§

Source§

impl OpCode

Source

pub const ALL: &'static [OpCode]

Every opcode variant, in declaration order. Generated from the same table as the enum, so it can never omit a variant — the exhaustive roundtrip test drives off this list.

Source

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

Convert a raw byte to an opcode.

Source

pub fn to_byte(self) -> u8

The wire byte for this opcode (inverse of Self::from_byte).

Equivalent to self as u8; provided as the named paired inverse so the round-trip is spelled out at call sites.

Source

pub fn disasm_operands(self) -> u8

Number of inline u16 operands the disassembler prints for this opcode (0, 1, or 2). This is the arity the Chunk Debug formatter uses to advance past inline operands; it is an exhaustive match self, so adding an opcode without an operand-arity column is a compile error.

Trait Implementations§

Source§

impl Clone for OpCode

Source§

fn clone(&self) -> OpCode

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for OpCode

Source§

impl Debug for OpCode

Source§

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

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

impl Eq for OpCode

Source§

impl PartialEq for OpCode

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
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> ArchivePointee for T

Source§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
Source§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
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

Checks if this value is equivalent to the given key. 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> LayoutRaw for T

Source§

fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>

Returns the layout of the type.
Source§

impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
where T: SharedNiching<N1, N2>, N1: Niching<T>, N2: Niching<T>,

Source§

unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool

Returns whether the given value has been niched. Read more
Source§

fn resolve_niched(out: Place<NichedOption<T, N1>>)

Writes data to out indicating that a T is niched.
Source§

impl<T> Pointee for T

Source§

type Metadata = ()

The metadata type for pointers and references to this type.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.