sbx-kits/grain-toolchainpublic Fork
⑂ main
Commits
⬇ Clone ▾
git clone https://git.rickub.com/sbx-kits/grain-toolchain.git
git clone ssh://git@rickub.com/sbx-kits/grain-toolchain.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

Download ZIP
🛟 Updated. bb06360 · on main · k33g · 4h ago
grain-context.md · 27 lines · 1.3 KBmarkdown
Blame HistoryOpen raw

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.
    • --release optimised build, --wat also emits a .wat file.
    • --no-wasm-tail-call if 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_preview1 and export memory,
    _start (runs the module top level — call it once) and every provided
    function.
  • Number parameters are tagged values: an integer n is passed as
    (n << 1) | 1. Use @unsafe functions typed with WasmI32/WasmI64 to
    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
# 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.
  - `--release` optimised build, `--wat` also emits a `.wat` file.
  - `--no-wasm-tail-call` if 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_preview1` and export `memory`,
  `_start` (runs the module top level — call it once) and every `provide`d
  function.
- `Number` parameters are tagged values: an integer `n` is passed as
  `(n << 1) | 1`. Use `@unsafe` functions typed with `WasmI32`/`WasmI64` to
  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.