Expand description
The guest side of the larvae worm ABI.
A worm is a wasm32 module that larvae loads and calls. wasm has no strings.
Thus all data crosses as an offset and a length into the linear memory of the
module. This crate owns that protocol, so a worm author does not write it:
larvae_worm::frontend!(|source: &str, config: &str| -> anyhow::Result<String> {
luaux::compile_configured(source, Backend::Vide, &Config::parse(config)?)
});The macro is not the only entry point. abi is public and documented. Thus
a worm with an unusual design can export the raw functions itself, without a
copy of the macro.
§The ABI
A worm exports memory, plus:
| export | signature |
|---|---|
larvae_alloc | (len: u32) -> ptr |
larvae_dealloc | (ptr, len: u32) |
larvae_transform | (src_ptr, src_len, cfg_ptr, cfg_len) -> *header |
larvae_init | (cfg_ptr, cfg_len, rules_ptr, rules_len) |
larvae_visit | (rule, epoch, node_id) |
larvae_transform returns a pointer to a three word header,
[out_ptr, out_len, ok]. ok is 1 when the bytes are output and 0 when they
are an error message. The header lives in a static, so the host does not free
it. The host calls larvae_dealloc(out_ptr, out_len) when it has read the
payload out.
Re-exports§
pub use node::Node;
Modules§
- abi
- The raw ABI, for a worm that wants the exports without
frontend! - node
- The guest side of the node API, so a rule reads an ordinary type and not offsets
Macros§
- frontend
- Define a front-end worm. It takes source text and returns transformed source.
- rules
- Define the rule half of a worm.
Constants§
- ABI_
VERSION - The ABI revision this crate implements. It must match
apiinworm.toml.