Grain toolchain
grain (Grain language compiler, see https://grain-lang.org/docs) is on PATH
at /usr/local/bin/grain. Check the version with grain --version.
Common commands
grain main.gr— compile and run (runs the module with the bundled runtime).grain compile main.gr -o main.wasm— compile to WebAssembly.--releaseoptimised build,--watalso emits a.watfile.--no-wasm-tail-callif the target runtime has no tail-call support.--import-memory,--initial-memory-pages,--maximum-memory-pages.
grain format file.gr(--write/-o),grain doc file.gr.grain lsp— language server over stdio.
Notes for host integration
- Compiled modules import
wasi_snapshot_preview1and exportmemory,
_start(runs the module top level — call it once) and everyprovided
function. Numberparameters are tagged values: an integernis passed as
(n << 1) | 1. Use@unsafefunctions typed withWasmI32/WasmI64to
get raw wasm values.- Grain emits tail calls (
return_call): with wazero enable
experimental.CoreFeaturesTailCall, or compile with--no-wasm-tail-call. - v0.7.x ("Farro") uses linear memory with reference counting; v0.8 moves to
WebAssembly GC, so low-level memory code will change.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
|