Language reference
MUL language reference
This is the current description of MUL Source: what you can write today, what
it means, and which errors you get. It merges the accepted RFCs in
spec/ into one document for people and AI agents. When
this reference and an RFC disagree, the RFC is normative and this page has a
bug.
Scope: MUL 0.1.0 (i32, bool and string,
arithmetic, comparisons, logical operators, calls, let/var variables,
assignment, block scopes, if/else, while, pure/io effects, print,
the normative run-time semantics of RFC-003).
Pages
| Page | Contents |
|---|---|
| syntax | files, modules, functions, statements, variables and scopes, if/else, while, expressions, precedence, comments, limits |
| types | i32 and bool, literals, arithmetic, comparisons, logical operators, type checking |
| effects | pure and io in signatures, the call rule, what a program can observe |
| errors | compile-time and run-time error semantics, exit codes, every MUL-* code |
| idioms | how to express common things with the current subset |
| not-in-mul | constructs the language does not have, now or by design |
| highlighting | token classes for syntax highlighting: keywords, effects, types, literals, the mul-ir format |
| guide | the compact version of all of the above, printed by mul guide |
The formal grammar is spec/grammar.ebnf. The same
content in the llms.txt format is at the repository root.
The smallest program
// expect: Hello, world!
// expect: 0
module demo
pub fn main() -> i32 io {
print("Hello, world!")
return 0
}
mul run executes main: the program prints Hello, world!, and the value
main returns becomes the exit code, here 0. mul run --print-result also
prints that value on the last line.
How examples are checked
Every mul code block in this directory is a complete module whose first lines
state the expected result, in the same format as
tests/golden/:
// expect: <line>, one per line —mul run --print-resultprints exactly these lines (what the program prints, then the value ofmain) and exits with code 0; plainmul runprints all but the last and exits with that value;// expect-error: <code>—mul runfails and reports thisMUL-*code;// expect:lines before it are what the program prints before the trap.
The test crates/mul-cli/tests/docs.rs runs
every block through mul check and mul run in both modes, so the examples
cannot go stale.
Fragments that are not complete modules use text blocks.
Examples here are in the pretty layout, for people; the compact guide uses the compact layout, the canonical form for AI agents (syntax). The test also checks that every block of the guide is in the compact layout.
Commands
| Command | Action |
|---|---|
mul check <file> |
parse and type-check; prints <file>: ok |
mul ir [--source-map] <file> |
print the verified IR, or with --source-map the file, its SHA-256 and the byte range and line:column of every function, block, instruction and terminator (ADR-017) |
mul run [--backend interp|cranelift] [--print-result] <file> |
run main; its result is the exit code, or printed with --print-result |
mul build [-o <output>] [--print-result] <file> |
build a native executable that behaves the same way |
mul build --emit mulb [-o <output>] <file> |
write the verified IR with its source map and Code Graph as a .mulb file; check, ir, run, build and inspect accept a .mulb path in place of source (RFC-012) |
mul test [<path>...] |
run every .mul file with an // expect: header under the paths in the interpreter and the Cranelift JIT (RFC-003) |
mul fmt [--pretty] [--check | --stdout] <file>... |
rewrite files in the compact layout, or the pretty one (RFC-011) |
mul inspect --file <file>.mulb |
print the header (schema version, feature masks, capabilities, content hash) and the section list of a .mulb file; rejections carry the MUL-B0xx code (RFC-012) |
mul inspect [--symbol <id>] <file> |
print the Code Graph: snapshot id and symbols (functions, their parameters and locals), or one symbol with its content hash, calls and references; a parameter or local is <function>/parameter:<name> or <function>/local:<name> and shows its reads and writes (ADR-014, ADR-019) |
mul guide |
print guide |
This page is docs/language/ in the repository, published as it is. Every mul code block on it is compiled and run by the test suite.