Working on the Compiler

This page is for anyone working on the compiler itself: where things are in the repository, and how to test a change. What each step of the compiler does, and how, is its own section - The Compiler, a page per step. This page describes the implementation in this repository, which is still being built - the rest of these docs describe the language it's growing into.

Layout

The compiler is written in TypeScript and runs on Bun. Its stages are folders numbered in the order they run, and each reads what the one before produced.

The TypeScript compiler's steps, in src/, are numbered in the order they run; so are the bootstrapping compiler's, in bootstrapping/ - its folders are the steps on The Compiler, one page each. Each stage adds its findings, and errors, warnings and notes collect on the file they're about; src/index.ts gathers them into the report described on Command Line, and runs nothing when there are errors.

Builtins

src/builtins holds the tables the stages share: the builtin operators and their precedences, the builtin functions and types, the intrinsics, the context components, and the reserved macro namespaces. The docs' reference pages list the same things, and a test checks the two agree - see Working on the docs.

Bootstrapping

bootstrapping/ is the compiler again, written in Refingere, so the language can eventually compile itself. It's compiled and run by the TypeScript compiler: bun run bootstrap:run -- --help lists what it can do, and bun run bootstrap:test runs its @test functions - add --target=js to either for the JavaScript backend, and keep both passing. bun run bootstrap:run -- --check bootstrapping checks its own sources, which should report no errors. Its builtins are bootstrapping/4-typecheck/core.rfn, generated from core.md by bun run bootstrap:core. Each of its steps is described in The Compiler.

Testing a change

The compiler's tests are next to the code they test, as *.test.ts files run by bun test. examples/ holds small programs that every test run parses, analyses and tests, so a change that breaks a real program fails there.

Working on the docs

The site in docs/ is a Vue app. The guide pages under docs/src/views/docs are written by hand, and listed in docs/src/views/docs/sections.ts, which builds the sidebar. The reference pages are generated from docs/src/core.md, the source of truth for types, methods, context values, macros, attributes and operators, and from docs/src/implementations.md, the builtin members written in Refingere.

src/builtins/docsSync.test.ts checks that the reference agrees with the compiler: every builtin function and operator in the compiler has a card and every card a builtin, unless it's marked as planned. It also checks that attribute and embedded-language examples parse, and that every link in the Keyword Index lands on a card. Adding a builtin without documenting it fails the tests.