Skip to main content

Crate elly_wasm

Crate elly_wasm 

Source
Expand description

A wasm32-unknown-unknown wrapper exposing the [elly] parse + eval pipeline to JavaScript.

The elly and muon crates are no_std; this thin shim links std only for the allocator that wasm32-unknown-unknown provides, so no wasm-bindgen (or any post-processing tool) is needed — the .wasm is loaded directly.

§ABI

Strings cross the boundary as (ptr, len) into wasm linear memory:

  • elly_alloc(len) -> ptr — reserve len bytes for JS to write UTF-8 into.
  • elly_run(ptr, len) -> out — parse and evaluate those bytes; returns a pointer to a length-prefixed result: a little-endian u32 byte length followed by that many bytes of UTF-8 JSON (see below).
  • elly_free(ptr, len) — release a block obtained from elly_alloc.

The JSON result is one of:

  • {"ast":<expr>,"value":"<display>"} — parsed and evaluated. <expr> is the tagged AST dump (elly::Expr::to_json).
  • {"ast":<expr>,"error":{"stage":"eval","raised":"<display>"}} — parsed, but evaluation raised a value that unwound to the top level (an explicit __Err_raise or a host failure like .div_by_zero); the AST is still shown.
  • {"error":{"stage":"parse","kind":"…"}} — a valid Muon tree but not a valid Elly program in this subset.
  • {"error":{"stage":"syntax","offset":N,"kind":"…"}} — the syntax layer (Muon) rejected the input.

Functions§

elly_alloc
Reserve len bytes of linear memory and hand ownership to the caller.
elly_free
Release a block previously returned by elly_alloc (same len).
elly_run
Run len UTF-8 bytes at ptr through the pipeline; return length-prefixed JSON.