aboutsummaryrefslogtreecommitdiff
path: root/docs/history/13-gap-fixes/code/test.sh
diff options
context:
space:
mode:
Diffstat (limited to 'docs/history/13-gap-fixes/code/test.sh')
-rwxr-xr-xdocs/history/13-gap-fixes/code/test.sh71
1 files changed, 71 insertions, 0 deletions
diff --git a/docs/history/13-gap-fixes/code/test.sh b/docs/history/13-gap-fixes/code/test.sh
new file mode 100755
index 0000000..e28182d
--- /dev/null
+++ b/docs/history/13-gap-fixes/code/test.sh
@@ -0,0 +1,71 @@
+#!/bin/bash
+# full check: bootstraps the compiler from zc0, verifies the fixpoint, then runs
+# the examples and tests on the portable interpreter (host), the arm64 jit under
+# qemu, and the llvm backend. needs gcc; the jit half needs aarch64-linux-gnu-gcc
+# and qemu-aarch64, the llvm half needs llvm-config and libLLVM (each is skipped
+# if missing).
+cd "$(dirname "$0")"; T=$(mktemp -d); trap 'rm -rf $T' EXIT
+ok=0; bad=0
+chk(){ if [ "$1" = "$2" ]; then echo "ok $3"; ok=$((ok+1)); else echo "FAIL $3: got [$1]"; bad=$((bad+1)); fi; }
+src(){ cat src/rt.zc src/compiler.zc; }
+selfc(){ (cat tools/build.zc; printf '`'; src) | $1 > $2; }
+
+# bootstrap: zc0 (c) -> g0, g0 compiles compiler.zc -> g1, g1 compiles it -> g2
+gcc -O1 -w zc0.c -o $T/zc0 && gcc -O1 -w mkgenome.c -o $T/mkg || exit 1
+mkdir $T/s0 $T/s1
+cp core.c io_linux.c $T/s0/; cp core.c io_linux.c $T/s1/
+src | $T/zc0 > $T/s0/genome.h || exit 1
+gcc -O2 -w -DJTYPE=int $T/s0/core.c $T/s0/io_linux.c -o $T/zy0
+selfc $T/zy0 $T/g1.bin; $T/mkg < $T/g1.bin > $T/s1/genome.h
+gcc -O2 -w -DJTYPE=int $T/s1/core.c $T/s1/io_linux.c -o $T/zy1
+selfc $T/zy1 $T/g2.bin
+cmp -s $T/g1.bin $T/g2.bin && chk 1 1 "fixpoint: the compiler compiles itself to the same $(($(stat -c %s $T/g1.bin) / 4)) words" || chk 0 1 "fixpoint"
+cmp -s $T/s1/genome.h genome.h && chk 1 1 "genome.h is up to date" || chk 0 1 "genome.h is stale (cp the bootstrap output over it)"
+
+run(){ # $1 = vm command, $2 = label
+ local vm="$1" l="$2"
+ chk "$($vm < examples/hello.zc)" "hello, world!" "$l hello"
+ chk "$($vm < examples/fact.zc | tr '\n' '/')" "1101110101111100000000/3628800/" "$l factorial"
+ chk "$( (cat examples/echo.zc; printf '`abc\n') | $vm)" "abc" "$l echo after the backtick"
+ chk "$($vm < examples/selfpatch.zc)" "ABC" "$l self-patching code"
+ chk "$($vm < examples/lists.zc | tr '\n' '/')" "[0 1 4 9 16 25]/live: 7/after the block: 0/" "$l ownership frees everything"
+ chk "$( (cat examples/repl.zc; printf '`fn sq(x) { return x * x; }`putn(sq(7)); putc(10);`puts("hi\\n");') | $vm | tr '\n' '/')" "49/hi/" "$l repl on the resident compiler"
+ chk "$($vm < examples/typed.zc | tr '\n' '/')" "last: 4/point is 2 words: x int, y int/vec<*point> is 3 words: len int, cap int, items **point/push is fn(*vec<T>, T.d) -> bool/the heap says v is a vec<T>, and v.items[0] is a point/" "$l typed example"
+ chk "$($vm < examples/wiring.zc)" "16 1234 25 4/9" "$l enhancement example"
+ chk "$($vm < tests/basics.zc | tr '\n' '/')" "285 610 42 512/hey 65 -3 -2 1024 -8/12456/757/9 100-101/5/ok/" "$l language basics"
+ chk "$($vm < tests/umd.zc)" "100 6 0 15 99 5 5" "$l u m d lifetimes"
+ chk "$($vm < tests/gc.zc)" "1000 1 900 1 199900" "$l mark-sweep collector"
+ chk "$($vm < tests/meta.zc | tr '\n' '/')" "1024 19/unless ok/rrr/15 42/7/42/7/144/" "$l parse words, quote, eval, load, operator tables"
+ chk "$($vm < tests/misc.zc | tr '\n' '/')" "45/54321/ok/" "$l compile-time eval, patched mnemonics, unchecked"
+ chk "$($vm < tests/types.zc | tr '\n' '/')" "12 5 2 15 56 42 7 14 3/rect *rect *list<int> fn(int) -> *list<T>.u fn(*list<T>) -> T fn(word.d)/a:point@0 b:point@2 tag:int@4 /point 1 1/" "$l types, generics, reflection"
+ chk "$($vm < tests/typeok.zc)" "14" "$l a program the typechecker accepts"
+ chk "$($vm < tests/typeoff.zc)" "6" "$l the typechecker is off by default"
+ chk "$($vm < tests/enhance.zc)" "100 0 343 3,2 5 -2 0" "$l virtual enhancements"
+ chk "$($vm < tests/joins.zc)" "0 0 5 80 8 3 9 0" "$l joins free what one path gave away; switch, ?:, no prototypes"
+ chk "$($vm < tests/buddy.zc)" "131072 262144 1 0" "$l buddy allocator merges freed blocks"
+ chk "$($vm < tests/borrowmove.zc)" "6" "$l storing into a borrowed object moves it"
+ chk "$($vm < tests/manyerrors.zc | tr '\n' '/')" "zc: line 3: expected an expression/zc: line 4: x: m object is never used/zc: line 5: type error: initializer: expected *char, got int/zc: line 6: expected ;/zc: 4 errors/" "$l several errors in one run"
+ chk "$($vm < tests/overflow_return.zc 2>&1)" "zy: return stack overflow" "$l return stack overflow is caught"
+ chk "$($vm < tests/overflow_data.zc 2>&1)" "zy: data stack overflow" "$l data stack overflow is caught"
+ chk "$($vm < tests/overflow_frame.zc 2>&1)" "zy: frame stack overflow" "$l frame stack overflow is caught"
+ local r; r=$(tests/runerr.sh "$vm" tests/errors | tail -1)
+ chk "$r" "rejected: $(ls tests/errors/*.zc | wc -l) passed, 0 failed" "$l analyzer rejects every bad program"
+ r=$(tests/runerr.sh "$vm" tests/typeerrors | tail -1)
+ chk "$r" "rejected: $(ls tests/typeerrors/*.zc | wc -l) passed, 0 failed" "$l typechecker rejects every bad program"
+}
+gcc -O2 -w -DJTYPE=int core.c io_linux.c -o $T/zy
+run $T/zy "interp"
+if command -v aarch64-linux-gnu-gcc >/dev/null && command -v qemu-aarch64 >/dev/null; then
+ aarch64-linux-gnu-gcc -O2 -w -DJTYPE=int -static core.c io_linux.c -o $T/zyj || exit 1
+ printf '#!/bin/sh\nexec qemu-aarch64 %s "$@"\n' $T/zyj > $T/jit; chmod +x $T/jit
+ run $T/jit "jit"
+ selfc $T/jit $T/gj.bin; cmp -s $T/g1.bin $T/gj.bin && chk 1 1 "jit self-compile matches" || chk 0 1 "jit self-compile matches"
+else echo "skip jit (no aarch64 toolchain or qemu)"; fi
+if command -v llvm-config >/dev/null; then
+ gcc -O2 -w -DJTYPE=int -DZYLLVM $(llvm-config --cflags) core.c io_linux.c -o $T/zyl $(llvm-config --ldflags --libs) || exit 1
+ run $T/zyl "llvm"
+ printf '#!/bin/sh\nZYHOT=1 exec %s "$@"\n' $T/zyl > $T/llall; chmod +x $T/llall
+ chk "$($T/llall < tests/types.zc | md5sum)" "$($T/zy < tests/types.zc | md5sum)" "llvm compiling every block agrees"
+ selfc $T/zyl $T/gl.bin; cmp -s $T/g1.bin $T/gl.bin && chk 1 1 "llvm self-compile matches" || chk 0 1 "llvm self-compile matches"
+else echo "skip llvm (no llvm-config)"; fi
+echo "$ok passed, $bad failed"; [ $bad = 0 ]