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
omega-mv / seed / omc / gate6.sh
| 1 | #!/bin/sh |
| 2 | # gate6.sh -- R6 structs. The compiler under test is omc built by om4, then by itself. |
| 3 | # Struct programs are not readable by om4 (it has no struct word). Results are exit |
| 4 | # statuses worked out in Wolfram (evidence/SEED-0/r6-structs/wolfram.txt), not copied |
| 5 | # from this compiler. RC=0 only when every case below ran and passed. |
| 6 | set -eu |
| 7 | R=$(CDPATH= cd -- "$(dirname "$0")/../.." && pwd) |
| 8 | cd "$R" |
| 9 | B=build/seed/r6 |
| 10 | T=seed/omc/tests/struct |
| 11 | mkdir -p "$B" |
| 12 | OM4=seed/rung4/om4.bin |
| 13 | bad() { printf 'FAIL: %s\n' "$*" >&2; exit 1; } |
| 14 | say() { printf '%s\n' "$*"; } |
| 15 | |
| 16 | "$OM4" < seed/omc/omc.om > "$B/stage1" 2>"$B/stage1.err" || bad "om4 refused omc.om ($(cat "$B/stage1.err"))" |
| 17 | chmod +x "$B/stage1" |
| 18 | "$B/stage1" < seed/omc/omc.om > "$B/stage2" 2>"$B/stage2.err" || bad "stage1 refused omc.om ($(cat "$B/stage2.err"))" |
| 19 | chmod +x "$B/stage2" |
| 20 | "$B/stage2" < seed/omc/omc.om > "$B/stage3" 2>"$B/stage3.err" || bad "stage2 refused omc.om ($(cat "$B/stage3.err"))" |
| 21 | chmod +x "$B/stage3" |
| 22 | s1=$(sha256sum "$B/stage1" | cut -d' ' -f1) |
| 23 | s2=$(sha256sum "$B/stage2" | cut -d' ' -f1) |
| 24 | s3=$(sha256sum "$B/stage3" | cut -d' ' -f1) |
| 25 | [ "$s1" = "$s2" ] || bad "parents differ: om4 $s1 != omc $s2" |
| 26 | [ "$s2" = "$s3" ] || bad "fixpoint: stage2 $s2 != stage3 $s3" |
| 27 | say "PASS fixpoint $s3" |
| 28 | S=$B/stage3 |
| 29 | cp "$S" seed/out/omc |
| 30 | printf '%s seed/out/omc\n' "$s3" > seed/out/omc.sha256 |
| 31 | |
| 32 | # om4 must still refuse a struct program (it has no such word). |
| 33 | set +e |
| 34 | "$OM4" < "$T/t1.om" > "$B/om4-t1.bin" 2>"$B/om4-t1.err" |
| 35 | orc=$? |
| 36 | set -e |
| 37 | [ "$orc" != 0 ] || bad "om4 accepted a struct program" |
| 38 | say "PASS om4 refuses struct (exit $orc)" |
| 39 | |
| 40 | n=0 |
| 41 | ok=0 |
| 42 | run_exit() { # name file expect |
| 43 | n=$((n+1)) |
| 44 | set +e |
| 45 | "$S" < "$2" > "$B/$1.bin" 2>"$B/$1.err" |
| 46 | crc=$? |
| 47 | set -e |
| 48 | [ "$crc" = 0 ] || bad "$1: compiler exit $crc ($(cat "$B/$1.err"))" |
| 49 | chmod +x "$B/$1.bin" |
| 50 | set +e |
| 51 | "$B/$1.bin" >/dev/null |
| 52 | rrc=$? |
| 53 | set -e |
| 54 | [ "$rrc" = "$3" ] || bad "$1: ran $rrc, wanted $3" |
| 55 | ok=$((ok+1)) |
| 56 | say "PASS $1 exit $rrc" |
| 57 | } |
| 58 | refuse() { # name file expect-error |
| 59 | n=$((n+1)) |
| 60 | set +e |
| 61 | "$S" < "$2" > "$B/$1.bin" 2>"$B/$1.err" |
| 62 | crc=$? |
| 63 | set -e |
| 64 | [ "$crc" = "$3" ] || bad "$1: compiler exit $crc, wanted $3 ($(cat "$B/$1.err"))" |
| 65 | grep -q "error $3" "$B/$1.err" || bad "$1: stderr missing error $3 ($(cat "$B/$1.err"))" |
| 66 | ok=$((ok+1)) |
| 67 | say "PASS $1 error $crc" |
| 68 | } |
| 69 | |
| 70 | run_exit t1 "$T/t1.om" 42 |
| 71 | run_exit t1x "$T/t1x.om" 20 |
| 72 | run_exit t1y "$T/t1y.om" 22 |
| 73 | run_exit t2 "$T/t2.om" 6 |
| 74 | run_exit t3 "$T/t3.om" 15 |
| 75 | run_exit t4 "$T/t4.om" 17 |
| 76 | run_exit t5 "$T/t5.om" 10 |
| 77 | run_exit t6 "$T/t6.om" 21 |
| 78 | run_exit t7 "$T/t7.om" 1 |
| 79 | run_exit t7b "$T/t7b.om" 9 |
| 80 | run_exit t8 "$T/t8.om" 1 |
| 81 | run_exit t9 "$T/t9.om" 1 |
| 82 | |
| 83 | refuse bad_field "$T/bad_field.om" 3 |
| 84 | refuse after_fn "$T/after_fn.om" 9 |
| 85 | refuse dup_struct "$T/dup_struct.om" 10 |
| 86 | refuse put_view "$T/put_view.om" 20 |
| 87 | refuse fields17 "$T/fields17.om" 14 |
| 88 | refuse idx_hi "$T/idx_hi.om" 21 |
| 89 | refuse still_free "$T/still_free.om" 9 |
| 90 | refuse field_is_struct "$T/field_is_struct.om" 10 |
| 91 | refuse new_in_if "$T/new_in_if.om" 9 |
| 92 | refuse no_end "$T/no_end.om" 4 |
| 93 | refuse empty "$T/empty.om" 16 |
| 94 | refuse dup_field "$T/dup_field.om" 10 |
| 95 | refuse missing_val "$T/missing_val.om" 4 |
| 96 | |
| 97 | # Field names are read. Swapping x for y must change the exit, or the gate checks nothing. |
| 98 | n=$((n+1)) |
| 99 | sed 's/get p x/get p y/' "$T/t1x.om" > "$B/mut.om" |
| 100 | set +e |
| 101 | "$S" < "$B/mut.om" > "$B/mut.bin" 2>"$B/mut.err" |
| 102 | crc=$? |
| 103 | set -e |
| 104 | [ "$crc" = 0 ] || bad "mut: compiler exit $crc ($(cat "$B/mut.err"))" |
| 105 | chmod +x "$B/mut.bin" |
| 106 | set +e |
| 107 | "$B/mut.bin" >/dev/null |
| 108 | rrc=$? |
| 109 | set -e |
| 110 | [ "$rrc" = 22 ] || bad "mut ran $rrc, wanted 22 (field swap did not change the result)" |
| 111 | [ "$rrc" != 20 ] || bad "mut still returned x" |
| 112 | ok=$((ok+1)) |
| 113 | say "PASS mut field-swap exit $rrc" |
| 114 | |
| 115 | [ "$n" = 26 ] || bad "ran $n cases, wrote 26" |
| 116 | [ "$ok" = 26 ] || bad "passed $ok of $n" |
| 117 | say "PASS gate6 $ok cases" |
| 118 | say "RC=0" |