Browser WASM API
The browser wrapper crate is
crates/rukalang_wasm.
It currently exposes these wasm-bindgen APIs:
compile_for_browser_json(source_name, source_text)analyze_for_browser_json(source_name, source_text)lex_for_browser_json(source_text)
Success payload fields:
ast_graphhir_graphmir_graphrust_sourcewat_sourcewasm_bytes(optionalu8array; present only when binary emission succeeds)wasm_diagnostics(non-fatal backend diagnostics)
Build prerequisite for direct WASM emission:
- run
./scripts/build-runtime-wasm.shbefore Rust or web WASM builds/tests that consume browser artifacts
Error payload shape:
- object with
diagnosticsarray - each diagnostic includes
phaseandmessage - syntax diagnostics may include
lineandcolumn - phase values currently include
module,syntax,meta,check,mir_lower, andcodegen
compile_for_browser_json behavior notes:
- Rust/AST/HIR/MIR artifacts are emitted when frontend + MIR + Rust codegen pass.
- AST/HIR/MIR graph payloads are browser-friendly Cytoscape data rather than DOT text.
- WASM backend diagnostics are reported in
wasm_diagnosticswithout failing the whole compile payload. wasm_bytesis omitted when the current source uses unsupported WASM backend features.wat_sourceis generated from emittedwasm_bytesviawasmprinter, with synthesized names enabled to improve readability; when WASM emission fails,wat_sourceis empty.- Emitted
wasm_bytesare validated withwasmparserbefore they are returned. - Emitted browser WASM exports
run_main, which calls runtimeassert_no_leaksby default after invoking usermain.
analyze_for_browser_json payload shape:
ok: boolean (truewhen no diagnostics were produced)diagnostics: same diagnostic entry shape as compile errorshighlight_spans: lexical/semantic token spans used by the editor
Validate the wrapper crate:
cargo test --manifest-path crates/rukalang_wasm/Cargo.toml