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: ValueOrSourceThe left hand side of the operation.
right: ValueOrSourceThe right hand side of the operation.
destination: DestinationThe 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: ValueOrSourceThe left hand side of the operation.
right: ValueOrSourceThe right hand side of the operation.
destination: DestinationThe 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: ValueOrSourceThe left hand side of the operation.
right: ValueOrSourceThe right hand side of the operation.
destination: DestinationThe 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: ValueOrSourceThe left hand side of the operation.
right: ValueOrSourceThe right hand side of the operation.
destination: DestinationThe 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: ValueOrSourceThe left hand side of the operation.
right: ValueOrSourceThe right hand side of the operation.
destination: DestinationThe 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: ValueOrSourceThe left hand side of the operation.
right: ValueOrSourceThe right hand side of the operation.
destination: DestinationThe 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: ValueOrSourceThe left hand side of the operation.
right: ValueOrSourceThe right hand side of the operation.
destination: DestinationThe 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: ValueOrSourceThe left hand side of the operation.
right: ValueOrSourceThe right hand side of the operation.
destination: DestinationThe 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: ValueOrSourceThe left hand side of the operation.
right: ValueOrSourceThe right hand side of the operation.
destination: DestinationThe 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: ValueOrSourceThe left hand side of the operation.
right: ValueOrSourceThe right hand side of the operation.
destination: DestinationThe 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: ValueOrSourceThe value to shift
right: ValueOrSourceThe number of bits to shift by
destination: DestinationThe 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: ValueOrSourceThe value to shift
right: ValueOrSourceThe number of bits to shift by
destination: DestinationThe 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: ValueOrSourceThe left hand side of the operation.
destination: DestinationThe 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: ValueOrSourceThe left hand side of the operation.
destination: DestinationThe 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: ValueOrSourceThe left hand side of the operation.
destination: DestinationThe 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: ValueOrSourceThe source of the condition.
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: ComparisonThe comparison to perform.
left: ValueOrSourceThe left hand side of the operation.
right: ValueOrSourceThe right hand side of the operation.
action: CompareActionThe 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
value: ValueOrSourceThe 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: usizeThe number of arguments on the stack that should be used as arguments to this call.
destination: DestinationThe 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: IntrinsicThe runtime intrinsic to call.
arg_count: usizeThe number of arguments on the stack that should be used as arguments to this call.
destination: DestinationThe 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: ValueOrSourceThe target of the function call. If ValueOrSource::Stack, the value on the
stack prior to the arguments is the target of the call.
arg_count: usizeThe number of arguments on the stack that should be used as arguments to this call.
destination: DestinationThe 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>
impl<Intrinsic: Clone> Clone for Instruction<Intrinsic>
source§fn clone(&self) -> Instruction<Intrinsic>
fn clone(&self) -> Instruction<Intrinsic>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moresource§impl<Intrinsic: Debug> Debug for Instruction<Intrinsic>
impl<Intrinsic: Debug> Debug for Instruction<Intrinsic>
source§impl<Intrinsic> Display for Instruction<Intrinsic>where
Intrinsic: Display,
impl<Intrinsic> Display for Instruction<Intrinsic>where Intrinsic: Display,
source§impl<Intrinsic: PartialEq> PartialEq<Instruction<Intrinsic>> for Instruction<Intrinsic>
impl<Intrinsic: PartialEq> PartialEq<Instruction<Intrinsic>> for Instruction<Intrinsic>
source§fn eq(&self, other: &Instruction<Intrinsic>) -> bool
fn eq(&self, other: &Instruction<Intrinsic>) -> bool
self and other values to be equal, and is used
by ==.