#!/bin/bash # builds the zygote for arm64 linux and runs it under qemu. # needs gcc, aarch64-linux-gnu-gcc and qemu-aarch64. on an arm64 mac or linux box, # build natively instead and drop the qemu prefix. cd "$(dirname "$0")"; T=$(mktemp -d); Q="timeout 60 qemu-aarch64" chk(){ if [ "$1" = "$2" ]; then echo "ok $3"; else echo "FAIL $3: got [$1]"; fi; } gcc -w mkgenome.c -o $T/mkg && cat gen.s aslib.s | $T/mkg >$T/g.h cmp -s $T/g.h genome.h && echo "ok genome.h is up to date" || echo "FAIL genome.h is stale, regenerate it" aarch64-linux-gnu-gcc -O2 -w -DJTYPE=int -static core.c io_linux.c -o $T/zy || exit 1 chk "$($Q $T/zy $T/asm.s (cat $T/asm.s; printf '`'; cat examples/hello.s) | $Q $T/zy >$T/a chk "$(od -An -td4 $T/a | tr -s ' \n' ' ' | sed 's/^ //;s/ $//')" "29 1 6 2 1 6 27 16 24 3 26 3 14 0 104 101 108 108 111 44 32 119 111 114 108 100 33 10 0" "self-hosted assembler, running on the zygote, assembles hello" chk "$( (cat repl.s; printf '`104 p 105 p 10 p r`121 p 111 p 10 p r') | $Q $T/zy | tr '\n' '/')" "hi/yo/" "repl with mutated assembler" rm -rf $T