interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / seed / omc / gate17.sh

84 lines · 3397 bytes Raw Blame History
1#!/bin/sh
2# gate17.sh -- differential fuzz against the pinned reference compiler. The reference is built from the
3# in-tree pinned source (seed/omc/pinned.om, the R5 compiler) with the seed-owned om4, and its digest is
4# asserted. 300 deterministic structured programs (old subset: scalars, arrays, if/while/for, arithmetic)
5# are compiled by both compilers; each must be accepted and produce byte-identical machine code.
6set -eu
7R=$(CDPATH= cd -- "$(dirname "$0")/../.." && pwd)
8cd "$R"
9O=seed/out/omc
10[ -x "$O" ] || { printf 'FAIL: %s missing; run sh seed/omega-from-seed.sh first\n' "$O" >&2; exit 1; }
11P=seed/rung4/om4.bin
12[ -x "$P" ] || { printf 'FAIL: %s missing\n' "$P" >&2; exit 1; }
13mkdir -p build/seed/r17
14T=$(mktemp -d build/seed/r17/diff.XXXXXX)
15trap 'rm -rf "$T"' EXIT HUP INT TERM
16bad() { printf 'FAIL: %s\n' "$*" >&2; exit 1; }
17say() { printf '%s\n' "$*"; }
18
19"$P" < seed/omc/pinned.om > "$T/pinned"
20chmod +x "$T/pinned"
21sha=$(sha256sum "$T/pinned" | cut -d' ' -f1)
22[ "$sha" = e5d60db892c8f21cc8c9128af26d8bded0e96d7f92946f5a549397c43a872649 ] || \
23 bad "pinned compiler digest $sha, wanted e5d60db8..."
24say "PASS pinned reference compiler e5d60db8..."
25
26awk -v dir="$T" 'BEGIN{
27 M = 65536;
28 for (p = 0; p < 300; p++) {
29 seed = 777 + p * 13;
30 f = sprintf("%s/p%03d.om", dir, p);
31 print "fn main to int" > f;
32 print "a = new ulong 4 0" > f;
33 print "x = ulong 1" > f;
34 print "y = ulong 2" > f;
35 depth = 0;
36 for (l = 0; l < 24; l++) {
37 seed = (seed * 25173 + 13849) % M;
38 r = seed / M;
39 if (r < 0.60 || depth == 0) {
40 seed = (seed * 25173 + 13849) % M;
41 k = seed % 8;
42 if (k == 0) print "x = add x 1" > f;
43 else if (k == 1) print "y = mul y 2" > f;
44 else if (k == 2) print "x = add x y" > f;
45 else if (k == 3) print "put a 0 x" > f;
46 else if (k == 4) print "x = get a 1" > f;
47 else if (k == 5) print "x = sub x 1" > f;
48 else if (k == 6) print "y = xor y 1" > f;
49 else print "x = rem x 7" > f;
50 } else if (r < 0.80 && depth < 4) {
51 print "if lt x 100" > f; depth++;
52 } else if (r < 0.90 && depth < 4) {
53 print "while lt x 100 bound 1000" > f; depth++;
54 } else if (r < 0.95 && depth < 4) {
55 print "for i ulong 4" > f; depth++;
56 } else if (depth > 0) {
57 print "end" > f; depth--;
58 }
59 }
60 while (depth > 0) { print "end" > f; depth--; }
61 print "ret int x" > f;
62 print "end" > f;
63 close(f);
64 }
65}'
66
67n=0
68for f in "$T"/p*.om; do
69 n=$((n + 1))
70 set +e
71 "$O" < "$f" > "$T/a.bin" 2> "$T/a.err"
72 ra=$?
73 "$T/pinned" < "$f" > "$T/p.bin" 2> "$T/p.err"
74 rp=$?
75 set -e
76 [ "$ra" = 0 ] || bad "$f: current compiler exit $ra ($(cat "$T/a.err"))"
77 [ "$rp" = 0 ] || bad "$f: pinned compiler exit $rp ($(cat "$T/p.err"))"
78 [ -s "$T/a.err" ] && bad "$f: current compiler wrote a diagnostic"
79 [ -s "$T/p.err" ] && bad "$f: pinned compiler wrote a diagnostic"
80 cmp -s "$T/a.bin" "$T/p.bin" || bad "$f: machine code differs from the pinned compiler"
81done
82[ "$n" = 300 ] || bad "ran $n of 300 programs"
83say "PASS gate17 300 programs byte-identical to the pinned compiler"
84exit 0