pub struct Store<'m> { /* private fields */ }
Expand description
Runtime store.
Implementations§
Source§impl<'m> Store<'m>
impl<'m> Store<'m>
Sourcepub fn instantiate(
&mut self,
module: Module<'m>,
memory: &'m mut [u8],
) -> Result<InstId, Error>
pub fn instantiate( &mut self, module: Module<'m>, memory: &'m mut [u8], ) -> Result<InstId, Error>
Instantiates a valid module in this store.
The memory is not dynamically allocated and must thus be provided. It is not necessary for the memory length to be a multiple of 64kB. Execution will trap if the module tries to access part of the memory that does not exist.
Sourcepub fn invoke<'a>(
&'a mut self,
inst: InstId,
name: &str,
args: Vec<Val>,
) -> Result<RunResult<'a, 'm>, Error>
pub fn invoke<'a>( &'a mut self, inst: InstId, name: &str, args: Vec<Val>, ) -> Result<RunResult<'a, 'm>, Error>
Invokes a function in an instance provided its name.
If a function was already running, it will resume once the function being called terminates. In other words, execution satisfies a stack property. Without this, the stack of the module may be corrupted.
Sourcepub fn get_global(&mut self, inst: InstId, name: &str) -> Result<Val, Error>
pub fn get_global(&mut self, inst: InstId, name: &str) -> Result<Val, Error>
Returns the value of a global of an instance.
Sourcepub fn set_name(&mut self, inst: InstId, name: &'m str) -> Result<(), Error>
pub fn set_name(&mut self, inst: InstId, name: &'m str) -> Result<(), Error>
Sets the name of an instance.
Sourcepub fn link_func(
&mut self,
module: &'m str,
name: &'m str,
params: usize,
results: usize,
) -> Result<(), Error>
pub fn link_func( &mut self, module: &'m str, name: &'m str, params: usize, results: usize, ) -> Result<(), Error>
Links a host function provided its signature.
This is a convenient wrapper around Self::link_func_custom()
for functions which
parameter and return types are only i32
. The params
and results
parameters describe
how many i32
are taken as parameters and returned as results respectively.
Sourcepub fn link_func_default(&mut self, module: &'m str) -> Result<(), Error>
pub fn link_func_default(&mut self, module: &'m str) -> Result<(), Error>
Enables linking unresolved imported function for the given module.
For each unresolved imported function type that returns exactly one i32
, a fake host
function is created (as if link_func
was used). As such, out-of-bound indices with respect
to real calls to Self::link_func()
represent such fake host functions. Callers must thus
expect and support out-of-bound indices returned by Call::index()
.
This function can be called at most once, and once called link_func
cannot be called.
Sourcepub fn link_func_custom(
&mut self,
module: &'m str,
name: &'m str,
type_: FuncType<'m>,
) -> Result<(), Error>
pub fn link_func_custom( &mut self, module: &'m str, name: &'m str, type_: FuncType<'m>, ) -> Result<(), Error>
Links a host function provided its signature.
Note that the order in which functions are linked defines their index. The first linked function has index 0, the second has index 1, etc. This index is used when a module calls in the host to identify the function.