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 - Host
Condition - A structured failure a native returns as its host
Err. The classifier lifts it from the wasmtime error chain with code and detail intact. - 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. - Script
Raise - An uncaught in-guest condition.
detailis the decoded detail value,Nonewhen absent. - Struct
View - The name and fields of a
DEFSTRUCTinstance; boxed inEvalValueso the error types carrying a value stay small. - Type
Handles - Module type handles for classifying a heterogeneous
anyrefresult or$paircar by structural kind (ADR-0033 Phase 6), once the null /$t/ i31 kinds Phase 3 already covers are ruled out. WasmGC struct/array types are structural, so the host can’t name “the ratio type”; instead it reads theHeapTypeoff an export whose signature already carries it — no value is ever taken through any of these exports host-side, only their declared shape.ratio_new/commodity_new/pair_new/string_eq/symbol_newand onealloc_<kind>pernomiscript::EntityKindwith a field layout are exported by every module regardless of program content.
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. - UnitEnd
- How a unit ended, which decides what its globals hold.
Constants§
- MAX_
WIRE_ LIST_ DEPTH - Deepest list and struct nesting a script’s result may have: the guest
writes a placeholder past it, so a struct holding itself ends, and the host
decoder refuses it. A client reader counts every expression, so the
(:id N :value V)envelope and the atom inside the innermost list take two of its levels (nomiscript::MAX_READ_DEPTH).
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. - alloc_
value - The guest value of
value: strings, numbers,t,nil, symbols and lists of them. - 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. - carry_
globals - Takes the unit’s manifest and settles each slot it wrote: one none of whose flags is 1 never got the unit’s value and is put back as it was before the unit, a function or layout keeps the last definition that ran, and a cell that got a value carries the one its instance holds, or, when the unit trapped inside a binding of it, the one outside the binding; one only a DEFVAR of it reached stays declared special and unbound. Never fails the unit that ran: a cell that cannot be read becomes an opaque global, loud when a later unit reads it, and the cause is logged. The session heap is settled only once the unit’s instance prologue ran to its end.
- carry_
not_ run - Puts back every slot a unit wrote when it compiled but never ran: its instantiation failed, or an interrupt stopped it before its call.
- classify_
runtime_ error - Classifies a [
wasmtime::Error] thrown during execution into a typedEngineError. Order: [wasmtime::Trap] (fuel/epoch), aHostConditionorScriptRaisein the chain, then the fiber cap; the rest 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).handlesresolves the module’s$tsingleton and struct/array type handles (seesuper::type_handles::resolve_type_handles), needed to classify a heterogeneousAnyRefresult by identity/kind (ADR-0033). - 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. - logged_
values - The one log message for
args, a$pairlist of the printed values: each printedprinc-style, joined by a space.Nonewhen a value in it cannot be read (compound money, a value of no known kind): the caller reports that to the guest, never as text. - nomi_
raise - The
__nomi_raisehost fn body shared by every linker: reads the condition’s fields and always returnsErr, carrying aScriptRaiseunless the code or message cannot be read. - 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 non-positive denominator is a structured trap. 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. - resolve_
caller_ type_ handles resolve_type_handlesfor a host function, which sees its calling instance’s exports only through theCaller.- resolve_
type_ handles - Resolves
TypeHandlesfrominstance’s exports. Call once per eval call, alongside (in place of)t_singleton. - t_
singleton - Resolves the compiler-emitted
tsingleton export (ADR-0033: the$tmodule global, an empty-struct instance identified by reference equality) so the host can recognise it when decoding anAnyRefresult or list cell. Every module the compiler emits exports it, so a missing export is a structured error, not a silent fallback. - throw_
condition - Throws a
$nomi_errorcarryingcode(upper-cased, ashandler-casecompares it),messageand the structureddetail, so the calling script’shandler-casecan catch it and read the detail witherror-detail. Return the result from the host fn:return Err(throw_condition(&mut caller, code, message, &detail).await). Any failure while building the condition is returned in its place.