Enum budvm::ir::Instruction

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

An intermediate representation of an crate::Instruction.

Variants§

§

Add

Fields

§left: LiteralOrSource

The left hand side of the operation.

§right: LiteralOrSource

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

The left hand side of the operation.

§right: LiteralOrSource

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

The left hand side of the operation.

§right: LiteralOrSource

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

The left hand side of the operation.

§right: LiteralOrSource

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

The left hand side of the operation.

§right: LiteralOrSource

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

The left hand side of the operation.

§right: LiteralOrSource

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

The left hand side of the operation.

§right: LiteralOrSource

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.

§

LogicalNot

Fields

§value: LiteralOrSource

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.

§

BitwiseAnd

Fields

§left: LiteralOrSource

The left hand side of the operation.

§right: LiteralOrSource

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 cannot be coerced to an 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: LiteralOrSource

The left hand side of the operation.

§right: LiteralOrSource

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 cannot be coerced to an 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: LiteralOrSource

The left hand side of the operation.

§right: LiteralOrSource

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 cannot be coerced to an 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.

§

BitwiseNot

Fields

§value: LiteralOrSource

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

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.

§

ShiftLeft

Fields

§left: LiteralOrSource

The value to shift

§right: LiteralOrSource

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

The value to shift

§right: LiteralOrSource

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.

§

If

Fields

§condition: LiteralOrSource

The source of the condition.

§false_jump_to: Label

The label to jump to if the condition is falsey.

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

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

If not truthy, the virtual machine jumps to label false_jump_to.

§

JumpTo(Label)

Jump execution to the address of the given Label.

§

Label(Label)

Labels the next instruction with the given Label.

§

Compare

Fields

§comparison: Comparison

The comparison to perform.

§left: LiteralOrSource

The left hand side of the operation.

§right: LiteralOrSource

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 label specified. If the result is true, the next instruction will continue executing.

§

Push(LiteralOrSource)

Pushes a value to the stack.

§

Load

Fields

§value: LiteralOrSource

The index of the variable to store the value in.

§variable: Variable

The value or source of the value to store.

Loads a value into a variable.

§

Return(Option<LiteralOrSource>)

Returns from the current stack frame.

§

Call

Fields

§function: Option<Symbol>

The name of the function to call. If None, the current function is called recursively.

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

The target of the function call. If LiteralOrSource::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> StructuralPartialEq for Instruction<Intrinsic>

Auto Trait Implementations§

§

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

§

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>where Intrinsic: UnwindSafe,

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.