Skip to main content

Store

Struct Store 

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

Mutable state of an instantiated module.

Defined memories and globals only; the imported index-space prefix is tracked so accesses to imported memories/globals can fail explicitly.

Implementations§

Source§

impl Store

Source

pub fn instantiate(module: &RegModule) -> Result<Self, RuntimeError>

Instantiate a lowered module with an empty import set. Modules with state imports (memories, globals, tables) need Store::instantiate_with_imports.

Source

pub fn instantiate_linked( module: &Rc<RegModule>, imports: &Imports, group: &Rc<RefCell<LinkGroup>>, instance_id: u32, ) -> Result<Rc<RefCell<Store>>, RuntimeError>

Instantiate and register the instance in a link group with the given instance id. Use for modules that link against each other so funcref values carry cross-instance identity.

Source

pub fn instantiate_with_imports( module: &RegModule, imports: &Imports, ) -> Result<Self, RuntimeError>

Instantiate a lowered module: resolve state imports eagerly from imports, zero memories to their minimum size, evaluate global initializers in declaration order, apply active data segments, and run the start function if present.

Source

pub fn run_start(&mut self, module: &RegModule) -> Result<(), RuntimeError>

Run the deferred start function, if any. Call after registering host functions; safe to call multiple times (runs at most once).

Source

pub fn shared_memory(&self, idx: u32) -> Option<Rc<RefCell<Vec<u8>>>>

The shared handle of a memory by index-space index (imported first).

Exposed so host-module crates (e.g. the GPU host module) can capture a guest-memory handle at registration time and read/write it from inside host-function closures. The handle stays valid across memory.grow, which mutates the Vec in place rather than replacing it.

Source

pub fn export_func(&self, name: &str) -> Option<FuncIdx>

An exported function by name.

Source

pub fn export_memory( &self, name: &str, ) -> Option<(MemType, Rc<RefCell<Vec<u8>>>)>

An exported memory by name: its declared type and shared handle.

Source

pub fn export_global(&self, name: &str) -> Option<(GlobalType, Rc<Cell<Value>>)>

An exported global by name: its declared type and shared cell.

Source

pub fn export_table( &self, name: &str, ) -> Option<(TableType, Rc<RefCell<Table>>)>

An exported table by name: its declared type and shared handle.

Source

pub fn get_global(&self, idx: u32) -> Option<Value>

Read a global’s current value by index-space index (embedding access).

Source

pub fn with_memory<R>(&self, idx: u32, f: impl FnOnce(&[u8]) -> R) -> Option<R>

Read a memory’s bytes by index-space index via closure (embedding access; memories are shared handles, so direct slices are not available).

Source

pub fn with_memory_mut<R>( &self, idx: u32, f: impl FnOnce(&mut [u8]) -> R, ) -> Option<R>

Mutate a memory’s bytes by index-space index via closure (embedding access).

Source

pub fn set_gpu(&mut self, backend: Box<dyn GpuBackend>)

Install a GPU backend for bulk SIMD offload.

Source

pub fn clear_gpu(&mut self)

Remove the installed GPU backend, if any.

Source

pub fn has_gpu(&self) -> bool

Whether a GPU backend is installed.

Source

pub fn with_gpu_mut<R>( &self, f: impl FnOnce(&mut dyn GpuBackend) -> R, ) -> Option<R>

Mutable access to the installed GPU backend via closure.

Source

pub fn register_host_func( &mut self, module: &str, name: &str, func: HostFunction, ) -> Result<(), RuntimeError>

Register a host function for a function import (module, name).

Fails with RuntimeErrorKind::UnknownImport when the module does not declare that import, or RuntimeErrorKind::ImportTypeMismatch when the signatures differ.

Source

pub fn set_fuel(&self, fuel: Option<u64>)

Set the instruction fuel budget (None = unlimited, the default).

Fuel is charged per executed instruction (and per block dispatch) across all calls made from this store. Cross-instance calls charge the callee’s store, not the caller’s — each instance has its own budget.

Source

pub fn fuel(&self) -> Option<u64>

Remaining fuel, or None when unlimited.

Source

pub fn set_offload_threshold(&mut self, threshold: usize)

Set the element count at or above which bulk SIMD work dispatches to GPU (per-platform tuning).

Source

pub fn f32_add_region( &mut self, a_ptr: u32, b_ptr: u32, out_ptr: u32, count: usize, ) -> Result<(), RuntimeError>

Bulk element-wise f32 addition over linear-memory regions: out[i] = a[i] + b[i] for count f32 elements (Borsalino Level 1).

At or above the offload threshold with a GPU backend installed, the work dispatches to GPU; otherwise it executes on CPU. Memory 0.

Trait Implementations§

Source§

impl Debug for Store

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !Freeze for Store

§

impl !RefUnwindSafe for Store

§

impl !Send for Store

§

impl !Sync for Store

§

impl !UnwindSafe for Store

§

impl Unpin for Store

§

impl UnsafeUnpin for Store

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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.