Enum tvix_eval::opcode::OpCode

source ·
pub enum OpCode {
Show 51 variants OpConstant(ConstantIdx), OpPop, OpInvert, OpNegate, OpAdd, OpSub, OpMul, OpDiv, OpEqual, OpLess, OpLessOrEq, OpMore, OpMoreOrEq, OpJump(JumpOffset), OpJumpIfTrue(JumpOffset), OpJumpIfFalse(JumpOffset), OpJumpIfCatchable(JumpOffset), OpJumpIfNotFound(JumpOffset), OpJumpIfNoFinaliseRequest(JumpOffset), OpAttrs(Count), OpAttrsUpdate, OpAttrsSelect, OpAttrsTrySelect, OpHasAttr, OpValidateClosedFormals, OpPushWith(StackIdx), OpPopWith, OpResolveWith, OpList(Count), OpConcat, OpInterpolate(Count), OpCoerceToString(CoercionKind), OpFindFile, OpResolveHomePath, OpAssertBool, OpAssertAttrs, OpGetLocal(StackIdx), OpCloseScope(Count), OpAssertFail, OpCall, OpGetUpvalue(UpvalueIdx), OpClosure(ConstantIdx), OpThunkClosure(ConstantIdx), OpThunkSuspended(ConstantIdx), OpForce, OpFinalise(StackIdx), OpReturn, DataStackIdx(StackIdx), DataDeferredLocal(StackIdx), DataUpvalueIdx(UpvalueIdx), DataCaptureWith,
}
Expand description

All variants of this enum carry a bounded amount of data to ensure that no heap allocations are needed for an Opcode.

In documentation comments, stack positions are referred to by indices written in {} as such, where required:

                            --- top of the stack
                           /
                          v
      [ ... | 3 | 2 | 1 | 0 ]
                  ^
                 /
2 values deep ---

Unless otherwise specified, operations leave their result at the top of the stack.

Variants§

§

OpConstant(ConstantIdx)

Push a constant onto the stack.

§

OpPop

Discard a value from the stack.

§

OpInvert

Invert the boolean at the top of the stack.

§

OpNegate

Invert the sign of the number at the top of the stack.

§

OpAdd

Sum up the two numbers at the top of the stack.

§

OpSub

Subtract the number at {1} from the number at {2}.

§

OpMul

Multiply the two numbers at the top of the stack.

§

OpDiv

Divide the two numbers at the top of the stack.

§

OpEqual

Check the two values at the top of the stack for Nix-equality.

§

OpLess

Check whether the value at {2} is less than {1}.

§

OpLessOrEq

Check whether the value at {2} is less than or equal to {1}.

§

OpMore

Check whether the value at {2} is greater than {1}.

§

OpMoreOrEq

Check whether the value at {2} is greater than or equal to {1}.

§

OpJump(JumpOffset)

Jump forward in the bytecode specified by the number of instructions in its usize operand.

§

OpJumpIfTrue(JumpOffset)

Jump forward in the bytecode specified by the number of instructions in its usize operand, if the value at the top of the stack is true.

§

OpJumpIfFalse(JumpOffset)

Jump forward in the bytecode specified by the number of instructions in its usize operand, if the value at the top of the stack is false.

§

OpJumpIfCatchable(JumpOffset)

Pop one stack item and jump forward in the bytecode specified by the number of instructions in its usize operand, if the value at the top of the stack is a Value::Catchable.

§

OpJumpIfNotFound(JumpOffset)

Jump forward in the bytecode specified by the number of instructions in its usize operand, if the value at the top of the stack is the internal value representing a missing attribute set key.

§

OpJumpIfNoFinaliseRequest(JumpOffset)

Jump forward in the bytecode specified by the number of instructions in its usize operand, if the value at the top of the stack is not the internal value requesting a stack value finalisation.

§

OpAttrs(Count)

Construct an attribute set from the given number of key-value pairs on the top of the stack

Note that this takes the count of pairs, not the number of stack values - the actual number of values popped off the stack will be twice the argument to this op

§

OpAttrsUpdate

Merge the attribute set at {2} into the attribute set at {1}, and leave the new set at the top of the stack.

§

OpAttrsSelect

Select the attribute with the name at {1} from the set at {2}.

§

OpAttrsTrySelect

Select the attribute with the name at {1} from the set at {2}, but leave a Value::AttrNotFound in the stack instead of failing if it is missing.

§

OpHasAttr

Check for the presence of the attribute with the name at {1} in the set at {2}.

§

OpValidateClosedFormals

Throw an error if the attribute set at the top of the stack has any attributes other than those listed in the formals of the current lambda

Panics if the current frame is not a lambda with formals

§

OpPushWith(StackIdx)

Push a value onto the runtime with-stack to enable dynamic identifier resolution. The absolute stack index of the value is supplied as a usize operand.

§

OpPopWith

Pop the last runtime with-stack element.

§

OpResolveWith

Dynamically resolve an identifier with the name at {1} from the runtime with-stack.

§

OpList(Count)

Construct a list from the given number of values at the top of the stack.

§

OpConcat

Concatenate the lists at {2} and {1}.

§

OpInterpolate(Count)

Interpolate the given number of string fragments into a single string.

§

OpCoerceToString(CoercionKind)

Force the Value on the stack and coerce it to a string

§

OpFindFile

Attempt to resolve the Value on the stack using the configured NixSearchPath

§

OpResolveHomePath

Attempt to resolve a path literal relative to the home dir

§

OpAssertBool

Assert that the value at {1} is a boolean, and fail with a runtime error otherwise.

§

OpAssertAttrs

§

OpGetLocal(StackIdx)

Access local identifiers with statically known positions.

§

OpCloseScope(Count)

Close scopes while leaving their expression value around.

§

OpAssertFail

Return an error indicating that an assert failed

§

OpCall

Call the value at {1} in a new VM callframe

§

OpGetUpvalue(UpvalueIdx)

Retrieve the upvalue at the given index from the closure or thunk currently under evaluation.

§

OpClosure(ConstantIdx)

Construct a closure which has upvalues but no self-references

§

OpThunkClosure(ConstantIdx)

Construct a closure which has self-references (direct or via upvalues)

§

OpThunkSuspended(ConstantIdx)

Construct a suspended thunk, used to delay a computation for laziness.

§

OpForce

Force the value at {1} until it is a Thunk::Evaluated.

§

OpFinalise(StackIdx)

Finalise initialisation of the upvalues of the value in the given stack index (which must be a Value::Thunk) after the scope is fully bound.

§

OpReturn

Final instruction emitted in a chunk. Does not have an inherent effect, but can simplify VM logic as a marker in some cases.

Can be thought of as “returning” the value to the parent frame, hence the name.

§

DataStackIdx(StackIdx)

Populate a static upvalue by copying from the stack immediately.

§

DataDeferredLocal(StackIdx)

Populate a static upvalue of a thunk by copying it the stack, but do when the thunk is finalised (by OpFinalise) rather than immediately.

§

DataUpvalueIdx(UpvalueIdx)

Populate a static upvalue by copying it from the upvalues of an enclosing scope.

§

DataCaptureWith

Populate dynamic upvalues by saving a copy of the with-stack.

Trait Implementations§

source§

impl Clone for OpCode

source§

fn clone(&self) -> OpCode

Returns a copy 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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method 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<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> Same for T

§

type Output = T

Should always be Self
source§

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

§

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>,

§

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>,

§

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.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V