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 / gate6.sh

118 lines · 3746 bytes Raw Blame History
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.
6set -eu
7R=$(CDPATH= cd -- "$(dirname "$0")/../.." && pwd)
8cd "$R"
9B=build/seed/r6
10T=seed/omc/tests/struct
11mkdir -p "$B"
12OM4=seed/rung4/om4.bin
13bad() { printf 'FAIL: %s\n' "$*" >&2; exit 1; }
14say() { 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"))"
17chmod +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"))"
19chmod +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"))"
21chmod +x "$B/stage3"
22s1=$(sha256sum "$B/stage1" | cut -d' ' -f1)
23s2=$(sha256sum "$B/stage2" | cut -d' ' -f1)
24s3=$(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"
27say "PASS fixpoint $s3"
28S=$B/stage3
29cp "$S" seed/out/omc
30printf '%s seed/out/omc\n' "$s3" > seed/out/omc.sha256
31
32# om4 must still refuse a struct program (it has no such word).
33set +e
34"$OM4" < "$T/t1.om" > "$B/om4-t1.bin" 2>"$B/om4-t1.err"
35orc=$?
36set -e
37[ "$orc" != 0 ] || bad "om4 accepted a struct program"
38say "PASS om4 refuses struct (exit $orc)"
39
40n=0
41ok=0
42run_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}
58refuse() { # 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
70run_exit t1 "$T/t1.om" 42
71run_exit t1x "$T/t1x.om" 20
72run_exit t1y "$T/t1y.om" 22
73run_exit t2 "$T/t2.om" 6
74run_exit t3 "$T/t3.om" 15
75run_exit t4 "$T/t4.om" 17
76run_exit t5 "$T/t5.om" 10
77run_exit t6 "$T/t6.om" 21
78run_exit t7 "$T/t7.om" 1
79run_exit t7b "$T/t7b.om" 9
80run_exit t8 "$T/t8.om" 1
81run_exit t9 "$T/t9.om" 1
82
83refuse bad_field "$T/bad_field.om" 3
84refuse after_fn "$T/after_fn.om" 9
85refuse dup_struct "$T/dup_struct.om" 10
86refuse put_view "$T/put_view.om" 20
87refuse fields17 "$T/fields17.om" 14
88refuse idx_hi "$T/idx_hi.om" 21
89refuse still_free "$T/still_free.om" 9
90refuse field_is_struct "$T/field_is_struct.om" 10
91refuse new_in_if "$T/new_in_if.om" 9
92refuse no_end "$T/no_end.om" 4
93refuse empty "$T/empty.om" 16
94refuse dup_field "$T/dup_field.om" 10
95refuse 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.
98n=$((n+1))
99sed 's/get p x/get p y/' "$T/t1x.om" > "$B/mut.om"
100set +e
101"$S" < "$B/mut.om" > "$B/mut.bin" 2>"$B/mut.err"
102crc=$?
103set -e
104[ "$crc" = 0 ] || bad "mut: compiler exit $crc ($(cat "$B/mut.err"))"
105chmod +x "$B/mut.bin"
106set +e
107"$B/mut.bin" >/dev/null
108rrc=$?
109set -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"
112ok=$((ok+1))
113say "PASS mut field-swap exit $rrc"
114
115[ "$n" = 26 ] || bad "ran $n cases, wrote 26"
116[ "$ok" = 26 ] || bad "passed $ok of $n"
117say "PASS gate6 $ok cases"
118say "RC=0"