Enum tvix_eval::opcode::Op

source ·
#[repr(u8)]
pub enum Op {
Show 48 variants Constant = 0, Pop = 1, Invert = 2, Negate = 3, Add = 4, Sub = 5, Mul = 6, Div = 7, Equal = 8, Less = 9, LessOrEq = 10, More = 11, MoreOrEq = 12, Jump = 13, JumpIfTrue = 14, JumpIfFalse = 15, JumpIfCatchable = 16, JumpIfNotFound = 17, JumpIfNoFinaliseRequest = 18, Attrs = 19, AttrsUpdate = 20, AttrsSelect = 21, AttrsTrySelect = 22, HasAttr = 23, ValidateClosedFormals = 24, PushWith = 25, PopWith = 26, ResolveWith = 27, List = 28, Concat = 29, Interpolate = 30, CoerceToString = 31, FindFile = 32, ResolveHomePath = 33, AssertBool = 34, AssertAttrs = 35, GetLocal = 36, CloseScope = 37, AssertFail = 38, Call = 39, GetUpvalue = 40, Closure = 41, ThunkClosure = 42, ThunkSuspended = 43, Force = 44, Finalise = 45, Return = 46, Invalid = 47,
}
Expand description

Op represents all instructions in the Tvix abstract machine.

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§

§

Constant = 0

Push a constant onto the stack.

§

Pop = 1

Discard the value on top of the stack.

§

Invert = 2

Invert the boolean at the top of the stack.

§

Negate = 3

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

§

Add = 4

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

§

Sub = 5

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

§

Mul = 6

Multiply the two numbers at the top of the stack.

§

Div = 7

Divide the two numbers at the top of the stack.

§

Equal = 8

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

§

Less = 9

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

§

LessOrEq = 10

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

§

More = 11

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

§

MoreOrEq = 12

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

§

Jump = 13

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

§

JumpIfTrue = 14

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.

§

JumpIfFalse = 15

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.

§

JumpIfCatchable = 16

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.

§

JumpIfNotFound = 17

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.

§

JumpIfNoFinaliseRequest = 18

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.

§

Attrs = 19

Construct an attribute set from the given number of key-value pairs on the top of the stack. The operand gives 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.

§

AttrsUpdate = 20

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

§

AttrsSelect = 21

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

§

AttrsTrySelect = 22

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.

§

HasAttr = 23

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

§

ValidateClosedFormals = 24

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

§

PushWith = 25

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.

§

PopWith = 26

Pop the last runtime with-stack element.

§

ResolveWith = 27

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

§

List = 28

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

§

Concat = 29

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

§

Interpolate = 30

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

§

CoerceToString = 31

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

§

FindFile = 32

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

§

ResolveHomePath = 33

Attempt to resolve a path literal relative to the home dir

§

AssertBool = 34

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

§

AssertAttrs = 35

§

GetLocal = 36

Access local identifiers with statically known positions.

§

CloseScope = 37

Close scopes while leaving their expression value around.

§

AssertFail = 38

Return an error indicating that an assert failed

§

Call = 39

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

§

GetUpvalue = 40

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

§

Closure = 41

Construct a closure which has upvalues but no self-references

§

ThunkClosure = 42

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

§

ThunkSuspended = 43

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

§

Force = 44

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

§

Finalise = 45

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.

§

Return = 46

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.

§

Invalid = 47

Sentinel value to signal invalid bytecode. This MUST always be the last value in the enum. Do not move it!

Implementations§

source§

impl Op

source

pub fn arg_type(&self) -> OpArg

Trait Implementations§

source§

impl Debug for Op

source§

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

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

impl From<u8> for Op

source§

fn from(num: u8) -> Self

Converts to this type from the input type.
source§

impl PartialEq for Op

source§

fn eq(&self, other: &Op) -> 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 Eq for Op

source§

impl StructuralPartialEq for Op

Auto Trait Implementations§

§

impl Freeze for Op

§

impl RefUnwindSafe for Op

§

impl Send for Op

§

impl Sync for Op

§

impl Unpin for Op

§

impl UnwindSafe for Op

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