Enum budvm::Instruction

source ·
pub enum Instruction<Intrinsic> {
Show 24 variants Add { left: ValueOrSource, right: ValueOrSource, destination: Destination, }, Sub { left: ValueOrSource, right: ValueOrSource, destination: Destination, }, Multiply { left: ValueOrSource, right: ValueOrSource, destination: Destination, }, Divide { left: ValueOrSource, right: ValueOrSource, destination: Destination, }, LogicalAnd { left: ValueOrSource, right: ValueOrSource, destination: Destination, }, LogicalOr { left: ValueOrSource, right: ValueOrSource, destination: Destination, }, LogicalXor { left: ValueOrSource, right: ValueOrSource, destination: Destination, }, BitwiseAnd { left: ValueOrSource, right: ValueOrSource, destination: Destination, }, BitwiseOr { left: ValueOrSource, right: ValueOrSource, destination: Destination, }, BitwiseXor { left: ValueOrSource, right: ValueOrSource, destination: Destination, }, ShiftLeft { left: ValueOrSource, right: ValueOrSource, destination: Destination, }, ShiftRight { left: ValueOrSource, right: ValueOrSource, destination: Destination, }, LogicalNot { value: ValueOrSource, destination: Destination, }, BitwiseNot { value: ValueOrSource, destination: Destination, }, Convert { value: ValueOrSource, kind: ValueKind, destination: Destination, }, If { condition: ValueOrSource, false_jump_to: usize, }, JumpTo(usize), Compare { comparison: Comparison, left: ValueOrSource, right: ValueOrSource, action: CompareAction, }, Push(ValueOrSource), Return(Option<ValueOrSource>), Load { variable_index: usize, value: ValueOrSource, }, Call { vtable_index: Option<usize>, arg_count: usize, destination: Destination, }, CallIntrinsic { intrinsic: Intrinsic, arg_count: usize, destination: Destination, }, CallInstance { target: ValueOrSource, name: Symbol, arg_count: usize, destination: Destination, },
}
Expand description

A virtual machine instruction.

This enum contains all instructions that the virtual machine is able to perform.

Variants§

§

Add

Fields

§left: ValueOrSource

The left hand side of the operation.

§right: ValueOrSource

The right hand side of the operation.

§destination: Destination

The destination for the result to be stored in.

Adds left and right and places the result in destination.

If this operation causes an overflow, Value::Void will be stored in the destination instead.

§

Sub

Fields

§left: ValueOrSource

The left hand side of the operation.

§right: ValueOrSource

The right hand side of the operation.

§destination: Destination

The destination for the result to be stored in.

Subtracts right from left and places the result in destination.

If this operation causes an overflow, Value::Void will be stored in the destination instead.

§

Multiply

Fields

§left: ValueOrSource

The left hand side of the operation.

§right: ValueOrSource

The right hand side of the operation.

§destination: Destination

The destination for the result to be stored in.

Multiply left by right and places the result in destination.

If this operation causes an overflow, Value::Void will be stored in the destination instead.

§

Divide

Fields

§left: ValueOrSource

The left hand side of the operation.

§right: ValueOrSource

The right hand side of the operation.

§destination: Destination

The destination for the result to be stored in.

Divides left by right and places the result in destination.

If this operation causes an overflow, Value::Void will be stored in the destination instead.

§

LogicalAnd

Fields

§left: ValueOrSource

The left hand side of the operation.

§right: ValueOrSource

The right hand side of the operation.

§destination: Destination

The destination for the result to be stored in.

Performs a logical and of left and right and places the result in destination. This operation always results in a Value::Boolean.

left and right will be checked for thruthyness. If both are truthy, this operation will store true in destination. Otherwise, false will be stored.

Short Circuiting

This instruction will not evaluate right’s truthiness if left is false.

§

LogicalOr

Fields

§left: ValueOrSource

The left hand side of the operation.

§right: ValueOrSource

The right hand side of the operation.

§destination: Destination

The destination for the result to be stored in.

Performs a logical or of left and right and places the result in destination. This operation always results in a Value::Boolean.

left and right will be checked for thruthyness. If either are truthy, this operation will store true in destination. Otherwise, false will be stored.

Short Circuiting

This instruction will not evaluate right’s truthiness if left is true.

§

LogicalXor

Fields

§left: ValueOrSource

The left hand side of the operation.

§right: ValueOrSource

The right hand side of the operation.

§destination: Destination

The destination for the result to be stored in.

Performs a logical exclusive-or of left and right and places the result in destination. This operation always results in a Value::Boolean.

left and right will be checked for thruthyness. If one is truthy and the other is not, this operation will store true in destination. Otherwise, false will be stored.

§

BitwiseAnd

Fields

§left: ValueOrSource

The left hand side of the operation.

§right: ValueOrSource

The right hand side of the operation.

§destination: Destination

The destination for the result to be stored in.

Performs a bitwise and of left and right and places the result in destination. This operation always results in a Value::Integer.

If either left or right are not Value::Integer, a fault will be returned.

The result will have each bit set based on whether the corresponding bit in both left and right are both 1.

§

BitwiseOr

Fields

§left: ValueOrSource

The left hand side of the operation.

§right: ValueOrSource

The right hand side of the operation.

§destination: Destination

The destination for the result to be stored in.

Performs a bitwise or of left and right and places the result in destination. This operation always results in a Value::Integer.

If either left or right are not Value::Integer, a fault will be returned.

The result will have each bit set based on whether either corresponding bit in left or right are 1.

§

BitwiseXor

Fields

§left: ValueOrSource

The left hand side of the operation.

§right: ValueOrSource

The right hand side of the operation.

§destination: Destination

The destination for the result to be stored in.

Performs a bitwise exclusive-or of left and right and places the result in destination. This operation always results in a Value::Integer.

If either left or right are not Value::Integer, a fault will be returned.

The result will have each bit set based on whether only one corresponding bit in either left or right are 1.

§

ShiftLeft

Fields

§left: ValueOrSource

The value to shift

§right: ValueOrSource

The number of bits to shift by

§destination: Destination

The destination for the result to be stored in.

Performs a bitwise shift left of left by right bits, storing the result in destination.

This operation requires both operands to be integers. If either are not integers, a fault will be returned.

§

ShiftRight

Fields

§left: ValueOrSource

The value to shift

§right: ValueOrSource

The number of bits to shift by

§destination: Destination

The destination for the result to be stored in.

Performs a bitwise shift right of left by right bits, storing the result in destination.

This operation requires both operands to be integers. If either are not integers, a fault will be returned.

§

LogicalNot

Fields

§value: ValueOrSource

The left hand side of the operation.

§destination: Destination

The destination for the result to be stored in.

Performs a logical not operation for value, storing the result in destination.

If the value is truthy, false will be stored in the destination. If the value is falsey, true will be stored in the destination.

§

BitwiseNot

Fields

§value: ValueOrSource

The left hand side of the operation.

§destination: Destination

The destination for the result to be stored in.

Performs a bitwise not operation for value, storing the result in destination. This operation always results in a Value::Integer.

If value cannot be coerced to an integer, a fault will be returned.

The result will be value with each bit flipped.

§

Convert

Fields

§value: ValueOrSource

The left hand side of the operation.

§kind: ValueKind

The type to convert to.

§destination: Destination

The destination for the converted value to be stored in.

Converts a value to another type, storing the result in destination.

If value cannot be converted, a fault will be returned.

§

If

Fields

§condition: ValueOrSource

The source of the condition.

§false_jump_to: usize

The 0-based index of the instruction to jump to. This index is relative to the begining of the set of instructions being executed.

Checks condition.is_truthy(), jumping to the target instruction if false.

If truthy, the virtual machine continues executing the next instruction in sequence.

If not truthy, the virtual machine jumps to number false_jump_to. This number is the absolute number from the start of the set of instructions being executed.

Jumping beyond the end of the function will not cause an error, but will instead cause the current function to return.

§

JumpTo(usize)

Jumps to the instruction number within the current function.

This number is the absolute number from the start of the function being executed.

Jumping beyond the end of the function will not cause an error, but will instead cause the current function to return.

§

Compare

Fields

§comparison: Comparison

The comparison to perform.

§left: ValueOrSource

The left hand side of the operation.

§right: ValueOrSource

The right hand side of the operation.

§action: CompareAction

The action to take with the result of the comparison.

Compares left and right using comparison to evaluate a boolean result.

If CompareAction::Store is used, the boolean result will be stored in the provided destination.

If CompareAction::JumpIfFalse is used and the result is false, execution will jump to the 0-based instruction index within the current set of executing instructions. If the result is true, the next instruction will continue executing.

§

Push(ValueOrSource)

Pushes a value to the stack.

§

Return(Option<ValueOrSource>)

Returns from the current stack frame.

§

Load

Fields

§variable_index: usize

The index of the variable to store the value in.

§value: ValueOrSource

The value or source of the value to store.

Loads a value into a variable.

§

Call

Fields

§vtable_index: Option<usize>

The vtable index within the current module of the function to call. If None, the current function is called recursively.

If a vtable index is provided but is beyond the number of functions registered to the current module, FaultKind::InvalidVtableIndex will be returned.

§arg_count: usize

The number of arguments on the stack that should be used as arguments to this call.

§destination: Destination

The destination for the result of the call.

Calls a function.

When calling a function, values on the stack are “passed” to the function being pushed to the stack before calling the function. To ensure the correct number of arguments are taken even when variable argument lists are supported, the number of arguments is passed and controls the baseline of the stack.

Upon returning from a function call, the arguments will no longer be on the stack. The value returned from the function (or Value::Void if no value was returned) will be placed in destination.

§

CallIntrinsic

Fields

§intrinsic: Intrinsic

The runtime intrinsic to call.

§arg_count: usize

The number of arguments on the stack that should be used as arguments to this call.

§destination: Destination

The destination for the result of the call.

Calls an intrinsic runtime function.

When calling a function, values on the stack are “passed” to the function being pushed to the stack before calling the function. To ensure the correct number of arguments are taken even when variable argument lists are supported, the number of arguments is passed and controls the baseline of the stack.

Upon returning from a function call, the arguments will no longer be on the stack. The value returned from the function (or Value::Void if no value was returned) will be placed in destination.

§

CallInstance

Fields

§target: ValueOrSource

The target of the function call. If ValueOrSource::Stack, the value on the stack prior to the arguments is the target of the call.

§name: Symbol

The name of the function to call.

§arg_count: usize

The number of arguments on the stack that should be used as arguments to this call.

§destination: Destination

The destination for the result of the call.

Calls a function by name on a value.

When calling a function, values on the stack are “passed” to the function being pushed to the stack before calling the function. To ensure the correct number of arguments are taken even when variable argument lists are supported, the number of arguments is passed and controls the baseline of the stack.

Upon returning from a function call, the arguments will no longer be on the stack. The value returned from the function (or Value::Void if no value was returned) will be placed in destination.

Trait Implementations§

source§

impl<Intrinsic: Clone> Clone for Instruction<Intrinsic>

source§

fn clone(&self) -> Instruction<Intrinsic>

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<Intrinsic: Debug> Debug for Instruction<Intrinsic>

source§

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

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

impl<Intrinsic> Display for Instruction<Intrinsic>where Intrinsic: Display,

source§

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

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

impl<Intrinsic: PartialEq> PartialEq<Instruction<Intrinsic>> for Instruction<Intrinsic>

source§

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

source§

impl<Intrinsic> StructuralEq for Instruction<Intrinsic>

source§

impl<Intrinsic> StructuralPartialEq for Instruction<Intrinsic>

Auto Trait Implementations§

§

impl<Intrinsic> !RefUnwindSafe for Instruction<Intrinsic>

§

impl<Intrinsic> Send for Instruction<Intrinsic>where Intrinsic: Send,

§

impl<Intrinsic> Sync for Instruction<Intrinsic>where Intrinsic: Sync,

§

impl<Intrinsic> Unpin for Instruction<Intrinsic>where Intrinsic: Unpin,

§

impl<Intrinsic> !UnwindSafe for Instruction<Intrinsic>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · 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 Twhere 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 Twhere 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 Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.