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 / rung4 / gate4.sh

220 lines · 15899 bytes Raw Blame History
1#!/bin/sh
2# gate4.sh -- the checks of rung 4 (seed/README.md). Run from the repo root: sh seed/rung4/gate4.sh
3# Needs build/omegese/omegese and build/omega_emit/omega_emit (the C path, built by make through
4# quiet-build), cc for the reference runner and committed expected outputs for the program tests. Oracles only:
5# none of them writes a byte of seed/; om4.bin is made by asm2 alone. Results: build/seed/r4/evidence/. The
6# recorded receipt evidence/SEED-0/rung4/ (and seed/rung4/om4.audit) is only read: the results are compared
7# with it at the end (seed/check/receipt.sh), never written over it.
8set -eu
9R=seed/rung4; B=build/seed/r4; E=$B/evidence; REC=evidence/SEED-0/rung4; X=$R/tests
10T=tests/one_layer/exp445/dev/tasks/cases; O=tests/one_layer/omegese/dev
11TAB="seed/rung2/table.s2 seed/rung3/table3.s2 $R/table4.s2"
12mkdir -p "$B" "$E"
13fail=0; cases=0
14say() { printf '%s\n' "$*" | tee -a "$E/gate4.log"; }
15bad() { say "FAIL: $*"; fail=1; }
16: > "$E/gate4.log"
17say "gate4 $(date -u +%FT%TZ) at $(git rev-parse HEAD)"
18
19# 1. asm2 builds om4; a second build gives the same bytes; the file-size field matches the file
20cat $TAB $R/om4.s | seed/rung2/asm2.bin > $B/om4.again
21cmp -s $R/om4.bin $B/om4.again && say "PASS om4.bin = a fresh asm2 build of om4.s, same bytes" || bad "om4.bin is not what asm2 makes from om4.s"
22size=$(stat -c %s $R/om4.bin); fsz=$(od -An -tu4 -j96 -N4 $R/om4.bin | tr -d ' ')
23[ "$size" = "$fsz" ] && say "PASS p_filesz $fsz = file size $size" || bad "p_filesz $fsz, file $size"
24sha256sum $R/om4.bin | tee "$E/om4.sha256" >> "$E/gate4.log"
25
26# 2. every instruction of om4 decodes (objdump, reference) to its name, registers, numbers, label
27if sh seed/check/audit2.sh $R/om4.s $R/om4.bin > $E/om4.audit; then :; fi
28tail -1 $E/om4.audit | tee -a "$E/gate4.log" | grep -q 'mismatch=0$' && say "PASS audit (objdump reference run)" || bad "audit"
29for c in 's/^ movz.x x25 0x181 1$/ movz.x x26 0x181 1/' 's/^ b.hs BO_SDIV$/ b.hs BO_RET/' \
30 's/^ ldr.x.r x12 sp x11$/ ldr.x.r x12 sp x10/' 's/^ ubfm.x x11 x11 1 63$/ ubfm.x x11 x11 2 63/' \
31 's/^ movz.x x0 0x63ff 0$/ movz.x x0 0x63fe 0/'; do
32 sed "$c" $R/om4.s > $B/bad.s
33 if cmp -s $B/bad.s $R/om4.s; then bad "control edit did nothing: $c"
34 elif sh seed/check/audit2.sh $B/bad.s $R/om4.bin > $B/bad.audit; then bad "control not caught: $c"
35 else say "PASS audit control caught ($c): $(tail -1 $B/bad.audit)"; fi
36done
37
38# 3. the reference runner (seed/check/runner.c, links the repo C path)
39cc -O1 -Isrc -Isrc/compiler -o $B/runner seed/check/runner.c \
40 $(ls src/compiler/*.c | grep -v oscc_main.c) src/omega_om_units.c
41[ -x build/omegese/omegese ] && [ -x build/omega_emit/omega_emit ] || { bad "C path tools not built"; exit 1; }
42
43# 4. the 10 dev tasks (gate 3) under om4: the same words as om3, the same results as the C path and the
44# expected file
45tab="$E/words.tsv"
46printf 'program\tinputs\ttraps\tc_path_words\tom4_words\n' > "$tab"
47cmpc() { # name entry inputs omegese -> compares om4 with the C path on the runner
48 build/omegese/omegese emit $4 $B/$1.json > /dev/null
49 build/omega_emit/omega_emit emit $B/$1.json $B/$1.oscir > /dev/null
50 sed '/^free /d' $4 | $R/om4.bin > $B/$1.om4.bin # the C path's language needs free for its arrays; om4's has none
51 $B/runner $B/$1.oscir "$2" $3 > $B/$1.c.out
52 $B/runner $B/$1.oscir "$2" $3 $B/$1.om4.bin > $B/$1.s.out
53 tail -n +2 $B/$1.c.out > $B/$1.c.res; tail -n +2 $B/$1.s.out > $B/$1.s.res
54 n=$(wc -l < $3); tr=$(grep -c TRAP $B/$1.s.res || true); cases=$((cases + n))
55 cw=$(sed -n 's/^words //p' $B/$1.c.out); sw=$(sed -n 's/^words //p' $B/$1.s.out)
56 printf '%s\t%s\t%s\t%s\t%s\n' $1 $n $tr $cw $sw >> "$tab"
57 if cmp -s $B/$1.c.res $B/$1.s.res; then say "PASS $1: $n inputs ($tr traps), om4 = C path (value and raw x0)"
58 else bad "$1 differs from the C path"; diff $B/$1.c.res $B/$1.s.res | head -5 >> "$E/gate4.log"; fi
59 grep -q NONCANONICAL $B/$1.s.res && bad "$1: a result not in canonical form" || true
60 cp $B/$1.s.out $E/$1.om4.out; cp $B/$1.c.out $E/$1.c.out
61}
62for d in dev01 dev02 dev03 dev04 dev05 dev06 dev07 dev08 dev09 dev10; do
63 entry=$(awk '$1=="entry"{print $2}' $T/$d/requirement)
64 cmpc $d "$entry" $T/$d/hidden/inputs $O/$d.omegese
65 cmp -s $B/$d.om4.bin evidence/SEED-0/rung3/$d.seed.bin && say "PASS $d: om4 words = om3 words" || bad "$d: om4 words differ from om3"
66 cut -f1 $B/$d.s.res | cmp -s - $T/$d/hidden/expected && say "PASS $d: om4 = expected" || bad "$d differs from expected"
67done
68
69# 5. function-mode programs with the new words the C path can also express (signed div, rem, shl at
70# their limits, calls, a for with a value count, local arrays, array parameters, bounds traps)
71for f in fm1 fm2 fm3 fm4 fm5 fm6 fm7 fm8 fm9; do
72 cmpc $f "$(cat $X/$f.entry)" $X/$f.inputs $X/$f.omegese
73 objdump -D -z -b binary -m aarch64 -M no-aliases $B/$f.om4.bin | grep -qE ' (udf|\.inst|undefined)' && bad "$f: a word that is not an instruction" || true
74done
75cat "$tab" >> "$E/gate4.log"
76
77# 6. program mode (hand-laid ELF, no linker) against committed expected outputs:
78# recursive fib, a 1000-entry sort, echo stdin -> stdout, byte copy (reversed)
79for p in fib sort echo bytecopy; do $R/om4.bin < $X/$p.om > $B/$p; chmod +x $B/$p; done
80cp $X/in.bin $B/in.bin
81./$B/fib > $B/fib.out
82cmp -s $B/fib.out $X/fib.want && say "PASS fib (recursion): 26 lines = expected output" || bad "fib differs from expected output"
83./$B/sort > $B/sort.out
84cmp -s $B/sort.out $X/sort.want && say "PASS sort 1000: checksum, sorted count, first, last = expected output ($(tr '\n' ' ' < $B/sort.out))" || bad "sort differs"
85./$B/echo < $B/in.bin > $B/echo.out
86cmp -s $B/in.bin $B/echo.out && say "PASS echo: 50000 fixture bytes stdin -> stdout unchanged" || bad "echo"
87./$B/bytecopy < $B/in.bin > $B/bc.out
88cmp -s $B/bc.out $X/bytecopy.want && say "PASS byte copy: 50000 bytes reversed = expected output" || bad "bytecopy"
89cases=$((cases + 4))
90for p in fib sort echo bytecopy; do cp $B/$p $E/$p.elf; done
91# program-mode traps and exit: status 100 + trap code, or the exit value. Run-time pools (OMEGESE 9.15):
92# t_pool (grow, keep, zero, len), t_pool_range (index = length, trap 3), t_pool_grow (a grow inside while
93# and if); h_* run under prlimit --as=268435456 (h_poolhost: the host refuses enlarge, -12, and the program
94# goes on with the pool unchanged)
95for t in $X/t_*.om $X/h_*.om; do n=$(basename $t .om)
96 $R/om4.bin < $t > $B/$n; chmod +x $B/$n
97 case $n in h_*) lim="prlimit --as=268435456";; *) lim="";; esac
98 set +e; $lim ./$B/$n < /dev/null; rc=$?; set -e; cases=$((cases + 1))
99 [ "$rc" = "$(cat ${t%.om}.want)" ] && say "PASS $n${lim:+ under $lim}: exit $rc" || bad "$n${lim:+ under $lim}: exit $rc, want $(cat ${t%.om}.want)"
100done
101
102# 7. om4 refuses, each with its own number (decisions 16-24 of docs/PROGRAM.md marked)
103t() { # expected-code text
104 printf '%b' "$2" > $B/ctl.omegese; cases=$((cases + 1))
105 set +e; $R/om4.bin < $B/ctl.omegese > $B/ctl.bin 2> $B/ctl.err; rc=$?; set -e
106 [ "$rc" = "$1" ] && say "PASS refusal exit $rc: $(cat $B/ctl.err) [$3]" || bad "refusal wanted exit $1, got $rc: $2"
107}
108t 3 'fn f a uint to uint\nret add a q\nend\n' 'unknown name'
109t 7 'fn f a uint b ulong to ulong\nret add a b\nend\n' '20: no implicit widening'
110t 7 'fn f a ulong to uint\nret a\nend\n' '20: no implicit narrowing'
111t 16 'fn f a view uchar to uint\nret 0\nend\n' '16: an array without its length'
112t 16 'global g uchar\nfn main to int\nret 0\nend\n' '16: a pool without its length'
113t 19 'fn s a edit uint 4 b edit uint 4 to void\nend\nfn f to uint\nx = new uint 4 0\ns x x\nfree x\nret 0\nend\n' '18: one array twice in a call'
114t 19 'global g uint 4\nfn s a view uint 4 to uint\nret get a 0\nend\nfn main to int\nr = s g\nret 0\nend\n' '18: a global passed'
115t 20 'fn s a view uint 4 to void\nput a 0 1\nend\n' '17: write through a view'
116t 20 'text t "ab"\nfn main to int\nput t 0 1\nret 0\nend\n' '17: write into a text'
117t 20 'text t "ab"\nfn main to int\nn = read 0 t 0 1\nret 0\nend\n' '17: read into a text'
118t 20 'fn s a edit uint 4 to void\nend\nfn f a view uint 4 to uint\ns a\nret 0\nend\n' '17: an edit argument from a view'
119t 21 'fn main to int\nx = new uint 4 0\nr = get x 4\nret 0\nend\n' '23: a number index outside the array'
120t 7 'fn s a view uint 4 to uint\nret 0\nend\nfn f to uint\nx = new uint 5 0\nr = s x\nret r\nend\n' '17: an array of another shape'
121t 22 'text t "a\\qb"\nfn main to int\nret 0\nend\n' '19: an escape with no meaning'
122t 22 'text t "ab\nfn main to int\nret 0\nend\n' 'a text with no end'
123t 23 'global g ulong 16777217\nfn main to int\nret 0\nend\n' '24: a pool over its limit'
124t 23 'fn main to int\nx = new ulong 600000 0\nret 0\nend\n' '24: local arrays over 4 MiB'
125t 17 'fn f a uint to uint\nret a\nx = a\nend\n' 'a line after ret'
126t 18 'fn f a uint to uint\nif eq a 0\nret 1\nend\nend\n' 'a value function that can reach its end'
127t 9 'fn f a uint to uint\nret f a\nend\n' 'a self-call in function mode (stack use bounded by the call order)'
128t 9 'global g uint 4\nfn f a uint to uint\nret a\nend\n' 'a pool in function mode'
129t 9 'fn main to int\nif true\nx = new uint 4 0\nend\nret 0\nend\n' 'new inside a block'
130t 9 'fn main a int to int\nret a\nend\n' 'main with parameters'
131t 20 'fn s a edit int 2 to void\nput a 1 9\nend\nfn main to int\nx = new int 2 0\ns view x\nret get x 1\nend\n' '17: view A to an edit parameter (L412 probe view_pfx_to_edit)'
132t 8 'fn main to int\nx = ulong -1\nret 0\nend\n' '20: a negative number is not a ulong'
133t 8 'fn main to int\nx = long 9223372036854775808\nret 0\nend\n' '20: 2^63 is not a long'
134t 8 'fn main to int\nx = byte 18446744073709551615\nret 0\nend\n' '20: 2^64 - 1 is not a byte (no wrap to -1)'
135t 8 'fn main to int\nx = ulong 18446744073709551616\nret 0\nend\n' '23: 2^64 is no whole number of any type'
136t 6 'fn main to int\nx = ulong 100000000000000000000\nret 0\nend\n' 'a number of 21 digits'
137t 23 'global g uchar 9223372036854775808\nfn main to int\nret 0\nend\n' '24: a pool of 2^63 elements is over its limit'
138t 9 'fn main to int\nx = new uint 4 0\nfree x\nret 0\nend\n' '24: free is not a word (no heap, nothing given back by hand)'
139t 9 'fn f a int b int to int\nret 0\nend\nfn g to int\nx = own a\nret 0\nend\n' 'own is not in the subset'
140t 10 'fn f a uint to uint\nret a\nend\nfn g f uint to uint\nret f\nend\n' 'a name equal to a function'
141t 13 'fn f a uint to uint\nabcdefghi = a\nret a\nend\n' 'a variable over 8 characters'
142t 15 'fn f a uint to uint\nret a\n' 'a function without end'
143t 14 "fn f a ulong to ulong\nx = $(printf 'neg %.0s' $(seq 1025))a\nret x\nend\n" '23: values nested over 1024 deep (a capacity, refused not overrun)'
144t 16 'end\n' 'end outside a function'
145t 16 'ret 5\n' 'a statement outside a function'
146t 6 'fn f a uint to uint\nret add a 12x\nend\n' 'bad number'
147t 7 'fn f to void\nret\nend\nfn g to uint\nx = f\nret 0\nend\n' 'a void function used as a value'
148t 7 'fn f to uint\nret 1\nend\nfn g to void\nf\nend\n' 'a value function called as a statement'
149
150# 6b. names pass (R5b). A later function is a call, never a new scalar. Program mode may
151# recurse mutually. Function mode refuses a call cycle (error 9). Checked here, not against
152# the C path: the C path still has the one-pass limit these cases exist to leave behind.
153r5b() { # file expect-exit expect-error-or-dash
154 cases=$((cases + 1))
155 set +e; $R/om4.bin < $X/$1 > $B/$1.bin 2> $B/$1.err; rc=$?; set -e
156 if [ "$rc" != "$2" ]; then bad "$1: exit $rc, wanted $2 ($(cat $B/$1.err))"; return; fi
157 if [ "$3" != "-" ] && ! grep -q "error $3" $B/$1.err; then bad "$1: stderr missing error $3: $(cat $B/$1.err)"; return; fi
158 if [ "$3" = "-" ]; then say "PASS $1: exit $rc"; else say "PASS $1: exit $rc error $3"; fi
159}
160r5b r5b_fwd.om 0 -
161chmod +x $B/r5b_fwd.om.bin; set +e; ./$B/r5b_fwd.om.bin >/dev/null; rc=$?; set -e
162[ "$rc" = 7 ] && say "PASS r5b_fwd runs: exit 7 (the later function)" || bad "r5b_fwd ran as $rc, wanted 7"
163r5b r5b_mut.om 0 -
164chmod +x $B/r5b_mut.om.bin; set +e; ./$B/r5b_mut.om.bin >/dev/null; rc=$?; set -e
165[ "$rc" = 0 ] && say "PASS r5b_mut runs: even 8 is 1, exit 0" || bad "r5b_mut ran as $rc, wanted 0"
166r5b r5b_cycle.om 9 9
167r5b r5b_assign.om 7 7
168r5b r5b_fwd_fm.om 0 -
169# the forward BL must land on late's MOVZ #7, not on a placeholder
170objdump -D -b binary -m aarch64 -M no-aliases $B/r5b_fwd_fm.om.bin > $B/r5b_fwd_fm.dis
171seven=$(awk '/movz/ && /#0x7/ { gsub(":", "", $1); print $1; exit }' $B/r5b_fwd_fm.dis)
172if grep bl $B/r5b_fwd_fm.dis | grep -q "0x$seven"; then
173 say "PASS r5b_fwd_fm: BL lands on MOVZ X0, #7 at 0x$seven"
174else bad "r5b_fwd_fm: forward call did not land (see $B/r5b_fwd_fm.dis)"; fi
175
176cases=$((cases + 3))
177
178# 7b. function table capacity (OMEGESE 9.6): 4096 functions accepted, the 4097th error 14. The unit is a
179# function-mode chain (g_k returns g_(k-1)), so the call graph check also runs at full size. Control:
180# an om4 whose limit is one lower must refuse the 4096-function unit.
181fnchain() { awk -v n=$1 'BEGIN{for(i=0;i<n;i++){printf "fn g%d to int\n", i; if(i==0) print "ret 7"; else printf "ret g%d\n", i-1; print "end"}}'; }
182fnchain 4096 > $B/fn4096.om; fnchain 4097 > $B/fn4097.om
183set +e; $R/om4.bin < $B/fn4096.om > $B/fn4096.bin 2> $B/fn4096.err; r1=$?
184$R/om4.bin < $B/fn4097.om > $B/fn4097.bin 2> $B/fn4097.err; r2=$?; set -e
185[ "$r1" = 0 ] && say "PASS 4096 functions accepted" || bad "4096 functions: exit $r1 ($(cat $B/fn4096.err))"
186[ "$r2" = 14 ] && grep -q 'line 12289: error 14' $B/fn4097.err && say "PASS 4097th function (line 12289) error 14" || bad "4097 functions: exit $r2 ($(cat $B/fn4097.err))"
187sed 's/^ cmp.x.i x10 4095$/ cmp.x.i x10 4094/' $R/om4.s > $B/cap.s
188cmp -s $B/cap.s $R/om4.s && bad "capacity control edit did nothing"
189cat $TAB $B/cap.s | seed/rung2/asm2.bin > $B/cap.bin; chmod +x $B/cap.bin
190set +e; $B/cap.bin < $B/fn4096.om > /dev/null 2>&1; r3=$?; set -e
191[ "$r3" = 14 ] && say "PASS capacity control: om4 with limit 4095 refuses 4096 functions (error 14)" || bad "capacity control not caught: exit $r3"
192cases=$((cases + 3))
193
194# 8. negative control on the corpus: an om4 with one word changed (signed division made unsigned) must
195# change a result
196sed 's/^ movz.x x0 0x0c00 0$/ movz.x x0 0x0800 0/' $R/om4.s > $B/mut.s
197cmp -s $B/mut.s $R/om4.s && bad "mutation did nothing"
198cat $TAB $B/mut.s | seed/rung2/asm2.bin > $B/mut.bin; chmod +x $B/mut.bin
199$B/mut.bin < $X/fm1.omegese > $B/fm1.mut.bin
200$B/runner $B/fm1.oscir sdivr $X/fm1.inputs $B/fm1.mut.bin > $B/fm1.mut.out
201if cmp -s $B/fm1.mut.out $B/fm1.s.out; then bad "mutant om4 (SDIV -> UDIV) not caught"; else say "PASS negative control: om4 with SDIV made UDIV changes fm1 results"; fi
202
203# 9. the spec addendum (decision 19): no sentence says a meaning is left open
204if sed -n "/^## 9. Systems words/,\$p" docs/one_layer/OMEGESE.md | grep -qi undefined; then bad "the word undefined in the spec addendum"; else say "PASS spec addendum (OMEGESE.md section 9): grep -i undefined finds nothing"; fi
205
206# 10. decision 22, one legal next word: the next-word fuzz over the om4 words (seed/check/nextfuzz.sh).
207# NF_N random programs from seed/check/nextgen.awk (all must be accepted), each cut after every word
208# and changed in every word place: om4 answers each with exit 0 or its error number, never a crash.
209# (omegese next, the C tool, does not know the om4 words, so this fuzz is native.)
210nf=${NF_N:-20}
211if [ "$nf" -gt 0 ]; then
212 if NFW=$B/nextfuzz sh seed/check/nextfuzz.sh $nf $R/om4.bin > $B/nextfuzz.out 2>&1; then say "PASS $(tail -1 $B/nextfuzz.out)"
213 else bad "next fuzz: $(grep -v '^nextfuzz:' $B/nextfuzz.out | head -3) $(tail -1 $B/nextfuzz.out)"; fi
214 cases=$((cases + 1))
215fi
216say "cases run: $cases"
217# the recorded receipt is compared, never rewritten; the verdict below is the checks' alone
218say "$(sh seed/check/receipt.sh "$E" "$REC" $R/om4.audit || true)"
219[ $fail = 0 ] && say "GATE4 PASS" || say "GATE4 FAIL"
220exit $fail