Skip to main content

Module vm

Module vm 

Source
Expand description

Register-based interpreter for one virtual flow.

The VM never touches threads, mailboxes, timers or the Cap table. It runs until it finishes, hits an instruction budget, or needs a scheduler effect — then returns a VmResult and stops. That split is what lets the M:N scheduler move a suspended Vm between workers freely.

TypeRole
VmPer-flow machine state (frames, pc, natives handle)
VmResultComplete / Yield / Sleep / Spawn / Send / Receive / Ask / …
FaultType errors, traps, native failures → flow failure
NativeTableHost FFI slots indexed by CallNative

Re-exports§

pub use crate::bytecode::Value;

Structs§

NativeTable
Immutable, indexable set of natives. Gaps left by NativeTableBuilder::register_at are None — calling them faults with Fault::BadNative.
NativeTableBuilder
Fluent builder for a NativeTable.
Vm
One virtual Flow’s execution state: call stack + registers. Cheap enough to construct that spawning a Flow is a handful of small heap allocations, not a native thread/stack (contrast: a std::thread reserves megabytes of stack whether it uses them or not).

Enums§

Fault
Anything that can go wrong inside a running Flow’s VM.
VmResult
What happened at the end of a crate::Vm::run slice.

Constants§

MAX_CALL_DEPTH
Hard limit on call nesting. Frames are heap-allocated (see [Frame]), so unbounded recursion would grow the Flow’s memory instead of crashing the worker thread’s native stack — which is worse, not better, without a limit. 4096 comfortably covers real recursive algorithms while keeping a runaway fn f() { f() } a Fault, not an OOM.

Functions§

expect_arg
Require args[index] to exist.
expect_bool
Require args[index] to be a bool (ints: nonzero = true).
expect_int
Require args[index] to coerce to an int (Value::as_int).
expect_message
Require args[index] to be a crate::Message.
expect_u64
Coerce args[index] to u64 from Int (≥ 0), Pid, Cap, or Bool.

Type Aliases§

NativeFn
A host-side function callable from bytecode via Opcode::CallNative.
NativeResult
Result type for a native function.