Struct passerine::vm::VM [−][src]
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: Closure
stack: Stack
ip: usize
Implementations
Initialize a new VM.
To run the VM, a lambda must be passed to it through run
.
Advances IP, returns Ok
. Used in Bytecode implementations.
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.
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.
Load a captured variable from the current closure.
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]