# Landin 0.2.11, for whoever has to write it One systems language from a 32 KB microcontroller to a hosted application. Manual memory with arenas as the idiom and no garbage collector, reference counting or destructors; separate reference permission and binding mutability; local origin and escape analysis rather than a borrow checker; concepts with evidence tables for both static generics and runtime dispatch; no compile-time execution and no macros. Native backends emit assembly for hosted systems and microcontrollers; the capabilities page lists the current targets. This half of the file is generated from the compiler's own tables and the specification's own grammar. The documents follow it in full. The one thing to know first: the kernel the compiler enables is narrower than the language the tour describes, and the compiler says which is which by name rather than guessing ([1830]). Section 4 is that list. A program written against the whole tour fails with it, not with a parse error. ## 1. Install, compile and run `refine` is Landin's compiler, and the command you run for everything else too: checking, running and compiling programs, formatting source, and the language server and debug adapter your editor starts. An install gives you `refine`, a few further commands you run through it, and Landin's standard library. There are six ways to get it: with the install script, with Homebrew, from a release, in a container, with nix, or from source. Use 0.2.9 or later: [the first program](https://www.701.dev/readme.html#your-first-program) needs `refine run` and `hosted/blocking`, both newer than 0.2.8. ### With the install script On Linux x86-64 or arm64, or on a Mac with Apple Silicon: ```sh curl -fsSL https://www.701.dev/install.sh | sh ``` It downloads the newest release's archive for your platform, the one [From a release](https://www.701.dev/readme.html#from-a-release) describes, checks it against the `.sha256` published beside it and unpacks it into `~/.landin`. On Linux that is the static archive unless you ask for the other one. It edits none of your files and needs no root: it prints the line that puts `~/.landin/bin` on your `PATH`, which you add to your shell's startup file. Run it again to replace that install with the newest release. Options follow `sh -s --`. To install a named release into a directory of your choosing: ```sh curl -fsSL https://www.701.dev/install.sh | sh -s -- --version 0.2.11 --dir ~/opt/landin ``` From the release after 0.2.11 a release has two archives for each Linux architecture, and `--variant static` or `--variant dynamic` chooses between them. Without the option you get the static one, which starts on any Linux. The dynamic one uses your system's glibc and needs glibc 2.38 or later: ```sh curl -fsSL https://www.701.dev/install.sh | sh -s -- --variant dynamic ``` The option is for Linux only. On a Mac the script refuses it, because macOS has one archive. `--list` names the archives a release has, both Linux ones among them. `--help` lists the options. The script is [`install.sh`](install.sh) in this repository, served unchanged; read it before you run it if you like. It refuses a host no archive serves, Intel Macs, FreeBSD, Windows and other CPU architectures among them. It also refuses an archive whose `refine` does not start on your host, after downloading and checking it. That is what the dynamic archive, and every archive of 0.2.11 and earlier, does on NixOS, on musl distributions and with a glibc older than 2.38. In both cases it says so, installs nothing, and names nix and the source build instead. For `--variant dynamic` it also says that the dynamic archive needs glibc 2.38 and that the static one starts on any Linux. With the GitHub CLI installed it also prints the commands that check the archive's attestation, as [From a release](https://www.701.dev/readme.html#from-a-release) describes. To remove the install, delete `~/.landin`. ### With Homebrew Homebrew installs `refine` on a Mac with Apple Silicon, and on Linux x86-64 and arm64. An Intel Mac is not covered. ```sh brew install 701-dev/tap/landin ``` `brew upgrade landin` updates it and `brew uninstall landin` removes it. To move an install from the earlier tap `janhaan/tap`, run `brew uninstall landin`, then the command above. The formula moves to a new release within a day of its publication. This installs the release archive for your platform, the one [From a release](https://www.701.dev/readme.html#from-a-release) describes; on Linux, from the release after 0.2.11, that is the static one. Its `bin/refine`, `libexec/landin` and `lib/landin` stay together in Homebrew's own directory for the package, and Homebrew puts `refine` on your `PATH`. Linking, and so `refine run`, needs Xcode's command-line tools on macOS and the system's GCC driver on Linux. See [the linker on Linux and macOS](https://www.701.dev/readme.html#the-linker-on-linux-and-macos). The `library: ` line of `refine version` then names the library inside that directory, for example `/opt/homebrew/Cellar/landin/VERSION/lib/landin` on a Mac. ### From a release The archive for your platform on [the releases page](https://github.com/701-dev/Landin/releases) holds `bin/refine`, the commands it runs from `libexec/landin` and the library under `lib/landin`, with no top-level directory. Unpack it into a directory of its own and put its `bin` on your `PATH`. From the release after 0.2.11, a release publishes two archives for each Linux architecture, x86-64 and arm64. macOS has one archive, as before, and FreeBSD x86-64 one, `landin-VERSION-x86_64-freebsd.tar.gz`, whose `refine` needs only the base system and links with its `cc` and binutils' `as` (`pkg install binutils`). The static archive has the platform's name: `landin-VERSION-x86_64-linux.tar.gz` and `landin-VERSION-aarch64-linux.tar.gz`. Its `refine` and the commands it runs have glibc linked in. It asks for no loader and no shared library, so it runs on any Linux: musl distributions such as Alpine, NixOS, and distributions whose glibc is older. The dynamic archive is beside it: `landin-VERSION-x86_64-linux-dynamic.tar.gz` and `landin-VERSION-aarch64-linux-dynamic.tar.gz`. Its `refine` uses the system's glibc, so it takes the system's glibc fixes. It needs glibc 2.38 or later and its standard loader, `/lib64/ld-linux-x86-64.so.2` on x86-64 and `/lib/ld-linux-aarch64.so.1` on arm64. It does not start on Debian 12 (glibc 2.36), Ubuntu 22.04 (2.35) or RHEL 9 (2.34), nor on NixOS or a musl distribution. 0.2.11 and earlier have one Linux archive for each architecture, and those stay published. It has the platform's name but is a dynamic one, linked against the glibc of Ubuntu 24.04, with the same needs as the dynamic archive above. Where it does not start, install with nix or build from source. The static archive holds two more files at its top level, which the dynamic one does not have. `LICENSE-GLIBC` is the copyright file of the Debian or Ubuntu `libc6-dev` package whose `libc.a` was linked in, with glibc's licence, the LGPL, version 2.1 or later. `NOTICE-GLIBC` names that glibc by its package version and distribution, says where its source is, and says how to relink `refine` with a modified glibc from Landin's public source. Beside each archive is `landin-VERSION-PLATFORM.tar.gz.sha256`, one line in `sha256sum`'s own format: `SUM landin-VERSION-PLATFORM.tar.gz`. For a dynamic archive, `PLATFORM` here and below ends in `-dynamic`, as in `x86_64-linux-dynamic`. Download it into the same directory as the archive and check the archive against it: ```sh sha256sum -c landin-VERSION-PLATFORM.tar.gz.sha256 # Linux shasum -a 256 -c landin-VERSION-PLATFORM.tar.gz.sha256 # macOS ``` It prints `OK` after the file name when the archive arrived whole and unchanged. It does not say who built it. The attestation does: the release workflow built each archive from its tag. With the GitHub CLI, check a downloaded archive before you unpack it: ```sh gh attestation verify landin-VERSION-PLATFORM.tar.gz --repo 701-dev/Landin \ --signer-workflow 701-dev/Landin/.github/workflows/release.yml \ --source-ref refs/tags/vVERSION --deny-self-hosted-runners ``` Releases up to 0.2.10 were built before the repository moved from the account `JanHaan` to the organisation `701-dev`, and their attestations name the old owner: for those, write `JanHaan` for `701-dev` in both options. Each archive leaves the compiler's debug information out and publishes it beside it as `landin-VERSION-PLATFORM-debug.tar.gz`, which for a dynamic archive ends in `-dynamic-debug.tar.gz`. You need that file only to read a crash of the compiler itself. ### In a container Each release publishes an image on GitHub's container registry, `ghcr.io/701-dev/landin:VERSION`. The tag is the release's version without the `v`: release `vVERSION` is tag `VERSION`. There is no `latest` tag, so name the version. Each tag holds Linux amd64 and arm64, and Docker or Podman picks the one for your host. Images start with the first release after 0.2.11; 0.2.11 and earlier have none. The image is Debian 13 with the static release archive for its platform unpacked in `/usr/local`: `refine` in `/usr/local/bin`, its commands in `/usr/local/libexec/landin` and the library in `/usr/local/lib/landin`. It also holds Debian's `gcc` and `libc6-dev`, which `refine` links with. Its working directory is `/work`. Mount your directory there and run as your own user, so the files `refine` writes are yours: ```sh docker run --rm -v "$PWD:/work" --user "$(id -u):$(id -g)" \ ghcr.io/701-dev/landin:VERSION refine run main.ldn ``` Compile and run a program the same way: give `refine compile main.ldn -o main` as the command, and then `./main`. `podman` takes the same arguments. With no command the image runs `refine version`, whose `library: ` line then says `/usr/local/lib/landin`. The release workflow attests each image. With the GitHub CLI, check one: ```sh gh attestation verify oci://ghcr.io/701-dev/landin:VERSION --repo 701-dev/Landin \ --signer-workflow 701-dev/Landin/.github/workflows/release.yml \ --source-ref refs/tags/vVERSION --deny-self-hosted-runners ``` The image links only for Linux on its own architecture. It holds no toolchain for firmware (Cortex-M, RISC-V, Xtensa) or for the other Linux architecture. Add one from Debian in an image of your own, for example for Cortex-M: ```dockerfile FROM ghcr.io/701-dev/landin:VERSION RUN apt-get update \ && apt-get install --no-install-recommends --yes gcc-arm-none-eabi libnewlib-arm-none-eabi \ && rm -rf /var/lib/apt/lists/* ``` `refine` also finds these Debian packages: - `gcc-riscv64-unknown-elf`, for RV32 firmware; - `gcc-aarch64-linux-gnu` and `libc6-dev-arm64-cross`, to link Linux arm64 programs on amd64; - `gcc-x86-64-linux-gnu` and `libc6-dev-amd64-cross`, to link Linux amd64 programs on arm64. Espressif's Xtensa compiler is not in Debian; it comes from Espressif. When a driver is missing, `refine`'s error names the package to install. To debug inside a container, install `gdb` the same way. It needs no extra capability. It warns that it cannot turn off address randomisation, which Docker's default security profile refuses, so a program's addresses can differ from one run to the next. An image moves only at a release: the Debian packages inside are the ones of the day the release was built. A second image, `ghcr.io/701-dev/landin-contributor:VERSION`, is for building the compiler itself. See [Building and checking](https://www.701.dev/readme.html#building-and-checking). ### With nix This command installs the prebuilt compiler and puts `refine` on your `PATH`: ```sh nix --extra-experimental-features 'nix-command flakes' \ profile install github:701-dev/Landin ``` It works on Linux x86-64, Linux arm64 and macOS arm64. It fetches the latest release archive, about 17 MB, and compiles nothing, so it takes seconds. On Linux, from the release after 0.2.11, that is the static archive. You can leave the `--extra-experimental-features` option out once `experimental-features = nix-command flakes` is in `~/.config/nix/nix.conf`. To run `refine` without installing it, use `nix run`. Everything after `--` goes to `refine`: ```sh nix run github:701-dev/Landin -- version nix run github:701-dev/Landin -- run main.ldn ``` The second line runs [the first program](https://www.701.dev/readme.html#your-first-program). To build from source instead, for example to get unreleased changes from main, install `#refine`. The first source build also fetches the pinned toolchain, which takes a few minutes: ```sh nix profile install github:701-dev/Landin#refine ``` In a clone, `nix build .#refine` builds the checkout into `result/`, and `nix build` alone fetches the release. ### From source On Linux x86-64, Linux arm64 or a Mac, you can fetch the pinned GNAT and GPRbuild and build from a clone. Any other host needs nix. `environments/pins.sh` holds the versions, URLs and SHA-256 sums of GNAT and GPRbuild. Its `landin_install_toolchain` downloads both archives and checks each against its sum. The archives are about 500 MB together. You need these tools first: - `curl`, `sha256sum` and `tar` for `landin_install_toolchain`; - `python3` and `git` for the build; - on a Mac, Xcode's command-line tools as well. ```sh git clone https://github.com/701-dev/Landin cd Landin . environments/pins.sh landin_install_toolchain "$HOME/landin-toolchain" x86_64-linux export LANDIN_GNAT_HOME="$HOME/landin-toolchain/gnat-$LANDIN_GNAT_VERSION" export LANDIN_GPRBUILD_HOME="$HOME/landin-toolchain/gprbuild-$LANDIN_GPRBUILD_VERSION" ./scripts/build.sh --compiler-only ``` These commands name `x86_64-linux`. Name `aarch64-linux` on Linux arm64 instead, and `aarch64-darwin` on a Mac. The build prints where it put `refine`. On Linux x86-64 that is `compiler/ada/build/linux-amd64/debug/bin/refine`, where `linux-amd64` is the build tag that keeps each host's objects apart. That is the debug build, which keeps the compiler's own internal checks on. `LANDIN_BUILD_MODE=release` builds the faster release one beside it. On Linux the release build links statically and needs glibc's static library, `libc.a`: `libc6-dev` has it on Debian and Ubuntu, and on Fedora you install `glibc-static`. The debug build does not need it. A static `refine` linked against musl and the jemalloc allocator has been built once, as a test, and the project does not build or publish one. It was built on Alpine 3.24, for x86-64 only, with Alpine's GNAT 15.2 and a GPRbuild 26.0.0 built from its sources. The pinned GNAT 16.1 has no musl build. Run with jemalloc's thread cache off (`MALLOC_CONF=tcache:false`), it passed the whole test program, 1279 of 1279 cases. On the scaling corpus it compiled about 6 % slower than the static glibc build. arm64 was not built. Making one needs source changes that are not in this repository, so you would have to make them yourself: two musl portability fixes in the C adapters, about twenty workarounds for GNAT 15.2, the jemalloc link and its heap figure, and accepting a musl host triple as Linux. Without the last, a `refine` built for musl refuses every compile that does not pass `--target=linux-x86-64`. The static glibc archive is the supported way to run `refine` on a musl distribution. This `refine` reads the clone's library, so put its directory on your `PATH` rather than copying it elsewhere. ### The linker on Linux and macOS Linking on Linux uses GCC as the linker driver, even when the program links no C library. `refine run` links, so it needs GCC too. The GCC is the one your distribution installs. `refine` looks for it under these names, in this order, and runs the first one it can start, so any one of them is enough: - `x86_64-pc-linux-gnu-gcc`, the name a GCC built from its own sources takes; - `x86_64-linux-gnu-gcc`, on Debian and Ubuntu; - `x86_64-redhat-linux-gcc`, on Fedora; - `gcc`, which `nix-shell -p gcc` provides on NixOS and `apk add gcc` on Alpine. On an arm64 machine the names are `aarch64-linux-gnu-gcc`, `aarch64-redhat-linux-gcc`, `aarch64-unknown-linux-gnu-gcc` and `gcc`, in that order. `--toolchain=NAME` names a driver yourself, and then `refine` tries that one alone. On Alpine, a program that links the C library, with `--link=libc`, also needs the `musl-dev` package. Without one, `refine` names each driver it looked for, in the same order, and says what to install. Checking, formatting, the language server and emitting assembly or the intermediate representation (IR) need none. macOS links through the Xcode command-line tools. ### Checking the install Run `refine version`. It names the compiler: a release, or `refine dev (01234567)` for a build from a clone. Its `library: ` line names the directory the standard library is read from: the archive's `lib/landin`, the one in Homebrew's directory for the package, or the clone. The lines under it name the `citations.txt` that `refine explain` reads, say whether it can be read, and list each command shipped beside `refine` with its path. Install `refine` as [the README](https://www.701.dev/readme.html#installing) describes. Copy a program into a file called `main.ldn` in a directory of its own, then compile and run it there: ```sh refine compile main.ldn -o fizzbuzz ./fizzbuzz ``` `refine` compiles for the computer it runs on unless `--target` names another. Each program prints what it computes and returns 0 when it succeeds. Its output is shown under its listing. A program that reads its standard input or takes an argument says so in its section. Every program here is compiled and run, and what it prints is checked, on Linux, macOS and FreeBSD. The `Fixture source:` line above each listing says where the program lives in the repository. [The firmware example](https://www.701.dev/readme.html#firmware-for-a-microcontroller) is the exception to both paragraphs: it is built for a microcontroller, runs in an emulator and has its own commands. ## 2. The vocabulary of the enabled kernel 48 reserved words. Reserved everywhere, including in ordinary name positions (D225), so `begin: i32 = 10` is invalid and `begin_value` is not. addr alignof and any atom begin break continue dec defer do else elsif end escaping extern fail false fixed for from if import in inc inout loop match mut none not or ptr public return sink sizeof struct then true try type unchecked undo uninit when while zeroed 13 scalar type names. Not keywords: they are ordinary declared names the kernel predeclares, so nothing stops a program shadowing one. u8 u16 u32 u64 i8 i16 i32 i64 usize isize f32 f64 bool 3 text type names, on the same footing. utf8 utf16 cstring Words a production recognises that nothing reserves. Each is an ordinary identifier wherever its own production does not meet it, which is the commonest way to misread the grammar. align as assembler at boot_stage c caller compiler concept distinct held interrupt into is keep layout lenof link linker naked noreturn of offsetof option out packed region section symbol thread through u16 u32 u64 u8 variant vector ## 3. The grammar of the enabled kernel, in one piece The 172 productions of [1740] to [1830], with the prose that explains them removed. A name in lower case is a rule, a quoted word is itself, `?` is optional, `*` is none or more, `+` is one or more, `...` between two quoted bytes is every byte from one to the other, and parentheses group. This is what the hand-written parser is written against, and `check.py` derives the whole fixture corpus from it. ``` program ::= import_declaration* declaration* import_declaration ::= "import" import_path ("as" identifier)? import_path ::= identifier ("/" identifier)* declaration ::= "public"? (atom_declaration | binding | function | external_function | machine_function | linked_binding | type_declaration | concept_declaration) | conformance_declaration | fixed_conditional | option_declaration | tool_directive option_declaration ::= "option" identifier ":" type "=" expression tool_directive ::= tool_namespace "." identifier "(" (expression ("," expression)*)? ")" tool_namespace ::= "compiler" | "assembler" | "linker" fixed_conditional ::= "fixed" "if" expression "then" declaration* ("elsif" expression "then" declaration*)* ("else" declaration*)? "end" "if" atom_declaration ::= identifier ":" "atom" identifiers ::= identifier ("," identifier)* space ::= " " | "\t" | line_end | comment line_end ::= "\n" | "\r\n" | "\r" identifier ::= lower (lower | digit | "_")* | "_" (lower | digit | "_")+ lower ::= "a" ... "z" digit ::= "0" ... "9" keyword ::= "addr" | "alignof" | "and" | "any" | "atom" | "begin" | "break" | "continue" | "dec" | "defer" | "do" | "else" | "elsif" | "end" | "escaping" | "extern" | "fail" | "false" | "fixed" | "for" | "from" | "if" | "import" | "in" | "inc" | "inout" | "loop" | "match" | "mut" | "none" | "not" | "or" | "ptr" | "public" | "return" | "sink" | "sizeof" | "struct" | "then" | "true" | "try" | "type" | "unchecked" | "undo" | "uninit" | "when" | "while" | "zeroed" literal ::= integer | float | character | text | raw | "true" | "false" | "zeroed" | "uninit" character ::= "'" (character_escape | unicode_scalar) "'" unicode_scalar ::= any Unicode scalar except apostrophe, backslash or line_end character_escape ::= "\\" ("n" | "r" | "t" | "e" | "\\" | "\"" | "'" | "u" "{" hex_digit+ "}") text ::= "\"" (text_escape | text_byte)* "\"" text_byte ::= any byte except quote, backslash or line_end text_escape ::= "\\" ("n" | "r" | "t" | "e" | "\\" | "\"" | "'" | "x" hex_digit hex_digit | "u" "{" hex_digit+ "}") raw ::= quote_run raw_content quote_run quote_run ::= "\"" "\"" "\"" "\""* raw_content ::= any byte+ integer ::= decimal | hex | octal | binary float ::= decimal_fraction decimal_exponent? | hex_fraction binary_exponent decimal_fraction ::= decimal_digits "." decimal_digits decimal_exponent ::= ("e" | "E") ("+" | "-")? decimal_digits hex_fraction ::= "0x" hex_digits "." hex_digits binary_exponent ::= ("p" | "P") ("+" | "-")? decimal_digits decimal_digits ::= digit ((digit | "_")* digit)? hex_digits ::= hex_digit ((hex_digit | "_")* hex_digit)? decimal ::= digit ((digit | "_")* digit)? hex ::= "0x" hex_digit ((hex_digit | "_")* hex_digit)? octal ::= "0o" octal_digit ((octal_digit | "_")* octal_digit)? binary ::= "0b" binary_digit ((binary_digit | "_")* binary_digit)? hex_digit ::= digit | "a" ... "f" | "A" ... "F" octal_digit ::= "0" ... "7" binary_digit ::= "0" | "1" comment ::= block_comment | doc_comment | line_comment block_comment ::= "--(" block_item* ")--" block_item ::= block_comment | any byte that begins neither "--(" nor ")--" doc_comment ::= "---" (any byte except line_end)* line_comment ::= "--" (any byte except line_end)* binding ::= "mut"? identifier ":" declared_type ("=" expression)? | "mut"? identifier ":=" expression declared_type ::= type | atom_union type ::= function_type | array_type | pointer_type | slice_type | any_type | type_application | scalar_name | packed_unsigned | text_name | declaration_reference function_type ::= signature | c_convention c_signature | machine_convention c_signature array_type ::= "[" expression "]" type pointer_type ::= "ptr" "mut"? type slice_type ::= "[" "]" "mut"? type any_type ::= "any" concept_reference type_application ::= declaration_reference "(" type_argument ("," type_argument)* ")" type_argument ::= type | expression scalar_name ::= "u8" | "u16" | "u32" | "u64" | "i8" | "i16" | "i32" | "i64" | "usize" | "isize" | "f32" | "f64" | "bool" text_name ::= "utf8" | "utf16" | "cstring" type_declaration ::= identifier ":" "type" ("=" (encoded_union | atom_union | distinct_body | type | struct_body) | type_formals "=" (encoded_union | atom_union | distinct_body | type | struct_body)) distinct_body ::= "distinct" type concept_declaration ::= identifier ":" "type" "=" concept_body concept_body ::= "concept" type_formals ("is" concept_reference ("," concept_reference)*)? concept_entry* "end" identifier? concept_entry ::= identifier ":" signature conformance_declaration ::= type_formals? conformance_target "is" concept_reference (conformance_entries conformance_field? | conformance_field) conformance_entries ::= "(" conformance_argument ("," conformance_argument)* ")" | "(" ")" conformance_field ::= "through" identifier conformance_target ::= array_type | pointer_type | slice_type | any_type | type_application | declaration_reference conformance_argument ::= identifier ":" argument_rhs concept_reference ::= declaration_reference declaration_reference ::= identifier | qualified_reference qualified_reference ::= identifier ("." identifier)+ type_formals ::= "(" type_formal ("," type_formal)* ")" type_formal ::= identifier ":" "type" constraint? | "fixed" identifier ":" type constraint ::= "is" concept_reference atom_union ::= union_member "|" union_member ("|" union_member)* union_member ::= declaration_reference | type_application | pointer_type encoded_union ::= packed_unsigned? "(" encoded_member ("|" encoded_member)* ")" encoded_member ::= declaration_reference "=" exclusion packed_unsigned ::= "u1" | "u2" | "u3" | "u4" | "u5" | "u6" | "u7" | "u8" | "u9" | "u10" | "u11" | "u12" | "u13" | "u14" | "u15" | "u16" | "u17" | "u18" | "u19" | "u20" | "u21" | "u22" | "u23" | "u24" | "u25" | "u26" | "u27" | "u28" | "u29" | "u30" | "u31" | "u32" | "u33" | "u34" | "u35" | "u36" | "u37" | "u38" | "u39" | "u40" | "u41" | "u42" | "u43" | "u44" | "u45" | "u46" | "u47" | "u48" | "u49" | "u50" | "u51" | "u52" | "u53" | "u54" | "u55" | "u56" | "u57" | "u58" | "u59" | "u60" | "u61" | "u62" | "u63" | "u64" struct_body ::= ("layout" "(" ("c" ("," "packed")? | "packed" ("," ("u8" | "u16" | "u32" | "u64"))?) ")")? "struct" member+ "end" identifier? member ::= field | variant_part field ::= identifier ":" declared_type ("at" expression (".." expression)?)? variant_part ::= identifier ":" "variant" variant_case ("|" variant_case)* "end" identifier variant_case ::= identifier (":" "(" payload_field ("," payload_field)* ")")? payload_field ::= identifiers ":" declared_type function ::= (link_attributes "public"?)? identifier ":" declared_signature "=" body "end" identifier? external_function ::= (link_attributes "public"?)? c_convention link_symbol? identifier ":" c_declared_signature ("=" body "end" identifier?)? machine_function ::= (link_attributes "public"?)? machine_convention link_attributes? identifier ":" declared_signature "=" body "end" identifier? linked_binding ::= link_attributes "public"? binding c_convention ::= "extern" "(" "c" ")" machine_convention ::= "extern" "(" ("interrupt" | "naked") ")" link_symbol ::= "link" "(" "symbol" ":" text ")" link_attributes ::= "link" "(" link_attribute ("," link_attribute)* ")" link_attribute ::= ("symbol" | "section" | "region") ":" text | ("align" | "vector") ":" integer | "keep" | "thread" | "boot_stage" c_signature ::= "(" (parameters ("," "...")?)? ")" "->" returns errors? c_declared_signature ::= "(" (routine_formals ("," "...")?)? ")" "->" returns errors? signature ::= "(" parameters? ")" "->" returns errors? declared_signature ::= "(" routine_formals? ")" "->" returns errors? routine_formals ::= routine_formal ("," routine_formal)* routine_formal ::= parameter | type_formal errors ::= "!" (declaration_reference ("|" declaration_reference)* | "...") parameters ::= parameter ("," parameter)* parameter ::= "caller" identifiers ":" declared_type | ("escaping" ("into" identifier)?)? parameter_convention? identifiers ":" declared_type parameter_convention ::= "inout" | "sink" returns ::= "(" named_return ("," named_return)* ")" | "none" | "noreturn" named_return ::= identifiers ":" declared_type ("from" return_source ("," return_source)*)? return_source ::= "held"? identifier body ::= block block ::= statement* | value_statement* expression value_statement ::= binding | destructuring_binding | assignment | increment | discard | call | labeled_application | defer | undo | try | "return" "when" expression | "fail" expression "when" expression | break | continue | loop | while | for | if | match | bare_block | labeled_block destructuring_binding ::= "(" destructured_field ("," destructured_field)* ")" ":=" expression destructured_field ::= identifier (":" (identifier | "_"))? | "_" statement ::= binding | destructuring_binding | assignment | increment | discard | call | labeled_application | defer | undo | try | return | fail | break | continue | loop | while | for | if | match | unchecked | bare_block | labeled_block assignment ::= place assignment_operator expression assignment_operator ::= "=" | "+=" | "-=" | "*=" | "/=" | "%=" | "&=" | "|=" | "^=" | "<<=" | ">>=" | "+%=" | "-%=" | "*%=" increment ::= ("inc" | "dec") place discard ::= "_" "=" expression defer ::= "defer" call undo ::= "undo" call return ::= "return" ("when" expression)? fail ::= "fail" expression ("when" expression)? break ::= "break" identifier? ("when" expression)? continue ::= "continue" identifier? ("when" expression)? loop ::= "loop" "do" block "end" "loop" | identifier ":" "loop" "do" block "end" identifier condition ::= expression | condition_declaration condition_declaration ::= "mut"? identifier ":=" expression | "mut"? identifier ":" declared_type "=" expression while ::= "while" condition "do" block "end" "while" | identifier ":" "while" condition "do" block "end" identifier for ::= "for" identifier ("," identifier)? "in" expression ((".." | "..<") expression)? "do" block "end" "for" | identifier ":" "for" identifier ("," identifier)? "in" expression ((".." | "..<") expression)? "do" block "end" identifier try ::= "try" (call | labeled_application) if ::= "if" condition "then" block ("elsif" condition "then" block)* ("else" block)? "end" "if" match ::= "match" expression match_arm+ "end" "match" match_arm ::= (match_label | "_") ("(" match_binding ("," match_binding)* ")")? ":" (statement | expression) | match_label ("," match_label)+ ":" (statement | expression) match_label ::= declaration_reference | "ptr" match_binding ::= ("inout" | "sink")? identifier unchecked ::= "unchecked" "begin" block "end" "unchecked" bare_block ::= "begin" block "end" labeled_block ::= identifier ":" "begin" block "end" identifier place ::= indexed primary ::= literal | array_literal | array_repetition | struct_literal | empty_slice | labeled_application | indexed | call | address | pointer_conversion | any_construction | measurement | try | if | match | bare_block | "(" expression ")" array_literal ::= "[" expression ("," expression)* "]" array_repetition ::= "[" integer "of" expression "]" | "[" "of" expression "]" | "[" expression ("," expression)* "," "of" expression "]" struct_literal ::= "(" field_value ("," field_value)* ("," "of" expression)? ")" field_value ::= identifier ":" expression labeled_application ::= indexed "(" labeled_arguments ")" recovery? labeled_arguments ::= (expression ",")* labeled_argument ("," labeled_argument)* ("," "of" expression)? labeled_argument ::= identifier ":" argument_rhs argument_rhs ::= expression | type indexed ::= selection (index | slice_selection | ("." identifier))* index ::= "[" expression "]" slice_selection ::= "[" expression (".." | "..<") expression "]" selection ::= identifier ("." identifier)* call ::= indexed "(" arguments? ")" recovery? | written_conversion recovery ::= "else" expression | "else" "none" | "else" "(" identifier ")" block "end" address ::= "addr" place written_conversion ::= conversion_type "(" expression ")" conversion_type ::= function_type | array_type | pointer_type | slice_type | any_type | type_application pointer_conversion ::= "ptr" "(" expression ")" any_construction ::= "any" "(" expression ")" empty_slice ::= "[" "]" measurement ::= ("sizeof" | "alignof") type | "lenof" (call | labeled_application | indexed) | "lenof" "(" array_literal ")" | "offsetof" qualified_reference arguments ::= expression ("," expression)* ("," assembly_operand)* assembly_operand ::= ("in" | "inout") identifier ":" type "at" identifier "=" expression | "out" identifier ":" type "at" identifier | "out" "_" "at" identifier unary ::= ("-" | "~" | "not")* primary product ::= unary (("*" | "/" | "%" | "*%") unary)* sum ::= product (("+" | "-" | "+%" | "-%") product)* shift ::= sum (("<<" | ">>") sum)* conjunction ::= shift ("&" shift)* exclusion ::= conjunction ("^" conjunction)* alternation ::= exclusion ("|" exclusion)* comparison ::= alternation (("==" | "<>" | "<" | "<=" | ">" | ">=") alternation)? logical_and ::= comparison ("and" comparison)* expression ::= logical_and ("or" logical_and)* ``` ## 4. Spellings the compiler refuses by name Read this before writing anything the tour shows. Each row is a form the compiler recognises and declines, with the paragraph that describes it and what it is. None is pending work: [1830] separates a source form an implemented construct does not admit from a form the language withdrew and one a successor roadmap owns, and `spec.md`'s register says why for each. [0100] Several names in one declaration the parser refuses `shared declaration`; a recorded source-form boundary [0120] Declaring a type the parser refuses `declared type`; a recorded source-form boundary [0150] Integer types the checker refuses `wide integer type`, spelled i128, u128; transferred to Language evolution [0170] Floating point the checker refuses `narrow float type`, spelled f16; transferred to Language evolution [0520] Arrays are values the checker refuses `array value`; a recorded source-form boundary the checker refuses `array element`; a recorded source-form boundary [0540] `zeroed`: the all-zero value the checker refuses `zeroed value`; a recorded source-form boundary [0560] Filling an array with one value the parser refuses `array repetition`; a recorded source-form boundary [0570] Slices are views the parser refuses `indexing`; a recorded source-form boundary [0670] Structs the parser refuses `struct type`; a recorded source-form boundary the checker refuses `struct value`; a recorded source-form boundary [0680] Structs with a variant part the checker refuses `variant value`; a recorded source-form boundary [0720] Filling the remaining fields with `of` the parser refuses `struct all of`; a recorded source-form boundary [0820] Arenas are ordinary allocators you give storage to the parser refuses `arena block`; withdrawn the checker refuses `arena region`, spelled arena; withdrawn [0850] Volatile access sits outside the borrow rules the parser refuses `volatile reference`; withdrawn [1290] Writing a generic function the parser refuses `type parameter`; a recorded source-form boundary [1350] Generic types the checker refuses `parameterized type alias`; a recorded source-form boundary [1630] Inline assembly, for what has no builtin the checker refuses `float operand`; a recorded source-form boundary ## 5. Every diagnostic code What `refine` prints, and the rule behind it. `Retired` means the code is spent and never issued. Generated from the catalogue that owns them; nothing else writes a code. ``` L0001 Retired a source was read and no frontend is wired to the driver L0002 Live an option or argument the driver does not define L0003 Live a source that is missing or cannot be read L0004 Live a target no description names L0005 Live an output file that cannot be written L0006 Live [1420]: no ordered import root contains the requested module L0007 Live [1410], [1420]: a module directory is invalid or unreadable L0015 Live D267: an imported source namespace is unavailable for the target L0016 Live D275: a project root holds a module the compiler's library supplies instead L0017 Live D1357: the citations file names compiler sources other than the compiler's L0532 Live D563: an import's first directory holds no source and a later root holds its module L0616 Live D1055: an import selects the directory of a source the request named as the entry module L0008 Live D252: a source `refine fmt --check` finds out of the layout L0009 Live D255: a CPU feature level the selected target does not have L0010 Live [1830]: the tour describes this and the kernel omits it L0011 Live [1770]: an integer with missing digits, misplaced underscores, an invalid base digit, or an adjacent name L0012 Live [1750]/[1760]: a run of bytes no rule spells, or a word with a capital L0013 Live [1780]: a block comment that is never closed L0014 Live [0250]/[0260]/[0280]: a quoted or raw literal that is never closed L0100 Live [1760]: a name position holds something that is not a name L0101 Live [1790]: a type position holds no type the kernel enables L0102 Live [1820]: an expression was required and none begins here L0103 Live [1810]: a terminal the production spells is absent L0104 Live [1800]: a construct whose closing `end` never arrives L0105 Live [0390]: assignment is a statement, never an expression L0106 Live [1820]: comparison takes at most one operator L0107 Live [1810]: `return` carries no value; assign the named return L0108 Live [1740]: `public` rides on a declaration, not a statement L0109 Live [1800]: the name on `end` is not the name declared L0110 Live [1740]: a run of tokens beginning no declaration or statement L0111 Live an implementation limit on how deeply a construct nests L0112 Live [0980]: a positional call argument precedes every named argument L0200 Live [1850]: one scope gives one name to one thing L0201 Live [1860]: a name used and declared in no visible scope L0202 Live [1410]: a module-internal declaration used across modules L0203 Live [1560]: a builtin tool namespace binding or use is unavailable L0300 Live a compile-time magnitude its context or target does not hold L0398 Live [0740]: a known register image violates its reserved-bit write policy L0301 Live [1890]: a value's type is not the one its context or operation requires L0302 Live [1910], [0910], [0930]: a place unassigned at a read or exit L0303 Live [1900]: a place that may not be written L0304 Live [1830]: a known form used where the language does not permit it L0305 Live [1940]/D136/D202: a required static value or initial image that the compiler cannot establish before runtime L0306 Live [1950]: an operand the operation cannot take, where the compiler knows it L0324 Live [1510]: a compile-time assertion is false L0307 Live [1795]: a chain of aliases that reaches no type L0308 Live [0750]: a field a struct was not declared with L0309 Live [0670]/[0710]/D74/D76: each field is named at most once in a struct declaration or literal, or a variant case declaration or construction L0310 Live [0710]/D76: every field in a struct literal or variant case construction is named or covered by `of` L0311 Live [1210]: a match names each variant case at most once L0312 Live [1210]: an exhaustive match names every variant case L0313 Live D137: a nominal value layout cannot contain itself by value L0314 Live [0770]/[0780]: retention requires live storage and permission from the reference's origin L0315 Live [0800]/[0830]: a live derived view keeps its source still L0316 Live [0790]: a returned reference derives from exactly its declared source parameters L0317 Live a whole-program conformance key has two declarations L0318 Live a concrete type actual lacks the required concept conformance L0319 Live a user attempts to declare the compiler-owned concept or one of its supplied conformances L0320 Live [0270] [1750]: a text literal contains a malformed escape or invalid source encoding L0321 Live [0210] [0220] [0230] [1770]: a float has a complete fraction and exponent when required, and ends before a name L0322 Live [0250] [0270]: a character literal spells exactly one Unicode scalar value L0323 Live [0280] [1750]: raw content is UTF-8 and every nonblank line has the closing delimiter's indentation L0325 Live D247: an implementation limit on declarations in a routine or fields in a struct body or variant case L0390 Live [1530]/D202: an option must be unconditional, have an available name and use a supported scalar type L0391 Live [1510]/[1590]/D202: a tool directive needs one argument; linker.library needs a quoted portable library name L0326 Live D251: a local declared `mut` that nothing writes L0327 Live [1920]/D138: call arguments match the parameters and the callee's static formals L0328 Live [0540]: zeroed or an implicit initializer has no complete zero image L0329 Live [0940]/[0960]: failures obey the declared error set and call handling L0330 Live [1630]/[1990]: assembly operands, registers and template slots obey the block contract L0331 Live [1020]/[1930]/[0990]: a call's results are used, discarded or bound as the signature allows L0332 Live D1651/D124: a loop is a statement and a break carries no value; value-producing fallthroughs supply one L0333 Live [1210]/[0480]/[0640]: each match arm names a case of its subject in an admitted form L0334 Live [0700]/[0720]: struct, variant and array values are built and used in their admitted forms L0335 Live [0480]: a pointer union is matched before its pointer is read L0336 Live [0730]: a packed image is used through its fields and declared layout L0337 Live [0430]/[0900]/[0910]: an operation needing a distinct addressable place lacks one L0338 Live [1795]/[1350]: a type position or declaration is not well formed L0339 Live [0790]/[0980]/[0990]/D192: a written signature is not well formed L0340 Live D138: a generic call deduces and instantiates one concrete routine L0341 Live [1230]-[1270]: a concept or conformance declaration is not well formed L0342 Live [1370]-[1390]/D145-D147: an `any` value or dispatch outside its erased contract L0343 Live [0890]: a noreturn routine is infallible and never returns L0344 Live [1620]/D227: a memory intrinsic outside its explicit contract L0345 Live [1570]: an interrupt or naked routine outside its machine-entry contract L0346 Live [1580]: a C boundary signature, layout or variadic call the C ABI cannot carry L0347 Live [1610]/[1640]: a link symbol, helper import or placement outside its contract L0348 Live [1150]/D180: a for source is a range, a traversable value or one exact iterable conformance L0399 Live D542: a device description directive whose arguments are not the forms its row says L0513 Live D542/D543: a description directive outside one description, a repeated or missing one, or a second description L0514 Live D543: regions that overlap, or a placement, vector table or stack its regions cannot hold L0515 Live D543: a description whose core is not the request's target and level L0516 Retired retired: a reserved boot image kind refine did not build L0517 Live D547: a link(region: ...) the selected description cannot hold L0518 Live D543: firmware or a placement that needs a profile, with no description reached and none in the library L0533 Live D587: link(boot_stage) on anything but a naked routine with no other link attribute L0534 Live D587: a boot stage outside the device description the program selects L0535 Live D587: a boot stage in a description whose boot kind takes none L0536 Live D587: a second boot stage in one description L0537 Live D587: a description whose boot kind begins with a second stage, holding none L0545 Live D615: a float unit refine does not build, or one the description's core cannot have L0546 Live D615: a description with a float unit, built at a level whose architecture lacks it L0610 Live D971: a cache refine does not build, or one the description's core cannot have L0611 Live D971: a described cache whose line is not its core's L0560 Live D653: a vector-table description's stage that does not name compiler-owned reset L0561 Live D653: a vector-table description's stage that uses the stack L0576 Live D681: a boot image kind another family's boot ROM reads L0575 Live D683: an esp-app-image description without compiler.esp_image, or compiler.esp_image without an esp-app-image L0578 Live D688: a .ramtext routine in a profile whose data region code does not run in L0349 Live D251: an unused local with an effect-free literal initializer L0350 Live D760: an untyped float literal converted to an integer that its f32 rounding changes L0600 Live D949: compiler.utf8_unvalidated outside an unchecked region L0628 Live D1077: a bidirectional control character in a comment or a literal L0684 Live D1261: a call-site `else` that binds an error its block never reads L0692 Live D1342: a declaration that takes a predeclared type's name L0693 Live D1367: a body ends with a value after its named result was assigned L0500 Live [1550]: the requested output cannot be made with the target, settings or available toolchain L0501 Live [1550]: assembler or linker refusal, or executable output lifecycle failure L0502 Live [1970] [1990]: a missing or invalid hosted main or explicitly selected firmware entry L0503 Retired retired: the register-only internal calling limit L0504 Live a verified frame larger than the target's backend can address L0505 Live D537: static images exceed the image budget of the target or the firmware profile L0506 Live [1670]: invalid panic handler or unrepresentable site space L0507 Live [1990]: one firmware frame exceeds the selected stack reservation L0508 Live [1670]: a selected panic handler in a program that prepares a stack exceeds or cannot be measured against the target's stack margin L0509 Live [1590]/D525: a failed link's library that no named directory and none of the C driver's own holds L0519 Live D546: a linked firmware image that breaks a clause of the linker script contract L0538 Live D588: an assembled boot stage that outgrows its slot or that a relocation reaches L0555 Live D638: an assembled image block that is not the IMAGE_DEF block its boot kind gives, or that a relocation reaches L0577 Live D685: a linked image no ESP application image can hold, or one whose written bytes do not read back L0525 Live D555: an SVD that is not XML in the subset refine svd reads L0526 Live D556: a selection policy refine svd cannot read L0527 Live D556: an SVD that is not the one its policy was reviewed against L0528 Live D557: an SVD form refine svd does not read, for a selected register L0529 Live D557: a selected register the SVD describes in a way that cannot be generated as it says L0530 Live D556: a policy that selects what its SVD does not have L0531 Live D558: outputs refine svd will not replace L0579 Live D820: a binding policy refine bindings cannot read L0580 Live D820: a Clang that cannot be run as asked, fails, or describes another ABI L0581 Live D820: a selected C declaration, or its policy, that cannot be bound L0582 Live D820: outputs refine bindings will not replace L0587 Live D924: a firmware image whose C archives bring constructors, thread-local storage or a dynamic linkage L0688 Live D1292: a source table refine site cannot read L0689 Live D1292: a build that is not the one its source table was written with L0690 Live D1292: a site or a caller's file the table does not hold L0694 Live D1384: a split command refine was built with that its installation lacks L0695 Live D1387: an external command whose description refine cannot accept L0696 Live D1847: the language removed this form, and the refusal names the one that replaces it L0697 Live D2175: an atom set names one member twice ``` ## 6. What follows `tour.md` teaches the language, construct by numbered construct. `spec.md` decides it: the grammar above, the rules the tour leaves unsaid, and a register of every decision with the alternative it was chosen over and the fixture that pins it. `examples.md` holds complete programs that print what they compute, which the gate runs. Where the tour and the specification could be read differently, the specification decides.