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
impl Store
Sourcepub fn instantiate(module: &RegModule) -> Result<Self, RuntimeError>
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.
Sourcepub fn instantiate_linked(
module: &Rc<RegModule>,
imports: &Imports,
group: &Rc<RefCell<LinkGroup>>,
instance_id: u32,
) -> Result<Rc<RefCell<Store>>, RuntimeError>
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.
Sourcepub fn instantiate_with_imports(
module: &RegModule,
imports: &Imports,
) -> Result<Self, RuntimeError>
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.
Sourcepub fn run_start(&mut self, module: &RegModule) -> Result<(), RuntimeError>
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).
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.
Sourcepub fn export_func(&self, name: &str) -> Option<FuncIdx>
pub fn export_func(&self, name: &str) -> Option<FuncIdx>
An exported function by name.
Sourcepub fn export_memory(
&self,
name: &str,
) -> Option<(MemType, Rc<RefCell<Vec<u8>>>)>
pub fn export_memory( &self, name: &str, ) -> Option<(MemType, Rc<RefCell<Vec<u8>>>)>
An exported memory by name: its declared type and shared handle.
Sourcepub fn export_global(&self, name: &str) -> Option<(GlobalType, Rc<Cell<Value>>)>
pub fn export_global(&self, name: &str) -> Option<(GlobalType, Rc<Cell<Value>>)>
An exported global by name: its declared type and shared cell.
Sourcepub fn export_table(
&self,
name: &str,
) -> Option<(TableType, Rc<RefCell<Table>>)>
pub fn export_table( &self, name: &str, ) -> Option<(TableType, Rc<RefCell<Table>>)>
An exported table by name: its declared type and shared handle.
Sourcepub fn get_global(&self, idx: u32) -> Option<Value>
pub fn get_global(&self, idx: u32) -> Option<Value>
Read a global’s current value by index-space index (embedding access).
Sourcepub fn with_memory<R>(&self, idx: u32, f: impl FnOnce(&[u8]) -> R) -> Option<R>
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).
Sourcepub fn with_memory_mut<R>(
&self,
idx: u32,
f: impl FnOnce(&mut [u8]) -> R,
) -> Option<R>
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).
Sourcepub fn set_gpu(&mut self, backend: Box<dyn GpuBackend>)
pub fn set_gpu(&mut self, backend: Box<dyn GpuBackend>)
Install a GPU backend for bulk SIMD offload.
Sourcepub fn with_gpu_mut<R>(
&self,
f: impl FnOnce(&mut dyn GpuBackend) -> R,
) -> Option<R>
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.
Sourcepub fn register_host_func(
&mut self,
module: &str,
name: &str,
func: HostFunction,
) -> Result<(), RuntimeError>
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.
Sourcepub fn set_fuel(&self, fuel: Option<u64>)
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.
Sourcepub fn set_offload_threshold(&mut self, threshold: usize)
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).
Sourcepub fn f32_add_region(
&mut self,
a_ptr: u32,
b_ptr: u32,
out_ptr: u32,
count: usize,
) -> Result<(), RuntimeError>
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.