pub struct LoopScope<'a, T, Intrinsic>where
T: BorrowMut<CodeBlockBuilder<Intrinsic>>,{
pub break_label: Label,
pub continue_label: Label,
/* private fields */
}
Expand description
A loop within a CodeBlockBuilder
.
Fields§
§break_label: Label
The label for a break
operation.
continue_label: Label
The label for a continue
operation.
Implementations§
source§impl<'a, T, Intrinsic> LoopScope<'a, T, Intrinsic>where
T: BorrowMut<CodeBlockBuilder<Intrinsic>>,
impl<'a, T, Intrinsic> LoopScope<'a, T, Intrinsic>where T: BorrowMut<CodeBlockBuilder<Intrinsic>>,
sourcepub fn label_break(&mut self)
pub fn label_break(&mut self)
Marks the next instruction as where the break
operation should jump
to.
sourcepub fn label_continue(&mut self)
pub fn label_continue(&mut self)
Marks the next instruction as where the continue
operation should jump
to.
Methods from Deref<Target = CodeBlockBuilder<Intrinsic>>§
sourcepub fn new_argument(&mut self, name: impl Into<Symbol>) -> Argument
pub fn new_argument(&mut self, name: impl Into<Symbol>) -> Argument
Adds a new argument with the given name.
sourcepub fn argument(&self, name: &Symbol) -> Option<Argument>
pub fn argument(&self, name: &Symbol) -> Option<Argument>
Finds an argument by a given name, or None if not found.
sourcepub fn named_label(&mut self, name: impl Into<Symbol>) -> Label
pub fn named_label(&mut self, name: impl Into<Symbol>) -> Label
Create a new label with a given name.
sourcepub fn push(&mut self, operation: Instruction<Intrinsic>)
pub fn push(&mut self, operation: Instruction<Intrinsic>)
Push an instruction.
To push a value to the stack use push_to_stack
.
sourcepub fn lookup(&self, symbol: &Symbol) -> Option<&ScopeSymbol>
pub fn lookup(&self, symbol: &Symbol) -> Option<&ScopeSymbol>
Looks up a symbol.
sourcepub fn loop_info(&self, name: Option<&Symbol>) -> Option<&LoopInfo>
pub fn loop_info(&self, name: Option<&Symbol>) -> Option<&LoopInfo>
Returns the loop information for a given name, or the current loop if no name is provided.
sourcepub fn store_into_destination(
&mut self,
value: LiteralOrSource,
destination: Destination
)
pub fn store_into_destination( &mut self, value: LiteralOrSource, destination: Destination )
Adds the appropriate instruction to store value
into destination
.
sourcepub fn load_from_symbol(
&mut self,
symbol: &Symbol,
destination: Destination
) -> Result<(), LinkError>
pub fn load_from_symbol( &mut self, symbol: &Symbol, destination: Destination ) -> Result<(), LinkError>
Adds the correct instruction to load a value from symbol
and store it
in destination
.
sourcepub fn variable_index_from_name(&mut self, name: &Symbol) -> Variable
pub fn variable_index_from_name(&mut self, name: &Symbol) -> Variable
Looks up an existing location for a variable with the provided name
.
If an existing location is not found, new space will be allocated for
it and returned.
sourcepub fn new_temporary_variable(&mut self) -> Variable
pub fn new_temporary_variable(&mut self) -> Variable
Creates a new temporary variable.
Internally this simply uses a counter to create a new variable each time
this is called named $1
, $2
, and so on.
sourcepub fn add(
&mut self,
left: impl Into<LiteralOrSource>,
right: impl Into<LiteralOrSource>,
destination: impl Into<Destination>
)
pub fn add( &mut self, left: impl Into<LiteralOrSource>, right: impl Into<LiteralOrSource>, destination: impl Into<Destination> )
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.
sourcepub fn sub(
&mut self,
left: impl Into<LiteralOrSource>,
right: impl Into<LiteralOrSource>,
destination: impl Into<Destination>
)
pub fn sub( &mut self, left: impl Into<LiteralOrSource>, right: impl Into<LiteralOrSource>, destination: impl Into<Destination> )
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.
sourcepub fn multiply(
&mut self,
left: impl Into<LiteralOrSource>,
right: impl Into<LiteralOrSource>,
destination: impl Into<Destination>
)
pub fn multiply( &mut self, left: impl Into<LiteralOrSource>, right: impl Into<LiteralOrSource>, destination: impl Into<Destination> )
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.
sourcepub fn divide(
&mut self,
left: impl Into<LiteralOrSource>,
right: impl Into<LiteralOrSource>,
destination: impl Into<Destination>
)
pub fn divide( &mut self, left: impl Into<LiteralOrSource>, right: impl Into<LiteralOrSource>, destination: impl Into<Destination> )
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.
sourcepub fn logical_and(
&mut self,
left: impl Into<LiteralOrSource>,
right: impl Into<LiteralOrSource>,
destination: impl Into<Destination>
)
pub fn logical_and( &mut self, left: impl Into<LiteralOrSource>, right: impl Into<LiteralOrSource>, destination: impl Into<Destination> )
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.
sourcepub fn logical_or(
&mut self,
left: impl Into<LiteralOrSource>,
right: impl Into<LiteralOrSource>,
destination: impl Into<Destination>
)
pub fn logical_or( &mut self, left: impl Into<LiteralOrSource>, right: impl Into<LiteralOrSource>, destination: impl Into<Destination> )
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.
sourcepub fn logical_xor(
&mut self,
left: impl Into<LiteralOrSource>,
right: impl Into<LiteralOrSource>,
destination: impl Into<Destination>
)
pub fn logical_xor( &mut self, left: impl Into<LiteralOrSource>, right: impl Into<LiteralOrSource>, destination: impl Into<Destination> )
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.
sourcepub fn logical_not(
&mut self,
value: impl Into<LiteralOrSource>,
destination: impl Into<Destination>
)
pub fn logical_not( &mut self, value: impl Into<LiteralOrSource>, destination: impl Into<Destination> )
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.
sourcepub fn bitwise_and(
&mut self,
left: impl Into<LiteralOrSource>,
right: impl Into<LiteralOrSource>,
destination: impl Into<Destination>
)
pub fn bitwise_and( &mut self, left: impl Into<LiteralOrSource>, right: impl Into<LiteralOrSource>, destination: impl Into<Destination> )
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.
sourcepub fn bitwise_or(
&mut self,
left: impl Into<LiteralOrSource>,
right: impl Into<LiteralOrSource>,
destination: impl Into<Destination>
)
pub fn bitwise_or( &mut self, left: impl Into<LiteralOrSource>, right: impl Into<LiteralOrSource>, destination: impl Into<Destination> )
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.
sourcepub fn bitwise_xor(
&mut self,
left: impl Into<LiteralOrSource>,
right: impl Into<LiteralOrSource>,
destination: impl Into<Destination>
)
pub fn bitwise_xor( &mut self, left: impl Into<LiteralOrSource>, right: impl Into<LiteralOrSource>, destination: impl Into<Destination> )
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.
sourcepub fn bitwise_not(
&mut self,
value: impl Into<LiteralOrSource>,
destination: impl Into<Destination>
)
pub fn bitwise_not( &mut self, value: impl Into<LiteralOrSource>, destination: impl Into<Destination> )
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.
sourcepub fn convert(
&mut self,
value: impl Into<LiteralOrSource>,
kind: impl Into<ValueKind>,
destination: impl Into<Destination>
)
pub fn convert( &mut self, value: impl Into<LiteralOrSource>, kind: impl Into<ValueKind>, destination: impl Into<Destination> )
Converts a value to another type, storing the result in destination
.
If value
cannot be converted, a fault will be returned.
sourcepub fn shift_left(
&mut self,
left: impl Into<LiteralOrSource>,
right: impl Into<LiteralOrSource>,
destination: impl Into<Destination>
)
pub fn shift_left( &mut self, left: impl Into<LiteralOrSource>, right: impl Into<LiteralOrSource>, destination: impl Into<Destination> )
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.
sourcepub fn shift_right(
&mut self,
left: impl Into<LiteralOrSource>,
right: impl Into<LiteralOrSource>,
destination: impl Into<Destination>
)
pub fn shift_right( &mut self, left: impl Into<LiteralOrSource>, right: impl Into<LiteralOrSource>, destination: impl Into<Destination> )
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.
sourcepub fn jump_if_false(
&mut self,
condition: impl Into<LiteralOrSource>,
false_jump_to: impl Into<Label>
)
pub fn jump_if_false( &mut self, condition: impl Into<LiteralOrSource>, false_jump_to: impl Into<Label> )
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
.
Consider using begin_if()
instead for a more convinient
option.
sourcepub fn begin_if(
&mut self,
condition: impl Into<LiteralOrSource>
) -> If<'_, Intrinsic>
pub fn begin_if( &mut self, condition: impl Into<LiteralOrSource> ) -> If<'_, Intrinsic>
Begins an if block with the given condition.
If the condition is the result of a comparsion consider
begin_if_comparison()
.
sourcepub fn jump_to(&mut self, label: impl Into<Label>)
pub fn jump_to(&mut self, label: impl Into<Label>)
Jump execution to the address of the given Label
.
Consider using begin_loop()
instead of using
jump_to
for looping.
sourcepub fn label(&mut self, label: impl Into<Label>)
pub fn label(&mut self, label: impl Into<Label>)
Labels the next instruction with the given Label
.
sourcepub fn begin_loop(
&mut self,
name: Option<Symbol>,
result: Destination
) -> LoopScope<'_, Self, Intrinsic>
pub fn begin_loop( &mut self, name: Option<Symbol>, result: Destination ) -> LoopScope<'_, Self, Intrinsic>
Begins a loop with the given name
. The result of the loop will be
stored in result
. If the loop does not return a result, the
destination will be untouched.
sourcepub fn compare(
&mut self,
comparison: impl Into<Comparison>,
left: impl Into<LiteralOrSource>,
right: impl Into<LiteralOrSource>,
action: impl Into<CompareAction>
)
pub fn compare( &mut self, comparison: impl Into<Comparison>, left: impl Into<LiteralOrSource>, right: impl Into<LiteralOrSource>, action: impl Into<CompareAction> )
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. Consider begin_if_comparison
for more convinient jumping.
sourcepub fn begin_if_comparison(
&mut self,
comparison: Comparison,
left: impl Into<LiteralOrSource>,
right: impl Into<LiteralOrSource>
) -> If<'_, Intrinsic>
pub fn begin_if_comparison( &mut self, comparison: Comparison, left: impl Into<LiteralOrSource>, right: impl Into<LiteralOrSource> ) -> If<'_, Intrinsic>
Begins an if block with the given comparison.
sourcepub fn push_to_stack(&mut self, value: impl Into<LiteralOrSource>)
pub fn push_to_stack(&mut self, value: impl Into<LiteralOrSource>)
Pushes a value to the stack.
sourcepub fn load(
&mut self,
value: impl Into<LiteralOrSource>,
variable: impl Into<Variable>
)
pub fn load( &mut self, value: impl Into<LiteralOrSource>, variable: impl Into<Variable> )
Loads a value
into a variable.
sourcepub fn return_value(&mut self, value: impl Into<LiteralOrSource>)
pub fn return_value(&mut self, value: impl Into<LiteralOrSource>)
Returns a value from the current stack frame.
sourcepub fn return_void(&mut self)
pub fn return_void(&mut self)
Returns from the current stack frame without a value.
sourcepub fn call(
&mut self,
function: impl Into<Symbol>,
arg_count: usize,
destination: impl Into<Destination>
)
pub fn call( &mut self, function: impl Into<Symbol>, arg_count: usize, destination: impl Into<Destination> )
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
.
There is also recurse()
always recursing the current function.
sourcepub fn recurse(&mut self, arg_count: usize, destination: impl Into<Destination>)
pub fn recurse(&mut self, arg_count: usize, destination: impl Into<Destination>)
Calls the current function recursively.
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
.
sourcepub fn call_intrinsic(
&mut self,
intrinsic: impl Into<Intrinsic>,
arg_count: usize,
destination: impl Into<Destination>
)
pub fn call_intrinsic( &mut self, intrinsic: impl Into<Intrinsic>, arg_count: usize, destination: impl Into<Destination> )
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
.
sourcepub fn call_instance(
&mut self,
target: impl Into<LiteralOrSource>,
name: impl Into<Symbol>,
arg_count: usize,
destination: impl Into<Destination>
)
pub fn call_instance( &mut self, target: impl Into<LiteralOrSource>, name: impl Into<Symbol>, arg_count: usize, destination: impl Into<Destination> )
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
.