fayasm is an experimental WebAssembly runtime in C99 built for people who want to understand execution internals, not hide them.
Instead of presenting a black box, fayasm keeps parsing, stack handling, control flow, traps, and host bindings visible and hackable. It is useful for learning, runtime prototyping, and embedded-focused experiments where you want clear control over tradeoffs.
Most runtimes optimize for performance and spec completeness first. fayasm takes a different path:
- Keep code paths understandable so new contributors can trace behavior quickly.
- Make runtime internals easy to test and evolve.
- Support practical experiments: host imports, table/memory operations, microcode preparation, and offload hooks for low-RAM targets.
fayasm already supports a substantial runtime slice:
- Real
.wasmparsing from disk or memory (fa_wasm.*) including types, functions, exports, globals, memories, tables, element segments, and data segments. - Runtime execution (
fa_runtime.*) with call frames, locals/globals, branch stack semantics, multi-value returns, label arity checks, memory64/multi-memory behavior, and trap propagation. - Reference operations and
call_indirectwith table lookup and signature validation, using encoded funcref storage (null = 0, indexn = n + 1). - Bulk memory and table operations, typed element expressions (
ref.func,ref.null,global.get), and live imported memory/table rebind after attach. - SIMD core + relaxed opcode coverage wired through
fa_ops.*(with active regression tests). - Host import bindings for functions, memories, and tables; dynamic-library bindings on supported desktop targets.
- JIT/microcode preparation scaffolding (
fa_jit.*) with per-function opcode caches, optional prescan, and spill/load hooks for JIT programs and linear memory.
./build.shDefault native behavior:
- Cleans and configures
build/ - Builds shared + static libraries
- Builds tools (including
build/bin/fayasm_run) - Builds fixtures from
wasm_samples/when toolchains are available - Runs
build/bin/fayasm_test_main
build/bin/fayasm_test_main --list
build/bin/fayasm_test_main call_indirect
build/bin/fayasm_test_main wasm_samplebuild/bin/fayasm_run wasm_samples/build/arithmetic.wasm sample_const42
# result[0] (i32): 42
build/bin/fayasm_run wasm_samples/build/control_flow.wasm sample_factorial_6
# result[0] (i32): 720If your module has parameters, pass typed args:
build/bin/fayasm_run ./my_module.wasm add i32:7 i32:5Supported CLI arg types:
i32:<value>i64:<value>f32:<value>f64:<value>
mkdir -p build
cd build
cmake .. \
-DFAYASM_BUILD_TESTS=ON \
-DFAYASM_BUILD_SHARED=ON \
-DFAYASM_BUILD_STATIC=ON
cmake --build .
ctest --output-on-failure./wasm_samples/build.shThe script prefers Emscripten and falls back to Rust (wasm32-unknown-unknown) when needed.
Use the target-aware wrapper:
./build.sh --target esp32 --esp-idf-path /Users/riccardo/esp/esp-idf --no-fixturesUseful overrides:
./build.sh --target esp32 \
--esp-idf-path /Users/riccardo/esp/esp-idf \
--esp-ram-bytes 262144 \
--esp-cpu-count 2 \
--cmake-arg -DFAYASM_BUILD_SHARED=OFFNotes:
- ESP32 targeting is compile-time (
FAYASM_TARGET_ESP32,FAYASM_TARGET_*). - Embedded builds intentionally avoid
dlopen/dlsym; dynamic-library host binding returnsFA_RUNTIME_ERR_UNSUPPORTED.
FAYASM_MICROCODE=1|0to force-enable/disable microcode tables (otherwise resource-gated: RAM/CPU probe).FAYASM_JIT_PRESCAN=1to enable per-function prescan.FAYASM_JIT_PRESCAN_FORCE=1to force prescan mode.FAYASM_TARGET_RAM_BYTES/FAYASM_TARGET_CPU_COUNTcompile-time hints for embedded probes.
src/fa_runtime.*: execution loop, frames, locals/globals, memory/table plumbing, trap + spill/load hooks, host bindings.src/fa_ops.*: opcode descriptors + dispatch, microcode-backed math/bit/select/float-special handlers, SIMD and ref ops.src/fa_jit.*: resource probe, budget/advantage scoring, opcode import/export, prepared-op execution.src/fa_wasm.*: parser/loader for module structure and function bodies.src/fa_wasm_stream.*: instruction cursor and immediate decoding helpers.src/fa_job.*: operand stack and register window.test/:fayasm_test_mainharness with runtime regressions + optional wasm fixture smoke tests.
- Standardize runtime-wide spill/load persistence conventions for versioned opcode + memory payloads.
- Expand smoke coverage using
wasm_samples/modules. - Validate repeated offload cycles on low-RAM targets.
- Broaden smoke coverage toward non-SIMD language/toolchain outputs.
- Add low-footprint runtime validation passes for ESP32-class targets (tables, call depth, spill/load cycles).
- Explore background offload/prefetch with wear-aware storage strategies.
- Validate and tune embedded resource heuristics (
FAYASM_TARGET_*) across more targets.
src/- runtime, parser, opcode, JIT, and architecture code.test/- regression and smoke harness (fayasm_test_main).samples/cli-runner- standalone CLI executor (fayasm_run).samples/host-import- dynamic-library host import example.samples/esp32-trap- trap + SD-backed offload example.wasm_samples/- fixture sources and builder script.studies/- research archive for runtime/JIT/WASM investigations.ROADMAP.md- active planning priorities.AGENTS.md- AI collaborator reference and workflow rules.
- Keep changes incremental and test-backed.
- Update
README.md,AGENTS.md, andROADMAP.mdwhen behavior or priorities change. - Add/extend tests for runtime or opcode changes.
- When editing
src/fa_ops.c, keep its explanatory section/macro comments updated with the code paths they describe. - Log new research under
studies/and index it inAGENTS.md.
fayasm is intentionally experimental, but the direction is practical: clear runtime internals, solid regression coverage, and a path toward robust low-resource execution.
Inspired by WASM3.
Riccardo Cecchini, 2025. MIT License.