[][src]Enum runestick::Inst

pub enum Inst {
    Not,
    Neg,
    Closure {
        hash: Hash,
        count: usize,
    },
    Call {
        hash: Hash,
        args: usize,
    },
    CallInstance {
        hash: Hash,
        args: usize,
    },
    LoadInstanceFn {
        hash: Hash,
    },
    CallFn {
        args: usize,
    },
    IndexGet,
    TupleIndexGet {
        index: usize,
    },
    TupleIndexSet {
        index: usize,
    },
    TupleIndexGetAt {
        offset: usize,
        index: usize,
    },
    ObjectIndexGet {
        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,
        offset: isize,
    },
    Clean {
        count: usize,
    },
    Copy {
        offset: usize,
    },
    Move {
        offset: usize,
    },
    Drop {
        offset: usize,
    },
    Dup,
    Replace {
        offset: usize,
    },
    Return,
    ReturnUnit,
    Jump {
        offset: isize,
    },
    JumpIf {
        offset: isize,
    },
    JumpIfNot {
        offset: isize,
    },
    JumpIfOrPop {
        offset: isize,
    },
    JumpIfNotOrPop {
        offset: isize,
    },
    JumpIfBranch {
        branch: i64,
        offset: isize,
    },
    Vec {
        count: usize,
    },
    Tuple {
        count: usize,
    },
    PushTuple,
    Object {
        slot: usize,
    },
    UnitStruct {
        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,
    IsValue,
    Unwrap,
    EqByte {
        byte: u8,
    },
    EqCharacter {
        character: char,
    },
    EqInteger {
        integer: i64,
    },
    EqStaticString {
        slot: usize,
    },
    MatchSequence {
        type_check: TypeCheck,
        len: usize,
        exact: bool,
    },
    MatchObject {
        type_check: TypeCheck,
        slot: usize,
        exact: bool,
    },
    Yield,
    YieldUnit,
    Op {
        op: InstOp,
    },
    Assign {
        target: InstTarget,
        op: InstAssignOp,
    },
    Panic {
        reason: PanicReason,
    },
}

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

Negate the numerical value on the stack.

Operation

<number>
=> <number>
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 of Closure

hash: Hash

The hash of the internally stored closure function.

count: usize

The number of arguments to store in the environment on the stack.

Call

Perform a function call.

It will construct a new stack frame which includes the last args number of entries.

Fields of Call

hash: Hash

The hash of the function to call.

args: usize

The number of arguments expected on the stack for this call.

CallInstance

Perform a instance function call.

The instance being called on should be on top of the stack, followed by args number of arguments.

Fields of CallInstance

hash: Hash

The hash of the name of the function to call.

args: usize

The number of arguments expected on the stack for this call.

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>

Fields of LoadInstanceFn

hash: Hash

The name hash of the instance function.

CallFn

Perform a function call on a function pointer stored on the stack.

Operation

<fn>
<args...>
=> <ret>

Fields of CallFn

args: usize

The number of arguments expected on the stack for this call.

IndexGet

Perform an index get operation. Pushing the result on the stack.

Operation

<target>
<index>
=> <value>
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>

Fields of TupleIndexGet

index: usize

The index to fetch.

TupleIndexSet

Set the given index of the tuple on the stack, with the given value.

Operation

<value>
<tuple>
=> *nothing*

Fields of TupleIndexSet

index: usize

The index to set.

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>

Fields of TupleIndexGetAt

offset: usize

The slot offset to load the tuple from.

index: usize

The index to fetch.

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>

Fields of ObjectIndexGet

slot: usize

The static string slot corresponding to the index to fetch.

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 of ObjectIndexGetAt

offset: usize

The slot offset to get the value to load from.

slot: usize

The static string slot corresponding to the index to fetch.

IndexSet

Perform an index set operation.

Operation

<target>
<index>
<value>
=> *noop*
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>

Fields of Select

len: usize

The number of futures to poll.

LoadFn

Load the given function by hash and push onto the stack.

Operation

=> <value>

Fields of LoadFn

hash: Hash

The hash of the function to push.

Push

Push a value onto the stack.

Operation

=> <value>

Fields of Push

value: InstValue

The value to push.

Pop

Pop the value on the stack, discarding its result.

Operation

<value>
=>
PopN

Pop the given number of elements from the stack.

Operation

<value..>
=> *noop*

Fields of PopN

count: usize

The number of elements to pop from the stack.

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 of PopAndJumpIfNot

count: usize

The number of entries to pop of the condition is true.

offset: isize

The offset to jump if the condition is true.

Clean

Clean the stack by keeping the top of it, and popping count values under it.

Operation

<top>
<value..>
=> <top>

Fields of Clean

count: usize

The number of entries in the stack to pop.

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.

Fields of Copy

offset: usize

Offset to copy value from.

Move

Move a variable from a location offset relative to the current call frame.

Fields of Move

offset: usize

Offset to move value from.

Drop

Drop the value in the given frame offset, cleaning out it's slot in memory.

Operation

=> *noop*

Fields of Drop

offset: usize

Frame offset to drop.

Dup

Duplicate the value at the top of the stack.

Operation

=> <value>
Replace

Replace a value at the offset relative from the top of the stack, with the top of the stack.

Fields of Replace

offset: usize

Offset to swap value from.

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.

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*

Fields of Jump

offset: isize

Offset to jump to.

JumpIf

Jump to offset relative to the current instruction pointer if the condition is true.

Operation

<boolean>
=> *nothing*

Fields of JumpIf

offset: isize

Offset to jump to.

JumpIfNot

Jump to offset relative to the current instruction pointer if the condition is false.

Operation

<boolean>
=> *nothing*

Fields of JumpIfNot

offset: isize

Offset to jump to.

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*

Fields of JumpIfOrPop

offset: isize

Offset to jump to.

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*

Fields of JumpIfNotOrPop

offset: isize

Offset to jump to.

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*

Fields of JumpIfBranch

branch: i64

The branch value to compare against.

offset: isize

The offset to jump.

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>

Fields of Vec

count: usize

The size of the vector.

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>

Fields of Tuple

count: usize

The size of the 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>

Fields of Object

slot: usize

The static slot of the object keys.

UnitStruct

Construct a push an object of the given type onto the stack. The type is an empty struct.

Operation

=> <object>

Fields of UnitStruct

hash: Hash

The type of the object to construct.

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 of Struct

hash: Hash

The type of the object to construct.

slot: usize

The static slot of the object keys.

UnitVariant

Construct a push an object variant of the given type onto the stack. The type is an empty struct.

Operation

=> <object>

Fields of UnitVariant

hash: Hash

The type hash of the object variant to construct.

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 of StructVariant

hash: Hash

The type hash of the object variant to construct.

slot: usize

The static slot of the object keys.

String

Load a literal string from a static string slot.

Operation

=> <string>

Fields of String

slot: usize

The static string slot to load the string from.

Bytes

Load a literal byte string from a static byte string slot.

Operation

=> <bytes>

Fields of Bytes

slot: usize

The static byte string slot to load the string from.

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 of StringConcat

len: usize

The number of items to pop from the stack.

size_hint: usize

The minimum string size used.

Format

Push a combined format specification and value onto the stack. The value used is the last value on the stack.

Fields of Format

spec: FormatSpec

The format specification to use.

IsUnit

Test if the top of the stack is a unit.

Operation

<value>
=> <boolean>
IsValue

Test if the top of the stack is a value.

This expects the top of the stack to be an option or a result, and it is a value if these are either Some or Ok.

Operation

<value>
=> <boolean>
Unwrap

Unwrap a result from the top of the stack. This causes a vm error if the top of the stack is not an ok result.

Operation

<result>
=> <value>
EqByte

Test if the top of the stack is a specific byte.

Operation

<value>
=> <boolean>

Fields of EqByte

byte: u8

The byte to test against.

EqCharacter

Test if the top of the stack is a specific character.

Operation

<value>
=> <boolean>

Fields of EqCharacter

character: char

The character to test against.

EqInteger

Test if the top of the stack is a specific integer.

Operation

<value>
=> <boolean>

Fields of EqInteger

integer: i64

The integer to test against.

EqStaticString

Compare the top of the stack against a static string slot.

Operation

<value>
=> <boolean>

Fields of EqStaticString

slot: usize

The slot to test against.

MatchSequence

Test that the top of the stack is a tuple with the given length requirements.

Operation

<value>
=> <boolean>

Fields of MatchSequence

type_check: TypeCheck

Type constraints that the sequence must match.

len: usize

The minimum length to test for.

exact: bool

Whether the operation should check exact true or minimum length false.

MatchObject

Test that the top of the stack is an object matching the given slot of object keys.

Operation

<object>
=> <boolean>

Fields of MatchObject

type_check: TypeCheck

Type constraints that the object must match.

slot: usize

The slot of object keys to use.

exact: bool

Whether the operation should check exact true or minimum length false.

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>
Op

A built-in operation like a + b that takes its operands and pushes its result to and from the stack.

Operation

<value>
<value>
=> <value>

Fields of Op

op: InstOp

The actual operation.

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>
=>

Fields of Assign

target: InstTarget

The target of the operation.

op: InstAssignOp

The actual operation.

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 of Panic

reason: PanicReason

The reason for the panic.

Implementations

impl Inst[src]

pub fn unit() -> Self[src]

Construct an instruction to push a unit.

pub fn bool(b: bool) -> Self[src]

Construct an instruction to push a boolean.

pub fn byte(b: u8) -> Self[src]

Construct an instruction to push a byte.

pub fn char(c: char) -> Self[src]

Construct an instruction to push a character.

pub fn integer(v: i64) -> Self[src]

Construct an instruction to push an integer.

pub fn float(v: f64) -> Self[src]

Construct an instruction to push a float.

Trait Implementations

impl Clone for Inst[src]

impl Copy for Inst[src]

impl Debug for Inst[src]

impl<'de> Deserialize<'de> for Inst[src]

impl Display for Inst[src]

impl Serialize for Inst[src]

Auto Trait Implementations

impl RefUnwindSafe for Inst

impl Send for Inst

impl Sync for Inst

impl Unpin for Inst

impl UnwindSafe for Inst

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.