Enum Inst

Source
pub enum Inst {
Show 53 variants Not, Add, AddAssign { offset: usize, }, Sub, SubAssign { offset: usize, }, Mul, MulAssign { offset: usize, }, Div, DivAssign { offset: usize, }, Call { hash: Hash, args: usize, }, CallInstance { hash: Hash, args: usize, }, LoadInstanceFn { hash: Hash, }, CallFn { args: usize, }, IndexGet, ArrayIndexGet { index: usize, }, ObjectSlotIndexGet { slot: usize, }, IndexSet, Integer { number: i64, }, Float { number: f64, }, Pop, PopN { count: usize, }, Clean { count: usize, }, Copy { offset: usize, }, Dup, Replace { offset: usize, }, Return, ReturnUnit, Lt, Gt, Lte, Gte, Eq, Neq, Jump { offset: isize, }, JumpIf { offset: isize, }, JumpIfNot { offset: isize, }, Unit, Bool { value: bool, }, Array { count: usize, }, Object { slot: usize, }, Char { c: char, }, String { slot: usize, }, Is, And, Or, IsUnit, EqCharacter { character: char, }, EqInteger { integer: i64, }, EqStaticString { slot: usize, }, MatchArray { len: usize, exact: bool, }, MatchObject { slot: usize, exact: bool, }, Type { hash: Hash, }, Panic { reason: Panic, },
}
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>
§

Add

Add two things together.

This is the result of an <a> + <b> expression.

§

AddAssign

Add a value to the given frame offset.

This is the result of an <offset> += <b> expression.

Fields

§offset: usize

The frame offset to assign to.

§

Sub

Subtract two things.

This is the result of an <a> - <b> expression.

§

SubAssign

Subtract a value to the given frame offset.

This is the result of an <offset> -= <b> expression.

Fields

§offset: usize

The frame offset to assign to.

§

Mul

Multiply two things.

This is the result of an <a> * <b> expression.

§

MulAssign

Multiply a value to the given frame offset.

This is the result of an <offset> *= <b> expression.

Fields

§offset: usize

The frame offset to assign to.

§

Div

Divide two things.

This is the result of an <a> / <b> expression.

§

DivAssign

Divide a value to the given frame offset.

This is the result of an <offset> /= <b> expression.

Fields

§offset: usize

The frame offset to assign to.

§

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.

§

CallInstance

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

ArrayIndexGet

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

Note: this is a specialized variant of ExprIndexGet where we know that the top of the stack is supposed to be an array.

§Operation

<array>
=> <value>

Fields

§index: usize

The index to fetch.

§

ObjectSlotIndexGet

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

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

Note: this is a specialized variant of ExprIndexGet where we know that the top of the stack is supposed to be an array.

§Operation

<object>
=> <value>

Fields

§slot: usize

The static string slot corresponding to the index to fetch.

§

IndexSet

Perform an index set operation.

§Operation

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

Integer

Push a literal integer.

Fields

§number: i64

The number to push.

§

Float

Push a literal float into a slot.

Fields

§number: f64

The number to push.

§

Pop

Pop the value on the stack.

§

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.

§

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

Push 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 and increasing a reference count.

Fields

§offset: usize

Offset to copy value from.

§

Dup

Duplicate the value at the top of the stack.

§Operation

=> <value>
§

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.

§

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.

§

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.

§

Lt

Compare two values on the stack for lt and push the result as a boolean on the stack.

§

Gt

Compare two values on the stack for gt and push the result as a boolean on the stack.

§

Lte

Compare two values on the stack for lte and push the result as a boolean on the stack.

§

Gte

Compare two values on the stack for gte and push the result as a boolean on the stack.

§

Eq

Compare two values on the stack for equality and push the result as a boolean on the stack.

§Operation

<b>
<a>
=> <bool>
§

Neq

Compare two values on the stack for inequality and push the result as a boolean on the stack.

§Operation

<b>
<a>
=> <bool>
§

Jump

Unconditionally jump to offset relative to the current instruction pointer.

§Operation

*nothing*
=> *nothing*

Fields

§offset: isize

Offset to jump to.

§

JumpIf

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

§Operation

<boolean>
=> *nothing*

Fields

§offset: isize

Offset to jump to.

§

JumpIfNot

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

§Operation

<boolean>
=> *nothing*

Fields

§offset: isize

Offset to jump to.

§

Unit

Push a unit value onto the stack.

§Operation

=> <unit>
§

Bool

Push a boolean value onto the stack.

§Operation

=> <boolean>

Fields

§value: bool

The boolean value to push.

§

Array

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

Fields

§count: usize

The size of the array.

§

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.

§

Char

Load a literal character.

Fields

§c: char

The literal character to load.

§

String

Load a literal string.

Fields

§slot: usize

The static string slot to load the string from.

§

Is

Test if the top of the stack is an instance of the second item on the stack.

§Operation

<value>
<type>
=> <boolean>
§

And

Pop two values from the stack and test if they are both boolean true.

§Operation

<boolean>
<boolean>
=> <boolean>
§

Or

Pop two values from the stack and test if either of them are boolean true.

§Operation

<boolean>
<boolean>
=> <boolean>
§

IsUnit

Test if the top of the stack is a unit.

§Operation

<value>
=> <boolean>
§

EqCharacter

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

§Operation

<value>
=> <boolean>

Fields

§character: 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.

§

EqStaticString

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

§Operation

<value>
=> <boolean>

Fields

§slot: usize

The slot to test against.

§

MatchArray

Test that the top of the stack is an array with the given length requirements.

§Operation

<value>
=> <boolean>

Fields

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

§

Type

Push the type with the given hash as a value on the stack.

§Operation

=> <value>

Fields

§hash: Hash

The hash of the type.

§

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: Panic

The mark of the panic.

Trait Implementations§

Source§

impl Clone for Inst

Source§

fn clone(&self) -> Inst

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 Inst

Source§

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

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

impl Display for Inst

Source§

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

Formats the value using the given formatter. 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: 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<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> ToString for T
where T: Display + ?Sized,

Source§

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

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

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

Source§

fn vzip(self) -> V