The guest ABI
A mod is a WebAssembly module. It imports the calls it uses from the host, exports on_frame, which
the host calls once a frame, and optionally on_event, and nothing else crosses. This page is that
boundary: the header a mod compiles against, how each value crosses, and what the host checks
before a mod runs a line.
A whole mod
This is observer.c from the Axiom repository, the first mod written against the generated surface,
shortened by the exports its tests read. It reads how many entities there are and which frame it is,
and writes nothing.
"surface.h" uint32_t s_Seen = 0; uint64_t s_Frame = 0; __attribute__((export_name("on_frame"))) OnFrame() { s_Seen = axiom_entity_query_count(); s_Frame = axiom_frame_index(); }
It includes surface.h and nothing else: no C library, no C++ library, no sysroot. Linked, it is a
module whose only imports are axiom:entity.query@1 count and axiom:frame@1 index.
Exports and imports
A mod exports at most two functions the host calls. Any other export is ignored by the host, which is how the Axiom repository's test mods hand values to their tests.
/* Called once a frame. A mod without it runs nothing. */ __attribute__((export_name("on_frame"))) OnFrame() { } /* Called after on_frame, once each event waiting. Optional. */ __attribute__((export_name("on_event"))) OnEvent(uint32_t id, uint32_t size) { }
Everything else a mod does is an import. Each call in the surface is imported from a module named for
its capability, axiom:frame@1, under the call's name, index. surface.h writes those attributes
for you, so a mod calls axiom_frame_index() like any C function. One import is part of the ABI
rather than a capability: axiom_event_read, from axiom:event, which every mod may use without
declaring it (Events).
A module gets one linear memory of its own, at most 64 MiB, and no table, global or memory from the host. It has no allocator unless it brings one: most mods keep their state in static arrays, and format numbers by hand, as the overlay page shows.
surface.h
The header is generated from the surface definition, idl/axiom.idl, and is the guest ABI and
nothing more: fixed-width structs and the import declarations. It needs only <stdint.h> and
<stddef.h>, which the compiler itself provides.
It is generated from the same surface these pages are. Every call is named the same way:
The capability reference shows the C declaration under every call a mod can make. A capability for packs only has no declaration: it is absent from the header, which is how a mod is kept from importing it.
How a value crosses
A wasm import carries four types: i32, i64, f32 and f64. Everything richer is lowered by one
table, which the guest header and the host's import list are both generated from, so the two cannot
disagree.
A pointer here is an offset into the mod's own linear memory, never an address in the game. The host checks every span against the size of that memory, in 64 bits so a length cannot wrap the sum round to something small, before it reads a byte.
AxiomEntityQueryEntityId ids[32]; uint32_t alive = axiom_entity_query_alive(ids, 32); AxiomVec3 position; (alive > 0 && axiom_entity_transform_position(ids[0].index, ids[0].generation, &position) != 0) { /* A stale id, or a pack that does not answer positions. */ }
The handle crosses as its two fields. The position comes back through the out pointer, and the status says whether it did.
Handles
An entity, a panel, a list node and a hook are each named by a handle: an index and a generation. The host owns the table behind them and checks both on every call, so a handle to something that has gone is refused as stale rather than resolving to whatever took its slot. Generations come from the operating system's random generator, so a mod cannot guess one it was never handed.
Building
Any clang with the wasm backend builds a mod. These are the flags the Axiom repository builds its own test mods with:
Link without --allow-undefined. With it, a call to a function that does not exist becomes an
import of one instead of a link error, and the first anyone hears of the typo is a mod that will not
load on somebody else's machine.
What the host checks first
Before a mod runs, the host reads its import section and compares it with the manifest and with the import list generated from the surface. Every refusal happens here, not mid-frame.
Each import must also have exactly the lowered signature the surface gives it, so a module that
imports count with any other type fails to load. Declaring a capability the module never imports is
not a refusal; it is reported as unused.
Each call the mod imports must also be one the backend answers. An import nothing answers is left unbound, so the module fails to load with the call named rather than trapping on its first use. The overview lists what each backend answers.
Once a mod runs, every call into the host is paid for in fuel, charged per crossing by the runtime rather than counted by the mod (Frames and fuel).
Not built yet
- The Axiom repository's generator also writes C++, Rust and Lua bindings, and those do not follow the
lowering above yet. C and C++ use
surface.h, and Rust uses axiom.rs, which the site writes from it (Languages). - The ABI has no version of its own, separate from each capability's major.
axiom buildpackages a directory as it stands. Compiling the source first, with--releaseor--target, is the mod toolchain's, which does not exist yet, so those flags exit 3.