Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/seed/omc/gate13.sh # 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 Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / seed / omc / gate13.sh` 131 lines ยท 4389 bytes Raw Blame History 1 #!/bin/sh 2 # gate13.sh -- compiler robustness. Two deterministic generators (embedded LCG, no rand()): 3 # soup : 300 token streams from the language vocabulary plus garbage; every run must refuse with 4 # a documented error code (0..23), never crash, trap or time out. 5 # valid : 300 structured, balanced programs; every one must compile, and twice to identical bytes. 6 # RC=0 only when every case passed. 7 set -eu 8 R=$(CDPATH= cd -- "$(dirname "$0")/../.." && pwd) 9 cd "$R" 10 S=seed/out/omc 11 [ -x "$S" ] || { printf 'FAIL: %s missing; run sh seed/omega-from-seed.sh first\n' "$S" >&2; exit 1; } 12 mkdir -p build/seed/r13 13 T=$(mktemp -d build/seed/r13/fuzz.XXXXXX) 14 trap 'rm -rf "$T"' EXIT HUP INT TERM 15 bad() { printf 'FAIL: %s\n' "$*" >&2; exit 1; } 16 say() { printf '%s\n' "$*"; } 17 18 cat > "$T/soup.awk" <<'AWK' 19 BEGIN{ 20 seed = 12345; 21 n = split("fn main to int ulong uchar if else end while bound for ret put get new view edit struct text global note x y a b i n m = + - mul add sub div rem and or shl shr eq ne lt le gt ge neg not sizeof offsetof break trap continue random envcnt envread chdir ( ) junk own free", T, " "); 22 for (p = 0; p < 300; p++) { 23 f = sprintf("%s/s%04d.om", dir, p); 24 printf "" > f; 25 seed = (seed * 25173 + 13849) % 65536; 26 if (seed % 2 == 0) print "fn main to int" > f; 27 seed = (seed * 25173 + 13849) % 65536; 28 lines = 4 + (seed % 24); 29 for (l = 0; l < lines; l++) { 30 seed = (seed * 25173 + 13849) % 65536; 31 k = 1 + (seed % 6); 32 line = ""; 33 for (j = 0; j < k; j++) { 34 seed = (seed * 25173 + 13849) % 65536; 35 idx = 1 + (seed % n); 36 if (j > 0) line = line " "; 37 line = line T[idx]; 38 } 39 print line > f; 40 } 41 seed = (seed * 25173 + 13849) % 65536; 42 if (seed % 2 == 0) print "end" > f; 43 close(f); 44 } 45 } 46 AWK 47 48 cat > "$T/valid.awk" <<'AWK' 49 BEGIN{ 50 for (p = 0; p < 300; p++) { 51 seed = 777 + p * 13; 52 f = sprintf("%s/v%04d.om", dir, p); 53 print "fn main to int" > f; 54 print "a = new ulong 4 0" > f; 55 print "x = ulong 1" > f; 56 print "y = ulong 2" > f; 57 depth = 0; 58 for (l = 0; l < 24; l++) { 59 seed = (seed * 25173 + 13849) % 65536; 60 r = seed / 65536; 61 if (r < 0.60 || depth == 0) { 62 seed = (seed * 25173 + 13849) % 65536; 63 k = seed % 8; 64 if (k == 0) print "x = add x 1" > f; 65 else if (k == 1) print "y = mul y 2" > f; 66 else if (k == 2) print "x = add x y" > f; 67 else if (k == 3) print "put a 0 x" > f; 68 else if (k == 4) print "x = get a 1" > f; 69 else if (k == 5) print "x = sub x 1" > f; 70 else if (k == 6) print "y = xor y 1" > f; 71 else print "x = rem x 7" > f; 72 } else if (r < 0.80 && depth < 4) { 73 print "if lt x 100" > f; depth++; 74 } else if (r < 0.90 && depth < 4) { 75 print "while lt x 100 bound 1000" > f; depth++; 76 } else if (r < 0.95 && depth < 4) { 77 print "for i ulong 4" > f; depth++; 78 } else if (depth > 0) { 79 print "end" > f; depth--; 80 } 81 } 82 while (depth > 0) { print "end" > f; depth--; } 83 print "ret int x" > f; 84 print "end" > f; 85 close(f); 86 } 87 } 88 AWK 89 90 awk -v dir="$T" -f "$T/soup.awk" 91 awk -v dir="$T" -f "$T/valid.awk" 92 93 ok=0 94 n=0 95 for f in "$T"/s*.om; do 96 n=$((n+1)) 97 set +e 98 timeout 10 "$S" < "$f" > "$T/o1" 2> "$T/e1" 99 r1=$? 100 timeout 10 "$S" < "$f" > "$T/o2" 2> "$T/e2" 101 r2=$? 102 set -e 103 [ "$r1" = "$r2" ] || bad "soup $f: exit $r1 then $r2" 104 cmp -s "$T/o1" "$T/o2" || bad "soup $f: output differs between runs" 105 cmp -s "$T/e1" "$T/e2" || bad "soup $f: diagnostic differs between runs" 106 [ "$r1" -ge 0 ] && [ "$r1" -le 23 ] || bad "soup $f: exit $r1 outside 0..23" 107 ok=$((ok+1)) 108 done 109 [ "$ok" = 300 ] || bad "soup: ran $ok of 300" 110 say "PASS 300 token-stream programs: 0..23, deterministic, no crash or timeout" 111 112 ok=0 113 n=0 114 for f in "$T"/v*.om; do 115 n=$((n+1)) 116 set +e 117 timeout 10 "$S" < "$f" > "$T/o1" 2> "$T/e1" 118 r1=$? 119 timeout 10 "$S" < "$f" > "$T/o2" 2> "$T/e2" 120 r2=$? 121 set -e 122 [ "$r1" = 0 ] || bad "valid $f: exit $r1 ($(head -1 "$T/e1"))" 123 cmp -s "$T/o1" "$T/o2" || bad "valid $f: bytes differ between runs" 124 [ -s "$T/o1" ] || bad "valid $f: empty output" 125 ok=$((ok+1)) 126 done 127 [ "$ok" = 300 ] || bad "valid: ran $ok of 300" 128 say "PASS 300 structured programs: compiled, byte-identical twice" 129 130 say "PASS gate13 600 programs" 131 exit 0