mirror of
https://github.com/Nexoniarz/Finch.git
synced 2026-11-03 00:44:27 +00:00
The self-hosted compiler now has the numeric types the C++ one has: int and float stay the i64 and f64 defaults, the others lower to their LLVM sizes; literals adapt to the other operand if they fit, smaller types widen into bigger ones, signed and unsigned mixing is refused, division and shifts and comparisons pick their signedness, and u8(x), f32(x), bool(x) convert. boot.sh: 11 passed, 0 failed, 10 skipped (was 9 / 12).
50 lines
1.9 KiB
Shell
Executable file
50 lines
1.9 KiB
Shell
Executable file
#!/usr/bin/env bash
|
|
# The self-hosted compiler (boot/) must
|
|
# 1. build itself: stage1 (built by build/finch) -> stage2 -> stage3, with identical IR
|
|
# 2. give the same output as build/finch on every test in tests/run it supports
|
|
set -u
|
|
cd "$(dirname "$0")/.."
|
|
tmp=$(mktemp -d)
|
|
trap 'rm -rf "$tmp"' EXIT
|
|
|
|
build/finch build boot/main.fch -o "$tmp/boot1" || exit 1
|
|
"$tmp/boot1" build boot/main.fch -o "$tmp/boot2" || exit 1
|
|
"$tmp/boot1" ir boot/main.fch > "$tmp/stage2.ll"
|
|
"$tmp/boot2" ir boot/main.fch > "$tmp/stage3.ll"
|
|
if cmp -s "$tmp/stage2.ll" "$tmp/stage3.ll"; then
|
|
echo "bootstrap: stage 2 and stage 3 are identical ($(wc -l < "$tmp/stage3.ll") lines of IR)"
|
|
else
|
|
echo "bootstrap: FAILED, stage 2 and stage 3 differ"
|
|
exit 1
|
|
fi
|
|
|
|
pass=0; failed=0; skipped=0
|
|
for f in tests/run/*.fch; do
|
|
grep -q "^fn main" "$f" || continue
|
|
# the bootstrap compiler doesn't do C imports, defer, maps, methods or errors as values
|
|
# (checked in the test and in the modules it imports)
|
|
files="$f"
|
|
for m in $(sed -n 's/^import \([a-z_]*\)$/\1/p' "$f"); do files="$files tests/run/$m.fch"; done
|
|
if grep -qE '^import "|^link |defer | or |try |map\[|!\s*\{|^fn [A-Z][A-Za-z0-9_]*\.|for [a-z_]+, ' $files; then
|
|
skipped=$((skipped + 1))
|
|
continue
|
|
fi
|
|
input="${f%.fch}.in"
|
|
[ -f "$input" ] || input=/dev/null
|
|
if ! "$tmp/boot2" build "$f" -o "$tmp/prog" > "$tmp/err" 2>&1; then
|
|
failed=$((failed + 1))
|
|
echo "FAIL (compile) $f"
|
|
head -3 "$tmp/err"
|
|
continue
|
|
fi
|
|
got=$("$tmp/prog" < "$input" 2>&1)
|
|
if [ "$got" == "$(cat "${f%.fch}.out")" ]; then
|
|
pass=$((pass + 1))
|
|
else
|
|
failed=$((failed + 1))
|
|
echo "FAIL (output) $f"
|
|
diff <(echo "$got") "${f%.fch}.out" | head -10
|
|
fi
|
|
done
|
|
echo "self-hosted compiler: $pass passed, $failed failed, $skipped skipped (features it doesn't have)"
|
|
[ $failed -eq 0 ]
|