Reggie, the experimental Gleam -> WASM compiler (mirror) reggie.desertthunder.dev
wasm compiler rust gleam
Rust 92%
JavaScript 4%
CSS 2%
Handlebars <1%
TypeScript <1%
Gleam <1%

README.md

Regulus #

Regulus ("Reggie") is an experimental Gleam to WebAssembly compiler written in Rust.

Reggie

The compiler uses tree-sitter to parse Gleam source, builds compiler-owned data structures, lowers a supported subset of Gleam to core IR, and emits .wasm with optional WAT output.

Gleam source
  -> tree-sitter syntax tree
  -> AST
  -> name resolution
  -> type checking
  -> core IR
  -> WebAssembly module
  -> .wasm / optional WAT

Status #

Regulus is not a full Gleam compiler yet. It can compile and run small programs using scalar values, managed values, pattern matching, closures, selected stdlib modules, and host imports. The compiler pipeline is intentionally visible so that each layer can be tested and explained.

At a glance #

Area Status
Single-file Gleam to Wasm Supported
Type checking Broad subset
Managed runtime values Partial
Standard library Selected modules and intrinsics
Whole-project linked output Supported subset
Dependency source loading Selected Hex and path packages
Browser, bundler, and Node.js Supported adapter subset
WASI ABI Incomplete

Working today #

Supported Gleam surface #

WebAssembly output #

Not yet implemented #

For more detail, see the case-study book in docs/book and the user/development docs in docs/website.

Usage #

Build a Gleam project into one linked Wasm artifact:

cargo run -q -p compiler_cli -- build examples/scalar_project

Compile a single Gleam source file:

cargo run -q -p compiler_cli -- compile fixtures/e2e/public_id.gleam \
  -o .sandbox/public_id.wasm \
  --emit wasm,wat \
  --dump-dir .sandbox/dumps

--emit selects artifacts such as wasm, wat, ast, resolved, typed, and ir. The --dump-dir flag writes debug output for compiler stages. See CLI usage for project builds, targets, artifacts, and run.

Development #

Use the Rust workspace from the repository root:

cargo fmt
cargo test
cargo clippy --workspace --all-targets

To run examples & tests:

cargo test -p compiler_core
cargo test -p compiler_cli
cargo run -q -p compiler_cli -- compile fixtures/e2e/public_id.gleam \
  --out-dir .sandbox --emit wasm,wat
cargo run -q -p compiler_cli -- run fixtures/e2e/public_id.gleam
cargo run -q -p compiler_cli -- build examples/scalar_project \
  --target bundler --out-dir .sandbox

Documentation #

cd docs/website
pnpm install
pnpm docs:dev