Skip to main content

register_host_fn

Function register_host_fn 

Source
pub fn register_host_fn(
    linker: &mut Linker<StoreData>,
    module: &str,
    mangled_name: MangledName,
    ty: FuncType,
    _deterministic: bool,
    body: impl Fn(&mut Caller<'_, StoreData>, &[Val], &mut [Val]) -> Result<()> + Send + Sync + 'static,
) -> Result<()>
Expand description

Register a host fn under mangled_name — the linker field codegen imports for it: mangle::host(module, name) for stdlib/host modules, or a prelude method’s dispatch key (e.g. submilli:prelude#String#repeat) so codegen’s method lookup resolves to it.

_deterministic is reserved for Phase-2 durable-log wrapping; unused today.

Ordinary host errors become catchable guest errors via throw_error. FatalHostError, an engine trap and a reached memory cap bypass conversion and terminate execution. A body that already raised a throw (its Err is a ThrownException) is passed through untouched, so the pending exception isn’t clobbered. Bodies receive &mut Caller (not an owned Caller) so the wrapper can still use the caller to raise the throw after the body returns.

The import is synchronous: the engine services it inline in its dispatch loop rather than suspending the interpreter and resuming through the async driver. A body that awaits, or that re-enters guest code, belongs on register_host_fn_async instead.