Struct passerine::vm::VM[][src]

pub struct VM {
    pub closure: Closure,
    pub stack: Stack,
    pub ip: usize,
}
Expand description

A VM executes bytecode lambda closures. (That’s a mouthful - think bytecode + some context). VM initialization overhead is tiny, and each VM’s state is self-contained, so more than one can be spawned if needed.

Fields

closure: Closurestack: Stackip: usize

Implementations

Initialize a new VM. To run the VM, a lambda must be passed to it through run.

Advances to the next instruction.

Advances IP, returns Ok. Used in Bytecode implementations.

Returns the current instruction as a byte.

Advances IP and returns the current instruction as a byte.

Returns whether the program has terminated

Builds the next number in the bytecode stream. See utils::number for more.

Dissasembles and interprets a single (potentially fallible) bytecode op. The op definitions follow in the next impl block. To see what each op does, check common::opcode::Opcode.

Suspends the current lambda and runs a new one on the VM. Runs until either success, in which it restores the state of the previous lambda, Or failure, in which it returns the runtime error. In the future, fibers will allow for error handling - right now, error in Passerine are practically panics.

Load a constant and push it onto the stack.

Moves the top value on the stack to the heap, replacing it with a reference to the heapified value.

Save the topmost value on the stack into a variable.

Save the topmost value on the stack into a captured variable.

Push a copy of a variable’s value onto the stack.

Load a captured variable from the current closure.

Delete the top item of the stack.

Copy the top data of the stack, i.e. [F, D] becomes [F, D, D].

Call a function on the top of the stack, passing the next value as an argument.

Return a value from a function. End the execution of the current lambda. Takes the number of locals on the stack Relpaces the last frame with the value on the top of the stack. Expects the stack to be a [..., Frame, Local 1, ..., Local N, Data]

Trait Implementations

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.