Skip to main content

Vm

Struct Vm 

Source
pub struct Vm { /* private fields */ }
Expand description

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).

Vm owns no scheduler, mailbox, or thread handle — see VmResult for why that separation is the whole point.

Implementations§

Source§

impl Vm

Source

pub fn new( chunk: Arc<Chunk>, natives: Arc<NativeTable>, function: u32, args: &[Value], ) -> Result<Self, Fault>

Construct a Vm ready to run function (an index into chunk.functions) with the given arguments loaded into r0..argc. natives is the FFI table Opcode::CallNative dispatches through — pass NativeTable::empty if the chunk never calls out to Rust.

Source

pub fn instructions_executed(&self) -> u64

Source

pub fn current_function(&self) -> u32

Index into chunk.functions for the active (top) call frame. Useful for diagnostics / supervisor logs when a Flow traps.

Source

pub fn chunk_arc(&self) -> Arc<Chunk>

A cheap Arc clone of the chunk this VM is executing. Used by the scheduler to construct a child Vm for Opcode::Spawn without needing to know anything about Chunk’s internals — every Flow spawned (transitively) from the same top-level spawn() call shares one immutable chunk in memory, never copies it.

Source

pub fn natives_arc(&self) -> Arc<NativeTable>

A cheap Arc clone of this VM’s native function table, for the same reason as Vm::chunk_arc: a Spawn-created child must dispatch CallNative through the identical table its parent uses.

Source

pub fn resume_with(&mut self, dest_reg: u8, value: Value) -> Result<(), Fault>

Deliver a value the scheduler produced on our behalf (a Cap from Spawn / SelfPid, or a dequeued mailbox message from a Receive) into the register the instruction that suspended us was targeting, ahead of the next Vm::run call. A no-op is never valid to skip: calling run without this after a Spawn/Receive result leaves the destination register holding its previous (stale) value.

Source

pub fn run(&mut self, budget: u32) -> VmResult

Run at most budget instructions (cooperative-preemption quantum, design notes §10-11), or until the Flow completes / needs an effect the scheduler must perform / faults.

Every exit path is captured by VmResult — this function itself never panics on malformed verified bytecode; faults are returned, not thrown, so a buggy Flow can’t take a worker thread down.

Auto Trait Implementations§

§

impl !RefUnwindSafe for Vm

§

impl !UnwindSafe for Vm

§

impl Freeze for Vm

§

impl Send for Vm

§

impl Sync for Vm

§

impl Unpin for Vm

§

impl UnsafeUnpin for Vm

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.