Struct wasm::RuntimeInstance
source · pub struct RuntimeInstance<'b, H = EmptyHookSet>where
H: HookSet,{
pub modules: Vec<ExecutionInfo<'b>>,
module_map: BTreeMap<String, usize>,
lut: Option<Lut>,
pub hook_set: H,
}
Fields§
§modules: Vec<ExecutionInfo<'b>>
§module_map: BTreeMap<String, usize>
§lut: Option<Lut>
§hook_set: H
Implementations§
source§impl<'b> RuntimeInstance<'b, EmptyHookSet>
impl<'b> RuntimeInstance<'b, EmptyHookSet>
pub fn new(validation_info: &ValidationInfo<'b>) -> CustomResult<Self>
pub fn new_named( module_name: &str, validation_info: &ValidationInfo<'b> ) -> CustomResult<Self>
source§impl<'b, H> RuntimeInstance<'b, H>where
H: HookSet,
impl<'b, H> RuntimeInstance<'b, H>where
H: HookSet,
pub fn new_with_hooks( module_name: &str, validation_info: &ValidationInfo<'b>, hook_set: H ) -> CustomResult<Self>
pub fn get_function_by_name( &self, module_name: &str, function_name: &str ) -> Result<FunctionRef, RuntimeError>
pub fn get_function_by_index( &self, module_idx: usize, function_idx: usize ) -> Result<FunctionRef, RuntimeError>
pub fn add_module( &mut self, module_name: &str, validation_info: &ValidationInfo<'b> ) -> CustomResult<()>
pub fn invoke<Param: InteropValueList, Returns: InteropValueList>( &mut self, function_ref: &FunctionRef, params: Param ) -> Result<Returns, RuntimeError>
sourcepub fn invoke_dynamic(
&mut self,
function_ref: &FunctionRef,
params: Vec<Value>,
ret_types: &[ValType]
) -> Result<Vec<Value>, RuntimeError>
pub fn invoke_dynamic( &mut self, function_ref: &FunctionRef, params: Vec<Value>, ret_types: &[ValType] ) -> Result<Vec<Value>, RuntimeError>
Invokes a function with the given parameters, and return types which are not known at compile time.
sourcefn get_indicies(
&self,
module_name: &str,
function_name: &str
) -> Result<(usize, usize), RuntimeError>
fn get_indicies( &self, module_name: &str, function_name: &str ) -> Result<(usize, usize), RuntimeError>
Get the indicies of a module and function by their names.
§Arguments
module_name
: The module in which to find the function.function_name
: The name of the function to find inside the module. The function must be a local function and not an import.
§Returns
Ok((module_idx, func_idx))
, wheremodule_idx
is the internal index of the module inside the RuntimeInstance, andfunc_idx
is the internal index of the function inside the module.Err(RuntimeError::ModuleNotFound)
, if the module is not found.Err(RuntimeError::FunctionNotFound
, if the function is not found within the module.
sourcefn verify_function_ref(
&self,
function_ref: &FunctionRef
) -> Result<(usize, usize), RuntimeError>
fn verify_function_ref( &self, function_ref: &FunctionRef ) -> Result<(usize, usize), RuntimeError>
Verify that the function reference is still valid. A function reference may be invalid if it created from another RuntimeInstance or the modules inside the instance have been changed in a way that the indicies inside the FunctionRef would be invalid.
Note: this function ensures that making an unchecked indexation will not cause a panic.
§Returns
Ok((function_ref.module_idx, function_ref.func_idx))
Err(RuntimeError::FunctionNotFound)
, orErr(RuntimeError::ModuleNotFound)
if the function is not valid.
§Implementation details
For an exported function (i.e. created by the same RuntimeInstance), the names are re-resolved using RuntimeInstance::get_indicies, and the indicies are compared with the indicies in the FunctionRef.
For a FunctionRef with the export flag set to false
, the indicies are checked to be
in-bounds, and that the module name matches the module name in the FunctionRef. The function name is ignored.