Runtime abstraction + browser REPL

Decouple ForthVM from wasmtime via a Runtime trait so the same outer
interpreter, compiler, and 200+ word definitions work on both native
(wasmtime) and browser (js-sys WebAssembly API) backends.

Runtime trait (runtime.rs):
- HostAccess trait for memory/global ops inside host function closures
- HostFn type: Box<dyn Fn(&mut dyn HostAccess) -> Result<()>>
- Runtime trait: memory, globals, table, instantiate, call, register

NativeRuntime (runtime_native.rs):
- Wraps wasmtime Engine/Store/Memory/Table/Global/Func
- CallerHostAccess bridges HostAccess to wasmtime Caller API
- Feature-gated behind "native" (default)

outer.rs refactor:
- ForthVM<R: Runtime> — generic over execution backend
- All 87 host functions converted from Func::new closures to HostFn
- All memory access via rt.mem_read/write_*, global access via rt.get/set_*
- Zero logic changes — pure API conversion

wafer-core feature gates:
- default = ["native"] includes wasmtime + all native modules
- Without "native": pure Rust only (outer, codegen, optimizer, dictionary)

Browser REPL (crates/web):
- WebRuntime: js-sys WebAssembly.Memory/Table/Global/Module/Instance
- WaferRepl: wasm-bindgen entry point (evaluate, data_stack, reset)
- WebAssembly.Function with Safari fallback (wrapper module)
- Frontend: dark terminal UI, word panel, init code editor, history
- Build: wasm-pack build --target web

All 452 tests pass (431 unit + 1 benchmark + 9 comparison + 11 compliance).
This commit is contained in:
2026-04-13 10:06:37 +02:00
parent 7780ea3ab3
commit 321f001232
20 changed files with 3576 additions and 2707 deletions
+4 -16
View File
@@ -1,15 +1,5 @@
[advisories]
ignore = [
# wasmtime v31 known issues -- will resolve when upgrading wasmtime
{ id = "RUSTSEC-2025-0046", reason = "wasmtime v31: fd_renumber panic" },
{ id = "RUSTSEC-2025-0118", reason = "wasmtime v31: shared memory unsoundness" },
{ id = "RUSTSEC-2026-0006", reason = "wasmtime v31: f64.copysign segfault" },
{ id = "RUSTSEC-2026-0020", reason = "wasmtime v31: WASI resource exhaustion" },
{ id = "RUSTSEC-2026-0021", reason = "wasmtime v31: fields instance panic" },
# Unmaintained transitive deps from wasmtime/rustyline
{ id = "RUSTSEC-2025-0057", reason = "fxhash: transitive dep, no alternative" },
{ id = "RUSTSEC-2024-0436", reason = "paste: transitive dep, no alternative" },
]
ignore = []
[licenses]
allow = [
@@ -19,6 +9,7 @@ allow = [
"BSD-2-Clause",
"BSD-3-Clause",
"BSL-1.0",
"MPL-2.0",
"Unicode-3.0",
"Zlib",
]
@@ -31,15 +22,12 @@ wildcards = "deny"
skip = [
"getrandom",
"hashbrown",
"linux-raw-sys",
"object",
"rustix",
"r-efi",
"thiserror",
"thiserror-impl",
"wasm-encoder",
"wasmparser",
"wast",
"windows-sys",
"winnow",
]
[sources]