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: LiteralOrSourceThe left hand side of the operation.
right: LiteralOrSourceThe 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: LiteralOrSourceThe left hand side of the operation.
right: LiteralOrSourceThe 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: LiteralOrSourceThe left hand side of the operation.
right: LiteralOrSourceThe 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: LiteralOrSourceThe left hand side of the operation.
right: LiteralOrSourceThe 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: LiteralOrSourceThe left hand side of the operation.
right: LiteralOrSourceThe 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: LiteralOrSourceThe left hand side of the operation.
right: LiteralOrSourceThe 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: LiteralOrSourceThe left hand side of the operation.
right: LiteralOrSourceThe 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.
LogicalNot
Fields
value: LiteralOrSourceThe 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.
BitwiseAnd
Fields
left: LiteralOrSourceThe left hand side of the operation.
right: LiteralOrSourceThe 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 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: LiteralOrSourceThe left hand side of the operation.
right: LiteralOrSourceThe 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 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: LiteralOrSourceThe left hand side of the operation.
right: LiteralOrSourceThe 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 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: LiteralOrSourceThe 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: LiteralOrSourceThe 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.
ShiftLeft
Fields
left: LiteralOrSourceThe value to shift
right: LiteralOrSourceThe 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: LiteralOrSourceThe value to shift
right: LiteralOrSourceThe 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.
If
Fields
condition: LiteralOrSourceThe source of the condition.
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: ComparisonThe comparison to perform.
left: LiteralOrSourceThe left hand side of the operation.
right: LiteralOrSourceThe 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 label specified. If the result is true, the
next instruction will continue executing.
Push(LiteralOrSource)
Pushes a value to the stack.
Load
Fields
value: LiteralOrSourceThe index of the variable to store the value in.
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: 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: LiteralOrSourceThe target of the function call. If LiteralOrSource::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 ==.