Enum rune::runtime::Inst

source ·
pub enum Inst {
Show 73 variants Not, Neg, Closure { hash: Hash, count: usize, }, CallOffset { offset: usize, call: Call, args: usize, }, Call { hash: Hash, args: usize, }, CallAssociated { hash: Hash, args: usize, }, LoadInstanceFn { hash: Hash, }, CallFn { args: usize, }, IndexGet { target: InstAddress, index: InstAddress, }, TupleIndexGet { index: usize, }, TupleIndexSet { index: usize, }, TupleIndexGetAt { offset: usize, index: usize, }, ObjectIndexGet { slot: usize, }, ObjectIndexSet { slot: usize, }, ObjectIndexGetAt { offset: usize, slot: usize, }, IndexSet, Await, Select { len: usize, }, LoadFn { hash: Hash, }, Push { value: InstValue, }, Pop, PopN { count: usize, }, PopAndJumpIfNot { count: usize, jump: usize, }, Clean { count: usize, }, Copy { offset: usize, }, Move { offset: usize, }, Drop { offset: usize, }, Replace { offset: usize, }, Swap { a: usize, b: usize, }, Return { address: InstAddress, clean: usize, }, ReturnUnit, Jump { jump: usize, }, JumpIf { jump: usize, }, JumpIfOrPop { jump: usize, }, JumpIfNotOrPop { jump: usize, }, JumpIfBranch { branch: i64, jump: usize, }, Vec { count: usize, }, Tuple1 { args: [InstAddress; 1], }, Tuple2 { args: [InstAddress; 2], }, Tuple3 { args: [InstAddress; 3], }, Tuple4 { args: [InstAddress; 4], }, Tuple { count: usize, }, PushTuple, Object { slot: usize, }, Range { range: InstRange, }, EmptyStruct { hash: Hash, }, Struct { hash: Hash, slot: usize, }, UnitVariant { hash: Hash, }, StructVariant { hash: Hash, slot: usize, }, String { slot: usize, }, Bytes { slot: usize, }, StringConcat { len: usize, size_hint: usize, }, Format { spec: FormatSpec, }, IsUnit, Try { address: InstAddress, clean: usize, preserve: bool, }, EqByte { byte: u8, }, EqChar { char: char, }, EqInteger { integer: i64, }, EqBool { boolean: bool, }, EqString { slot: usize, }, EqBytes { slot: usize, }, MatchType { hash: Hash, }, MatchVariant { variant_hash: Hash, enum_hash: Hash, index: usize, }, MatchBuiltIn { type_check: TypeCheck, }, MatchSequence { type_check: TypeCheck, len: usize, exact: bool, }, MatchObject { slot: usize, exact: bool, }, Yield, YieldUnit, Variant { variant: InstVariant, }, Op { op: InstOp, a: InstAddress, b: InstAddress, }, Assign { target: InstTarget, op: InstAssignOp, }, IterNext { offset: usize, jump: usize, }, Panic { reason: PanicReason, },
}
Expand description

An operation in the stack-based virtual machine.

Variants§

§

Not

Not operator. Takes a boolean from the top of the stack and inverts its logical value.

§Operation

<bool>
=> <bool>
§

Neg

Negate the numerical value on the stack.

§Operation

<number>
=> <number>
§

Closure

Construct a closure that takes the given number of arguments and captures count elements from the top of the stack.

§Operation

<value..>
=> <fn>

Fields

§hash: Hash

The hash of the internally stored closure function.

§count: usize

The number of arguments to store in the environment on the stack.

§

CallOffset

Perform a function call within the same unit.

It will construct a new stack frame which includes the last args number of entries.

Fields

§offset: usize

The offset of the function being called in the same unit.

§call: Call

The calling convention to use.

§args: usize

The number of arguments expected on the stack for this call.

§

Call

Perform a function call.

It will construct a new stack frame which includes the last args number of entries.

Fields

§hash: Hash

The hash of the function to call.

§args: usize

The number of arguments expected on the stack for this call.

§

CallAssociated

Perform a instance function call.

The instance being called on should be on top of the stack, followed by args number of arguments.

Fields

§hash: Hash

The hash of the name of the function to call.

§args: usize

The number of arguments expected on the stack for this call.

§

LoadInstanceFn

Lookup the specified instance function and put it on the stack. This might help in cases where a single instance function is called many times (like in a loop) since it avoids calculating its full hash on every iteration.

Note that this does not resolve that the instance function exists, only that the instance does.

§Operation

<value>
=> <fn>

Fields

§hash: Hash

The name hash of the instance function.

§

CallFn

Perform a function call on a function pointer stored on the stack.

§Operation

<fn>
<args...>
=> <ret>

Fields

§args: usize

The number of arguments expected on the stack for this call.

§

IndexGet

Perform an index get operation. Pushing the result on the stack.

§Operation

<target>
<index>
=> <value>

Fields

§target: InstAddress

How the target is addressed.

§index: InstAddress

How the index is addressed.

§

TupleIndexGet

Get the given index out of a tuple on the top of the stack. Errors if the item doesn’t exist or the item is not a tuple.

§Operation

<tuple>
=> <value>

Fields

§index: usize

The index to fetch.

§

TupleIndexSet

Set the given index of the tuple on the stack, with the given value.

§Operation

<value>
<tuple>
=> *nothing*

Fields

§index: usize

The index to set.

§

TupleIndexGetAt

Get the given index out of a tuple from the given variable slot. Errors if the item doesn’t exist or the item is not a tuple.

§Operation

=> <value>

Fields

§offset: usize

The slot offset to load the tuple from.

§index: usize

The index to fetch.

§

ObjectIndexGet

Get the given index out of an object on the top of the stack. Errors if the item doesn’t exist or the item is not an object.

The index is identifier by a static string slot, which is provided as an argument.

§Operation

<object>
=> <value>

Fields

§slot: usize

The static string slot corresponding to the index to fetch.

§

ObjectIndexSet

Set the given index out of an object on the top of the stack. Errors if the item doesn’t exist or the item is not an object.

The index is identifier by a static string slot, which is provided as an argument.

§Operation

<object>
<value>
=>

Fields

§slot: usize

The static string slot corresponding to the index to set.

§

ObjectIndexGetAt

Get the given index out of an object from the given variable slot. Errors if the item doesn’t exist or the item is not an object.

The index is identifier by a static string slot, which is provided as an argument.

§Operation

=> <value>

Fields

§offset: usize

The slot offset to get the value to load from.

§slot: usize

The static string slot corresponding to the index to fetch.

§

IndexSet

Perform an index set operation.

§Operation

<target>
<index>
<value>
=> *noop*
§

Await

Await the future that is on the stack and push the value that it produces.

§Operation

<future>
=> <value>
§

Select

Select over len futures on the stack. Sets the branch register to the index of the branch that completed. And pushes its value on the stack.

This operation will block the VM until at least one of the underlying futures complete.

§Operation

<future...>
=> <value>

Fields

§len: usize

The number of futures to poll.

§

LoadFn

Load the given function by hash and push onto the stack.

§Operation

=> <value>

Fields

§hash: Hash

The hash of the function to push.

§

Push

Push a value onto the stack.

§Operation

=> <value>

Fields

§value: InstValue

The value to push.

§

Pop

Pop the value on the stack, discarding its result.

§Operation

<value>
=>
§

PopN

Pop the given number of elements from the stack.

§Operation

<value..>
=> *noop*

Fields

§count: usize

The number of elements to pop from the stack.

§

PopAndJumpIfNot

If the stop of the stack is false, will pop the given count entries on the stack and jump to the given offset.

§Operation

<bool>
=> *noop*

Fields

§count: usize

The number of entries to pop of the condition is true.

§jump: usize

The offset to jump if the condition is true.

§

Clean

Clean the stack by keeping the top of it, and popping count values under it.

§Operation

<top>
<value..>
=> <top>

Fields

§count: usize

The number of entries in the stack to pop.

§

Copy

Copy a variable from a location offset relative to the current call frame.

A copy is very cheap. It simply means pushing a reference to the stack.

Fields

§offset: usize

Offset to copy value from.

§

Move

Move a variable from a location offset relative to the current call frame.

Fields

§offset: usize

Offset to move value from.

§

Drop

Drop the value in the given frame offset, cleaning out it’s slot in memory.

§Operation

=> *noop*

Fields

§offset: usize

Frame offset to drop.

§

Replace

Replace a value at the offset relative from the top of the stack, with the top of the stack.

Fields

§offset: usize

Offset to swap value from.

§

Swap

Swap two values on the stack using their offsets relative to the current stack frame.

Fields

§a: usize

Offset to the first value.

§b: usize

Offset to the second value.

§

Return

Pop the current stack frame and restore the instruction pointer from it.

The stack frame will be cleared, and the value on the top of the stack will be left on top of it.

Fields

§address: InstAddress

The address of the value to return.

§clean: usize

Number of variables to clean. If address is top, this should only specify variables in excess of the top variable. Otherwise, this includes the return value.

§

ReturnUnit

Pop the current stack frame and restore the instruction pointer from it.

The stack frame will be cleared, and a unit value will be pushed to the top of the stack.

§

Jump

Unconditionally jump to offset relative to the current instruction pointer.

§Operation

*nothing*
=> *nothing*

Fields

§jump: usize

Offset to jump to.

§

JumpIf

Jump to offset relative to the current instruction pointer if the condition is true.

§Operation

<boolean>
=> *nothing*

Fields

§jump: usize

Offset to jump to.

§

JumpIfOrPop

Jump to offset relative to the current instruction pointer if the condition is true. Will only pop the stack is a jump is not performed.

§Operation

<boolean>
=> *nothing*

Fields

§jump: usize

Offset to jump to.

§

JumpIfNotOrPop

Jump to offset relative to the current instruction pointer if the condition is false. Will only pop the stack is a jump is not performed.

§Operation

<boolean>
=> *nothing*

Fields

§jump: usize

Offset to jump to.

§

JumpIfBranch

Compares the branch register with the top of the stack, and if they match pops the top of the stack and performs the jump to offset.

§Operation

<integer>
=> *nothing*

Fields

§branch: i64

The branch value to compare against.

§jump: usize

The offset to jump.

§

Vec

Construct a push a vector value onto the stack. The number of elements in the vector are determined by count and are popped from the stack.

§Operation

<value..>
=> <vec>

Fields

§count: usize

The size of the vector.

§

Tuple1

Construct a push a one-tuple value onto the stack.

§Operation

=> <tuple>

Fields

§args: [InstAddress; 1]

First element of the tuple.

§

Tuple2

Construct a push a two-tuple value onto the stack.

§Operation

=> <tuple>

Fields

§args: [InstAddress; 2]

Tuple arguments.

§

Tuple3

Construct a push a three-tuple value onto the stack.

§Operation

=> <tuple>

Fields

§args: [InstAddress; 3]

Tuple arguments.

§

Tuple4

Construct a push a four-tuple value onto the stack.

§Operation

=> <tuple>

Fields

§args: [InstAddress; 4]

Tuple arguments.

§

Tuple

Construct a push a tuple value onto the stack. The number of elements in the tuple are determined by count and are popped from the stack.

§Operation

<value..>
=> <tuple>

Fields

§count: usize

The size of the tuple.

§

PushTuple

Take the tuple that is on top of the stack and push its content onto the stack.

Note: this is used by closures to “unpack” their environment into local variables.

§Operation

<tuple>
=> <value...>
§

Object

Construct a push an object onto the stack. The number of elements in the object are determined the slot of the object keys slot and are popped from the stack.

For each element, a value is popped corresponding to the object key.

§Operation

<value..>
=> <object>

Fields

§slot: usize

The static slot of the object keys.

§

Range

Construct a range. This will pop the start and end of the range from the stack.

§Operation

[start]
[end]
=> <range>

Fields

§range: InstRange

The kind of the range, which determines the number of arguments on the stack.

§

EmptyStruct

Construct a push an object of the given type onto the stack. The type is an empty struct.

§Operation

=> <object>

Fields

§hash: Hash

The type of the object to construct.

§

Struct

Construct a push an object of the given type onto the stack. The number of elements in the object are determined the slot of the object keys slot and are popped from the stack.

For each element, a value is popped corresponding to the object key.

§Operation

<value..>
=> <object>

Fields

§hash: Hash

The type of the object to construct.

§slot: usize

The static slot of the object keys.

§

UnitVariant

Construct a push an object variant of the given type onto the stack. The type is an empty struct.

§Operation

=> <object>

Fields

§hash: Hash

The type hash of the object variant to construct.

§

StructVariant

Construct a push an object variant of the given type onto the stack. The number of elements in the object are determined the slot of the object keys slot and are popped from the stack.

For each element, a value is popped corresponding to the object key.

§Operation

<value..>
=> <object>

Fields

§hash: Hash

The type hash of the object variant to construct.

§slot: usize

The static slot of the object keys.

§

String

Load a literal string from a static string slot.

§Operation

=> <string>

Fields

§slot: usize

The static string slot to load the string from.

§

Bytes

Load a literal byte string from a static byte string slot.

§Operation

=> <bytes>

Fields

§slot: usize

The static byte string slot to load the string from.

§

StringConcat

Pop the given number of values from the stack, and concatenate a string from them.

This is a dedicated template-string optimization.

§Operation

<value...>
=> <string>

Fields

§len: usize

The number of items to pop from the stack.

§size_hint: usize

The minimum string size used.

§

Format

Push a combined format specification and value onto the stack. The value used is the last value on the stack.

Fields

§spec: FormatSpec

The format specification to use.

§

IsUnit

Test if the top of the stack is a unit.

§Operation

<value>
=> <boolean>
§

Try

Perform the try operation which takes the value at the given address and tries to unwrap it or return from the current call frame.

§Operation

<value>
=> <boolean>

Fields

§address: InstAddress

Address to test if value.

§clean: usize

Variable count that needs to be cleaned in case the operation results in a return.

§preserve: bool

If the value on top of the stack should be preserved.

§

EqByte

Test if the top of the stack is a specific byte.

§Operation

<value>
=> <boolean>

Fields

§byte: u8

The byte to test against.

§

EqChar

Test if the top of the stack is a specific character.

§Operation

<value>
=> <boolean>

Fields

§char: char

The character to test against.

§

EqInteger

Test if the top of the stack is a specific integer.

§Operation

<value>
=> <boolean>

Fields

§integer: i64

The integer to test against.

§

EqBool

Test if the top of the stack is a specific boolean.

§Operation

<value>
=> <boolean>

Fields

§boolean: bool

The bool to test against.

§

EqString

Compare the top of the stack against a static string slot.

§Operation

<value>
=> <boolean>

Fields

§slot: usize

The slot to test against.

§

EqBytes

Compare the top of the stack against a static bytes slot.

§Operation

<value>
=> <boolean>

Fields

§slot: usize

The slot to test against.

§

MatchType

Test that the top of the stack has the given type.

§Operation

<value>
=> <boolean>

Fields

§hash: Hash

The type hash to match against.

§

MatchVariant

Test if the specified variant matches. This is distinct from Inst::MatchType because it will match immediately on the variant type if appropriate which is possible for internal types, but external types will require an additional runtime check for matching.

§Operation

<value>
=> <boolean>

Fields

§variant_hash: Hash

The exact type hash of the variant.

§enum_hash: Hash

The container type.

§index: usize

The index of the variant.

§

MatchBuiltIn

Test if the top of the stack is the given builtin type or variant.

§Operation

<value>
=> <boolean>

Fields

§type_check: TypeCheck

The type to check for.

§

MatchSequence

Test that the top of the stack is a tuple with the given length requirements.

§Operation

<value>
=> <boolean>

Fields

§type_check: TypeCheck

Type constraints that the sequence must match.

§len: usize

The minimum length to test for.

§exact: bool

Whether the operation should check exact true or minimum length false.

§

MatchObject

Test that the top of the stack is an object matching the given slot of object keys.

§Operation

<object>
=> <boolean>

Fields

§slot: usize

The slot of object keys to use.

§exact: bool

Whether the operation should check exact true or minimum length false.

§

Yield

Perform a generator yield where the value yielded is expected to be found at the top of the stack.

This causes the virtual machine to suspend itself.

§Operation

<value>
=> <value>
§

YieldUnit

Perform a generator yield with a unit.

This causes the virtual machine to suspend itself.

§Operation

=> <unit>
§

Variant

Construct a built-in variant onto the stack.

The variant will pop as many values of the stack as necessary to construct it.

§Operation

<value..>
=> <variant>

Fields

§variant: InstVariant

The kind of built-in variant to construct.

§

Op

A built-in operation like a + b that takes its operands and pushes its result to and from the stack.

§Operation

=> <value>

Fields

§op: InstOp

The actual operation.

§a: InstAddress

The address of the first argument.

§b: InstAddress

The address of the second argument.

§

Assign

A built-in operation that assigns to the left-hand side operand. Like a += b.

The target determines the left hand side operation.

§Operation

<value>
=>

Fields

§target: InstTarget

The target of the operation.

§op: InstAssignOp

The actual operation.

§

IterNext

Advance an iterator at the given position.

Fields

§offset: usize

The offset of the value being advanced.

§jump: usize

A relative jump to perform if the iterator could not be advanced.

§

Panic

Cause the VM to panic and error out without a reason.

This should only be used during testing or extreme scenarios that are completely unrecoverable.

Fields

§reason: PanicReason

The reason for the panic.

Implementations§

source§

impl Inst

source

pub fn unit() -> Self

Construct an instruction to push a unit.

source

pub fn bool(b: bool) -> Self

Construct an instruction to push a boolean.

source

pub fn byte(b: u8) -> Self

Construct an instruction to push a byte.

source

pub fn char(c: char) -> Self

Construct an instruction to push a character.

source

pub fn integer(v: i64) -> Self

Construct an instruction to push an integer.

source

pub fn float(v: f64) -> Self

Construct an instruction to push a float.

Trait Implementations§

source§

impl Clone for Inst

source§

fn clone(&self) -> Inst

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 Inst

source§

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

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

impl<'de, M> Decode<'de, M> for Inst
where M: Mode,

source§

fn decode<D>(root_decoder: D) -> Result<Self, D::Error>
where D: Decoder<'de>,

Decode the given input.
source§

impl<'de> Deserialize<'de> for Inst

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl Display for Inst

source§

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

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

impl<M> Encode<M> for Inst
where M: Mode,

source§

fn encode<E>(&self, encoder: E) -> Result<E::Ok, E::Error>
where E: Encoder,

Encode the given output.
source§

impl Serialize for Inst

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl TryClone for Inst

source§

fn try_clone(&self) -> Result<Self>

Try to clone the current value, raising an allocation error if it’s unsuccessful.
source§

fn try_clone_from(&mut self, source: &Self) -> Result<(), Error>

Performs copy-assignment from source. Read more
source§

impl Copy for Inst

Auto Trait Implementations§

§

impl Freeze for Inst

§

impl RefUnwindSafe for Inst

§

impl Send for Inst

§

impl Sync for Inst

§

impl Unpin for Inst

§

impl UnwindSafe for Inst

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

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

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

source§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. 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<T> TryToOwned for T
where T: TryClone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn try_to_owned(&self) -> Result<T, Error>

Creates owned data from borrowed data, usually by cloning. Read more
source§

impl<T> TryToString for T
where T: Display,

source§

fn try_to_string(&self) -> Result<String, Error>

Converts the given value to a String. Read more
source§

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

source§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

impl<M, D> DecodeOwned<M> for D
where D: for<'de> Decode<'de, M>, M: Mode,

source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,