wasm-mumu

Crates.iowasm-mumu
lib.rswasm-mumu
version0.1.1
created_at2025-09-04 16:05:13.641722+00
updated_at2025-09-04 16:10:49.70127+00
descriptionWASM wrapper for the MuMu/Lava interpreter
homepagehttps://lava.nu11.uk
repositoryhttps://gitlab.com/tofo/wasm-mumu
max_upload_size
id1824471
size96,741
(justifiedmumu)

documentation

README

wasm-mumu

Minimal WebAssembly wrapper for the MuMu/Lava interpreter. It compiles the Rust interpreter to WebAssembly and exposes a tiny JS API.

What’s included

  • Browser-safe interpreter surface (no dynamic extend(…), no filesystem).
  • WASM class WasmMumu with:
    • new(verbose: boolean)
    • exec(code: string)result object
    • poll() to progress iterator printing
  • Result object shape: { ok, value, value_string, value_type, prints }.

Build

You’ll need wasm-pack:

cargo install wasm-pack
wasm-pack build --release --target web

This produces pkg/wasm_mumu.js and pkg/wasm_mumu_bg.wasm.

Quick test (no bundler)

  1. Create a simple demo page under web/ (see example below).
  2. Build assets directly into web/pkg:
wasm-pack build --release --target web --out-dir web/pkg
  1. Serve the folder with any static server and open it in a browser:
cd web
python3 -m http.server 8080
# open http://localhost:8080

Example: web/index.html

<!doctype html>
<meta charset="utf-8"/>
<title>MuMu WASM demo</title>
<div>
  <textarea id="code" rows="8" cols="80">slog( 1 + 2 * 3 )</textarea><br/>
  <button id="run">Run</button>
</div>
<pre id="out"></pre>
<script type="module">
  import init, { WasmMumu } from "./pkg/wasm_mumu.js";

  const out = document.getElementById('out');
  const code = document.getElementById('code');
  const runBtn = document.getElementById('run');

  await init();
  const vm = new WasmMumu(false);

  runBtn.onclick = () => {
    const res = vm.exec(code.value);
    out.textContent = JSON.stringify(res, null, 2);

    // drive iterator printing (if any)
    let ticks = 0;
    const id = setInterval(() => {
      const n = vm.poll();
      ticks += 1;
      if (n === 0 || ticks > 100) clearInterval(id);
    }, 16);
  };
</script>

JS API

  • new WasmMumu(verbose: boolean): create an interpreter instance.

  • exec(source: string): executes MuMu/Lava code and returns:

    {
      "ok": true,
      "value": { "...": "JSON view of the final Value" },
      "value_string": "pretty printed value",
      "value_type": "short type name",
      "prints": ["... lines produced by slog/sput ..."]
    }
    
  • poll(): run non-blocking iterator printers once; returns number of items printed this tick.

Notes

  • Not available in the browser (initially): extend(...) (native/dlopen) and include(...) (filesystem). These can be added later via WASM Components (for plugins) and fetch-backed includes.
  • slog/sput still populate prints in the result; prefer reading that buffer for UI output.
  • If your core engine crate path differs, update the dependency path in Cargo.toml.

MIT or Apache-2.0, at your option.

Commit count: 15

cargo fmt