pub enum Inst {
Show 73 variants
Not,
Neg,
Closure {
hash: Hash,
count: usize,
},
CallOffset {
offset: usize,
call: Call,
args: usize,
},
Call {
hash: Hash,
args: usize,
},
CallAssociated {
hash: Hash,
args: usize,
},
LoadInstanceFn {
hash: Hash,
},
CallFn {
args: usize,
},
IndexGet {
target: InstAddress,
index: InstAddress,
},
TupleIndexGet {
index: usize,
},
TupleIndexSet {
index: usize,
},
TupleIndexGetAt {
offset: usize,
index: usize,
},
ObjectIndexGet {
slot: usize,
},
ObjectIndexSet {
slot: usize,
},
ObjectIndexGetAt {
offset: usize,
slot: usize,
},
IndexSet,
Await,
Select {
len: usize,
},
LoadFn {
hash: Hash,
},
Push {
value: InstValue,
},
Pop,
PopN {
count: usize,
},
PopAndJumpIfNot {
count: usize,
jump: usize,
},
Clean {
count: usize,
},
Copy {
offset: usize,
},
Move {
offset: usize,
},
Drop {
offset: usize,
},
Replace {
offset: usize,
},
Swap {
a: usize,
b: usize,
},
Return {
address: InstAddress,
clean: usize,
},
ReturnUnit,
Jump {
jump: usize,
},
JumpIf {
jump: usize,
},
JumpIfOrPop {
jump: usize,
},
JumpIfNotOrPop {
jump: usize,
},
JumpIfBranch {
branch: i64,
jump: usize,
},
Vec {
count: usize,
},
Tuple1 {
args: [InstAddress; 1],
},
Tuple2 {
args: [InstAddress; 2],
},
Tuple3 {
args: [InstAddress; 3],
},
Tuple4 {
args: [InstAddress; 4],
},
Tuple {
count: usize,
},
PushTuple,
Object {
slot: usize,
},
Range {
range: InstRange,
},
EmptyStruct {
hash: Hash,
},
Struct {
hash: Hash,
slot: usize,
},
UnitVariant {
hash: Hash,
},
StructVariant {
hash: Hash,
slot: usize,
},
String {
slot: usize,
},
Bytes {
slot: usize,
},
StringConcat {
len: usize,
size_hint: usize,
},
Format {
spec: FormatSpec,
},
IsUnit,
Try {
address: InstAddress,
clean: usize,
preserve: bool,
},
EqByte {
byte: u8,
},
EqChar {
char: char,
},
EqInteger {
integer: i64,
},
EqBool {
boolean: bool,
},
EqString {
slot: usize,
},
EqBytes {
slot: usize,
},
MatchType {
hash: Hash,
},
MatchVariant {
variant_hash: Hash,
enum_hash: Hash,
index: usize,
},
MatchBuiltIn {
type_check: TypeCheck,
},
MatchSequence {
type_check: TypeCheck,
len: usize,
exact: bool,
},
MatchObject {
slot: usize,
exact: bool,
},
Yield,
YieldUnit,
Variant {
variant: InstVariant,
},
Op {
op: InstOp,
a: InstAddress,
b: InstAddress,
},
Assign {
target: InstTarget,
op: InstAssignOp,
},
IterNext {
offset: usize,
jump: usize,
},
Panic {
reason: PanicReason,
},
}
Expand description
An operation in the stack-based virtual machine.
Variants§
Not
Not operator. Takes a boolean from the top of the stack and inverts its logical value.
§Operation
<bool>
=> <bool>
Neg
Closure
Construct a closure that takes the given number of arguments and
captures count
elements from the top of the stack.
§Operation
<value..>
=> <fn>
Fields
CallOffset
Perform a function call within the same unit.
It will construct a new stack frame which includes the last args
number of entries.
Fields
Call
Perform a function call.
It will construct a new stack frame which includes the last args
number of entries.
Fields
CallAssociated
Perform a instance function call.
The instance being called on should be on top of the stack, followed by
args
number of arguments.
Fields
LoadInstanceFn
Lookup the specified instance function and put it on the stack. This might help in cases where a single instance function is called many times (like in a loop) since it avoids calculating its full hash on every iteration.
Note that this does not resolve that the instance function exists, only that the instance does.
§Operation
<value>
=> <fn>
CallFn
Perform a function call on a function pointer stored on the stack.
§Operation
<fn>
<args...>
=> <ret>
IndexGet
Perform an index get operation. Pushing the result on the stack.
§Operation
<target>
<index>
=> <value>
Fields
target: InstAddress
How the target is addressed.
index: InstAddress
How the index is addressed.
TupleIndexGet
Get the given index out of a tuple on the top of the stack. Errors if the item doesn’t exist or the item is not a tuple.
§Operation
<tuple>
=> <value>
TupleIndexSet
Set the given index of the tuple on the stack, with the given value.
§Operation
<value>
<tuple>
=> *nothing*
TupleIndexGetAt
Get the given index out of a tuple from the given variable slot. Errors if the item doesn’t exist or the item is not a tuple.
§Operation
=> <value>
ObjectIndexGet
Get the given index out of an object on the top of the stack. Errors if the item doesn’t exist or the item is not an object.
The index is identifier by a static string slot, which is provided as an argument.
§Operation
<object>
=> <value>
ObjectIndexSet
Set the given index out of an object on the top of the stack. Errors if the item doesn’t exist or the item is not an object.
The index is identifier by a static string slot, which is provided as an argument.
§Operation
<object>
<value>
=>
ObjectIndexGetAt
Get the given index out of an object from the given variable slot. Errors if the item doesn’t exist or the item is not an object.
The index is identifier by a static string slot, which is provided as an argument.
§Operation
=> <value>
Fields
IndexSet
Await
Await the future that is on the stack and push the value that it produces.
§Operation
<future>
=> <value>
Select
Select over len
futures on the stack. Sets the branch
register to
the index of the branch that completed. And pushes its value on the
stack.
This operation will block the VM until at least one of the underlying futures complete.
§Operation
<future...>
=> <value>
LoadFn
Push
Pop
PopN
PopAndJumpIfNot
If the stop of the stack is false, will pop the given count
entries on
the stack and jump to the given offset.
§Operation
<bool>
=> *noop*
Fields
Clean
Clean the stack by keeping the top of it, and popping count
values
under it.
§Operation
<top>
<value..>
=> <top>
Copy
Copy a variable from a location offset
relative to the current call
frame.
A copy is very cheap. It simply means pushing a reference to the stack.
Move
Move a variable from a location offset
relative to the current call
frame.
Drop
Replace
Replace a value at the offset relative from the top of the stack, with the top of the stack.
Swap
Swap two values on the stack using their offsets relative to the current stack frame.
Return
Pop the current stack frame and restore the instruction pointer from it.
The stack frame will be cleared, and the value on the top of the stack will be left on top of it.
Fields
address: InstAddress
The address of the value to return.
ReturnUnit
Pop the current stack frame and restore the instruction pointer from it.
The stack frame will be cleared, and a unit value will be pushed to the top of the stack.
Jump
Unconditionally jump to offset
relative to the current instruction
pointer.
§Operation
*nothing*
=> *nothing*
JumpIf
Jump to offset
relative to the current instruction pointer if the
condition is true
.
§Operation
<boolean>
=> *nothing*
JumpIfOrPop
Jump to offset
relative to the current instruction pointer if the
condition is true
. Will only pop the stack is a jump is not performed.
§Operation
<boolean>
=> *nothing*
JumpIfNotOrPop
Jump to offset
relative to the current instruction pointer if the
condition is false
. Will only pop the stack is a jump is not performed.
§Operation
<boolean>
=> *nothing*
JumpIfBranch
Compares the branch
register with the top of the stack, and if they
match pops the top of the stack and performs the jump to offset.
§Operation
<integer>
=> *nothing*
Vec
Construct a push a vector value onto the stack. The number of elements
in the vector are determined by count
and are popped from the stack.
§Operation
<value..>
=> <vec>
Tuple1
Fields
args: [InstAddress; 1]
First element of the tuple.
Tuple2
Fields
args: [InstAddress; 2]
Tuple arguments.
Tuple3
Fields
args: [InstAddress; 3]
Tuple arguments.
Tuple4
Fields
args: [InstAddress; 4]
Tuple arguments.
Tuple
Construct a push a tuple value onto the stack. The number of elements
in the tuple are determined by count
and are popped from the stack.
§Operation
<value..>
=> <tuple>
PushTuple
Take the tuple that is on top of the stack and push its content onto the stack.
Note: this is used by closures to “unpack” their environment into local variables.
§Operation
<tuple>
=> <value...>
Object
Construct a push an object onto the stack. The number of elements
in the object are determined the slot of the object keys slot
and are
popped from the stack.
For each element, a value is popped corresponding to the object key.
§Operation
<value..>
=> <object>
Range
Construct a range. This will pop the start and end of the range from the stack.
§Operation
[start]
[end]
=> <range>
Fields
EmptyStruct
Construct a push an object of the given type onto the stack. The type is an empty struct.
§Operation
=> <object>
Struct
Construct a push an object of the given type onto the stack. The number
of elements in the object are determined the slot of the object keys
slot
and are popped from the stack.
For each element, a value is popped corresponding to the object key.
§Operation
<value..>
=> <object>
Fields
UnitVariant
Construct a push an object variant of the given type onto the stack. The type is an empty struct.
§Operation
=> <object>
StructVariant
Construct a push an object variant of the given type onto the stack. The
number of elements in the object are determined the slot of the object
keys slot
and are popped from the stack.
For each element, a value is popped corresponding to the object key.
§Operation
<value..>
=> <object>
Fields
String
Bytes
StringConcat
Pop the given number of values from the stack, and concatenate a string from them.
This is a dedicated template-string optimization.
§Operation
<value...>
=> <string>
Fields
Format
Push a combined format specification and value onto the stack. The value used is the last value on the stack.
Fields
spec: FormatSpec
The format specification to use.
IsUnit
Try
Perform the try operation which takes the value at the given address
and tries to unwrap it or return from the current call frame.
§Operation
<value>
=> <boolean>
Fields
address: InstAddress
Address to test if value.
EqByte
EqChar
EqInteger
EqBool
EqString
EqBytes
MatchType
MatchVariant
Test if the specified variant matches. This is distinct from Inst::MatchType because it will match immediately on the variant type if appropriate which is possible for internal types, but external types will require an additional runtime check for matching.
§Operation
<value>
=> <boolean>
Fields
MatchBuiltIn
MatchSequence
Test that the top of the stack is a tuple with the given length requirements.
§Operation
<value>
=> <boolean>
Fields
MatchObject
Test that the top of the stack is an object matching the given slot of object keys.
§Operation
<object>
=> <boolean>
Fields
Yield
Perform a generator yield where the value yielded is expected to be found at the top of the stack.
This causes the virtual machine to suspend itself.
§Operation
<value>
=> <value>
YieldUnit
Perform a generator yield with a unit.
This causes the virtual machine to suspend itself.
§Operation
=> <unit>
Variant
Construct a built-in variant onto the stack.
The variant will pop as many values of the stack as necessary to construct it.
§Operation
<value..>
=> <variant>
Fields
variant: InstVariant
The kind of built-in variant to construct.
Op
A built-in operation like a + b
that takes its operands and pushes its
result to and from the stack.
§Operation
=> <value>
Fields
a: InstAddress
The address of the first argument.
b: InstAddress
The address of the second argument.
Assign
A built-in operation that assigns to the left-hand side operand. Like
a += b
.
The target determines the left hand side operation.
§Operation
<value>
=>
IterNext
Advance an iterator at the given position.
Fields
Panic
Cause the VM to panic and error out without a reason.
This should only be used during testing or extreme scenarios that are completely unrecoverable.
Fields
reason: PanicReason
The reason for the panic.
Implementations§
Trait Implementations§
source§impl<'de> Deserialize<'de> for Inst
impl<'de> Deserialize<'de> for Inst
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Copy for Inst
Auto Trait Implementations§
impl Freeze for Inst
impl RefUnwindSafe for Inst
impl Send for Inst
impl Sync for Inst
impl Unpin for Inst
impl UnwindSafe for Inst
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Copy,
impl<T> CloneToUninit for Twhere
T: Copy,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)