The compiler is written in Finch, and nothing else: src/*.fch, built from a seed

boot/ is src/ now. The C++ compiler and CMake are gone from this branch (they are on before-bootstrap).
bootstrap/build.sh builds the compiler from bootstrap/<system>.ll -- the compiler's own LLVM IR -- then builds
it with itself and checks the two come out identical. bootstrap/build.sh seed writes the seed anew.

The driver is complete: the runtime is compiled once and kept in ~/.cache/finch; a program's own C files,
.o and .a files and frameworks link along; a linker failure is read and answered with  link "lib"  or the
library that is missing. The old tests/fail diagnostics are all in again (a missing import, a str compared with
null, 'write just the library's name', a map key that is a float, non-ASCII names, ...).

tests/run.sh is the one test runner: programs, refusals, -g builds and the shared library. 106 passed.
This commit is contained in:
Nexoniarz 2026-10-25 21:42:17 +01:00
commit b9378050ab
39 changed files with 80403 additions and 7251 deletions

49
bootstrap/build.sh Executable file
View file

@ -0,0 +1,49 @@
#!/bin/sh
# Builds the Finch compiler without a compiler for Finch: from the seed (the compiler's own LLVM IR),
# then from itself, and checks that the two come out the same.
#
# bootstrap/build.sh build/finch
# bootstrap/build.sh seed also write bootstrap/<system>.ll anew (do this when the compiler got a feature
# its own source uses, or the seed is old: the next build starts from it)
#
# Needs clang and libclang (the C headers are read through it). The compiler is then in build/finch; it looks for the
# runtime and the standard library next to build/, in runtime/ and std/.
set -eu
cd "$(dirname "$0")/.."
mkdir -p build
case "$(uname -s)-$(uname -m)" in
Linux-x86_64) seed=linux-x86_64 ;;
Linux-aarch64|Linux-arm64) seed=linux-aarch64 ;;
Darwin-arm64) seed=macos-arm64 ;;
Darwin-x86_64) seed=macos-x86_64 ;;
MINGW*|MSYS*|CYGWIN*) seed=windows-x86_64 ;;
*) echo "bootstrap: no seed for $(uname -s) $(uname -m) (see bootstrap/README.md)" >&2; exit 1 ;;
esac
[ -f "bootstrap/$seed.ll" ] || { echo "bootstrap: bootstrap/$seed.ll is missing" >&2; exit 1; }
CLANG=${FINCH_CLANG:-clang}
LIBS=${FINCH_LIBCLANG:--lclang}
export FINCH_RT=$PWD/runtime/finch_rt.c
echo "bootstrap: seed ($seed) -> build/finch0"
$CLANG -O1 -w "bootstrap/$seed.ll" runtime/finch_rt.c -o build/finch0 -lm $LIBS
echo "bootstrap: build/finch0 builds the compiler -> build/finch1"
build/finch0 build src/main.fch -o build/finch1
echo "bootstrap: build/finch1 builds the compiler -> build/finch"
build/finch1 build src/main.fch -o build/finch
# a compiler that builds itself must come out the same however many times it does
build/finch1 ir src/main.fch > build/stage1.ll
build/finch ir src/main.fch > build/stage2.ll
if cmp -s build/stage1.ll build/stage2.ll; then
echo "bootstrap: build/finch1 and build/finch make the same IR ($(wc -l < build/stage2.ll) lines): done"
else
echo "bootstrap: the compiler does not reproduce itself (build/stage1.ll and build/stage2.ll differ)" >&2
exit 1
fi
if [ "${1:-}" = seed ]; then
cp build/stage2.ll "bootstrap/$seed.ll"
echo "bootstrap: wrote bootstrap/$seed.ll"
fi

79936
bootstrap/linux-x86_64.ll Normal file

File diff suppressed because it is too large Load diff