The toolchain at a glance
What happens between a .nib file and an answer — the stages every program passes, and the three ways it can then run.
nibc is one OCaml program. Every command starts the same way, and differs only in what it does once the program is known to be well formed.
The front end
- Parse. A Menhir grammar reads each file into an AST. A string literal with a
{…}splice is rewritten into a++chain of its parts and oneshowper splice — the one implicit conversion in the language. - Load.
use "path.nib"loads files relative to the one that writes it (std/…from the compiler's own library); packages are resolved, names qualified, and a package'srequires/offerswall enforced. - Interface check. Every effector is held against the interfaces it says it answers, operation by operation, and every wire binding against the interface on its left.
- Type inference. Hindley–Milner with records as rows, plus two things most checkers do not track: the effect row (
! Io.Print, what a function may perform) and the raises row (what it may raise). Both are upper bounds the body is held to, both ways.
A program that fails any stage is refused with a diagnostic that ends in a code, [nib-t006] say. The codes are a stable table: nibdoc --list-codes prints it and nibdoc --explain CODE the prose for one. nibc FILE alone checks and prints one ok line; exit status is 0 accepted, 1 refused, 2 a bad command line.
Three ways to run
| command | what runs | when to use it |
|---|---|---|
nibc --run FILE [--wire W] | the walker: the AST, evaluated as written | always works; the reference for every answer |
nibc build --target native | an executable, through LLVM | serving; anything that should be fast |
nibc build --target wasm32 / wasm32-wasip2 | a WebAssembly module or component | a host that runs wasm; sandboxing by construction |
The walker is normative. It is an abstract machine whose continuation is a list of defunctionalised data frames, which is what lets a run be journalled, cut and adopted elsewhere (The journal). Both compilers are measured against it: a construct either compiles to code that answers what the walker answers — the same value, the same raise, the same bytes on a socket — or is refused by name. Nothing compiles to something close.
The compilers share one middle: lib/aot.ml lowers a wire's entry, with every function it calls inlined (or, for a recursive one, compiled out of line as a closure), to a small IR of ops over 64-bit locals. Two backends write that IR out — lib/aot.ml itself as WebAssembly, lib/native.ml as LLVM IR — and both link the same runtime, nibrt, a no_std Rust crate (system/tools/nibrt) holding the counted heap, the vector and map slow paths, and, natively, the fibre host.
Flags worth knowing
| flag | does |
|---|---|
--run --arg name=value | passes the entry's parameter (a String, as written) |
--run --parallel N | lets parallel kernels use N cores |
--run --kernels | lists every Vec.map/Vec.fold and whether it can run in parallel |
--run --journal-out F / --journal-in F | records a run / replays one (The journal) |
--run --capture F / --adopt F | cuts a run at an operation / continues it in another process |
--transcript FILE | checks, then runs every wire and test, printing all of it |
--fmt FILE | prints the program back as the compiler reads it |
build --target native --check | links the runtime's checking build (traps a double free) |