Expand description
Shared wasmtime primitives used by every host of nomiscript-compiled
modules: the entity-script ScriptExecutor and the rpc eval channel.
Owns the engine config (WasmGC + epoch interruption + optional fuel),
the per-bytecode Module cache, the trap-classification helper, and the
decode_eval_result helper that walks the nomi-eval (ref null any)
return value into a structured EvalValue. Higher-level consumers
parameterize over the Store data type and assemble their own Linker on top.
Structs§
- Engine
Opts - Module
Cache - Per-engine bytecode cache keyed by the full module bytes. Cloning a
ModuleCacheyields a handle into the same inner map; meant to be shared between long-lived hosts (Session, ScriptExecutor) and any per-form helpers that need the same cached compilation.
Enums§
- Engine
Error - Eval
Value - Final value captured by an eval-mode module via the
nomi_capture_*host fns. Mirrors the subset ofnomiscript::WasmTypevariants the compiler emits as terminal stack types, plus aBytesvariant for native fns that marshal compound data (server-command results viascripting-format, chart SVGs, exported files, etc.). Cons/Vector/Closure/Struct still wait for the GC migration. - Profiler
Strategy - Optional profiling strategy. JitDump is the Linux
perf recordflow; it writes ajit-<pid>.dumpfile the OS-level profiler can read. PerfMap is the simpler symbol-name-only Linux variant. Both require thewasmtime/profilingcargo feature, which we pull in via thejitdumpfeature flag on the scripting crate; non-Linux builds should leave this asNone.
Constants§
- NOMI_
RAISE_ MARKER - Marker prefix the
__nomi_raisehost fn embeds in its wasmtime error message so the runtime classifier can recognise script-raised errors before the unreachable-trap branch fires. Kept here so the host-fn body and the classifier agree on the wire format.
Functions§
- alloc_
commodity_ ref - Allocates an ATOMIC
$commodityvalue by re-entering the guest’s exportedcommodity_newwith the four i64 components (numer, denom, commodity_hi, commodity_lo). Since ADR-0028 E0 the$commoditystruct carries a 5th(ref null $unit_term)field; the host must NOT construct that ref-bearing struct itself, so it delegates to the guest helper (which sets the term to null = atomic) — the same re-entry pattern asalloc_pair_chain/ the entity allocators. Async because it calls back into the wasm instance. - alloc_
entity_ via_ export - Allocates an entity wasm struct (
$account,$commodity_entity, etc) by re-entering the module’s exportedalloc_<kind>function. The host can’t freshly construct an entityStructTypeviaStructType::new— fields like(ref null $i8_array)reference concrete type indices that engine canonicalization compares by identity, so any abstractanyref-typed fresh declaration produces a structurally distinct (and uncastable) type. Re-entry through the guest’s own allocator (registered inCompileContext::register_entity_allocators) sidesteps the issue: each call returns a struct ref of the exact$<kind>type the subsequentref.cast (ref $<kind>)in the consuming form accepts. - alloc_
pair_ chain - Folds an iterator of GC-ref elements into a
$pairchain by re-entering the wasm module via its exportedpair_newfunction. Returns the chain head, orNoneif the iterator is empty. - alloc_
ratio_ ref - Allocates a
$ratiowasm struct (2 i64 fields: numer, denom). Mirrorsalloc_commodity_reffor the Ratio numeric stratum — used when a host fn returns a typed Ratio without going through the synthesizedratio_newwrap. - alloc_
string_ ref - Allocates a
$i8_arraywasm array holdingbytesand returns a rooted reference. Single allocation; callers can format UUID/name payloads into a reusedVec<u8>and ship the bytes without an intermediateString. Engine canonicalizes the i8 array type so the host-side allocation matches the guest’s(array i8)declaration inCompileContext::new_skeleton. - build_
engine - call_
i64_ export - Instantiates
moduleagainst an empty linker and calls a zero-arg export returning a singlei64. Constraints (fuel cap, epoch deadline) come from the caller-suppliedStore. - classify_
runtime_ error - Classifies a [
wasmtime::Error] thrown during execution into a typedEngineError. Downcast to [wasmtime::Trap] handles the structured fuel/epoch cases; everything else falls through asTrap(message). - compile_
module - compile_
wat - decode_
eval_ result - Decodes nomi-eval’s anyref return value into an
EvalValueusing the compile-time-known result type.Nonefor the result_ty means the form was empty / definition-only and the host should seeEvalValue::Nil. Numeric types (I32,Ratio,Commodity) andStringRefdecode directly.PairRefwalks the chain, decoding each car per its declared element type.EntityRefreturns a placeholder until a downstream consumer needs the structured shape host-side. Takes anyAsContextMutso it works with both&mut Store<T>(sync test paths) and&mut Caller<'_, T>(async host fn paths). - err_
code_ and_ message - Maps an
EngineErrorto the(code, message)pair scripts and batch consumers see when a script fails — code is a kebab-case symbol (matching the wire envelope’s:codeslot for catch-each cells andserver::scriptper-tx reports), message is the engine’s own diagnostic string. - read_
commodity_ arg - Reads a
$commodityarg ref into its (numer, denom, commodity_id) components. Mirrorsread_string_argfor the Commodity numeric stratum: fields 0-1 are numer/denom, fields 2-3 are the UUID halves.Nonereturns for a null ref; bad shape surfaces as a structured trap. - read_
entity_ string_ field - Reads a named String field from an entity struct arg, resolving the field’s
slot index from [
nomiscript::entity_layout] (the single source of struct slot order).Nonereturns for a null ref. Errors if the kind has no layout, the named field is absent or non-String, or the slot is not an$i8_array. This is how the draft natives read e.g. an account’sid(slot 0) from a(get-account …)entity ref passed as an argument. - read_
entity_ string_ field_ ctx - Context-based core of
read_entity_string_field, split out so it is unit-testable without aCaller(tests hold a bareStore). Resolves the field’s slot from the entity layout and reads it as an$i8_arraystring. - read_
ratio_ arg - Reads a
$ratioarg ref into its(numer, denom)components.Nonereturns for a null ref; a zero denominator is rejected as a structured trap so callers never divide by zero. Mirrorsread_commodity_argfor the dimensionless Scalar stratum (adraft-splitamount). - read_
string_ arg - Reads a
$i8_arrayarg ref into a RustString.Noneis returned for null refs (the wasm-level(ref null $i8_array)param’s null state). The underlying byte storage is i8 (mutable perregister_type("i8_array")), so each element is read viaarray.get_usemantics and assembled into aVec<u8>then UTF-8 validated. Non-UTF-8 bytes surface as a structured trap rather than a silent replacement.