Finch/bootstrap
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Nexoniarz dc0334fa0e Programs built by the Finch compiler free their memory
gen.fch never dropped anything (it was the bootstrap compiler); now it does what the C++ one did: owned variables are
dropped when their scope ends (defers interleaved, newest first), return moves a local out, assignments drop the old
value, temporaries nobody keeps are released, values an expression holds are dropped when try/or leave early,
clear/resize/remove/map.clear drop what goes, free() drops the pointee. The compiler itself now frees as it goes.

MEMCHECK=1 tests/run.sh: 108 passed under valgrind with --leak-check=full.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015f73FesGZGYPkmDvUcj6QX
2026-10-25 22:45:39 +01:00
..
build.sh The compiler carries its runtime and std inside itself; host module for the system it runs on 2026-10-25 22:32:02 +01:00
install.sh Install, CI, seeds and docs for the compiler written in Finch 2026-10-25 21:53:50 +01:00
linux-aarch64.ll Programs built by the Finch compiler free their memory 2026-10-25 22:45:39 +01:00
linux-x86_64.ll Programs built by the Finch compiler free their memory 2026-10-25 22:45:39 +01:00
pack.sh The compiler carries its runtime and std inside itself; host module for the system it runs on 2026-10-25 22:32:02 +01:00
README.md Install, CI, seeds and docs for the compiler written in Finch 2026-10-25 21:53:50 +01:00

The seed

Finch's compiler is written in Finch. To build it you need something that already runs Finch: the seed, which is the compiler's own LLVM IR, one file per system:

File System Checked
linux-x86_64.ll Linux x86-64 built and tested here and in CI
linux-aarch64.ll Linux ARM64 made with the ARM64 cross compiler; CI builds and tests it on an ARM64 runner

bootstrap/build.sh compiles the seed with clang (and the runtime, and libclang) into build/finch0; finch0 builds src/ into finch1; finch1 builds src/ again into build/finch; the two must make the same IR, or the script stops.

Why one per system

The seed includes how this system's C compiler passes structs by value, because the compiler calls libclang with CXCursor, CXType and CXString (the calling convention is different on x86-64, on ARM64 and on Windows). So a seed made for one system doesn't run on another, and a seed needs the target system's C headers to be made.

When to make a new one

When the compiler's own source starts to use a feature that the committed seed doesn't have, build.sh fails at the first step. Make the seed from a working compiler:

bootstrap/build.sh seed            # writes bootstrap/<this system>.ll

For another system, from a machine that has that system's headers and a cross compiler (what tests/cross.sh uses):

FINCH_CC=aarch64-linux-gnu-gcc build/finch ir src/main.fch --target arm64 > bootstrap/linux-aarch64.ll

macOS and Windows

There is no seed for them yet: it needs Apple's or Microsoft's headers, which can't be had on Linux. Until there is one, programs for macOS and Windows are built from Linux with --target macos|windows, and the compiler's older C++ version (branch before-bootstrap) is the way to get a compiler that runs there.