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 / gate15.sh
| 1 | #!/bin/sh |
| 2 | # gate15.sh -- refusal-code conformance and the error-code registry (issue #797). |
| 3 | # Every emitted or io code in seed/omc/error-codes.reg has at least one minimal case here: codes 1..25 |
| 4 | # and 27..30 (26 has no emitting site), including the IR-mode contract refusal (#791). Each case must |
| 5 | # exit with exactly its code and print exactly `omc: line L: error C` on stderr; a valid control must |
| 6 | # compile. Each refusal appends `NAME CODE` to a ran-log. seed/omc/codereg.om, compiled by the same |
| 7 | # omc, then checks the registry against omc.om, irwasm.om, the docs/one_layer/OMEGESE.md tables |
| 8 | # (sections 9.14 and 11.1) and the ran-log. Built-in negative controls (a changed registry meaning, a |
| 9 | # changed OMEGESE row, a dropped ran-log case) must each make codereg fail. |
| 10 | set -eu |
| 11 | R=$(CDPATH= cd -- "$(dirname "$0")/../.." && pwd) |
| 12 | cd "$R" |
| 13 | S=seed/out/omc |
| 14 | [ -x "$S" ] || { printf 'FAIL: %s missing; run sh seed/omega-from-seed.sh first\n' "$S" >&2; exit 1; } |
| 15 | mkdir -p build/seed/r15 |
| 16 | T=$(mktemp -d build/seed/r15/codes.XXXXXX) |
| 17 | trap 'rm -rf "$T"' EXIT HUP INT TERM |
| 18 | bad() { printf 'FAIL: %s\n' "$*" >&2; exit 1; } |
| 19 | say() { printf '%s\n' "$*"; } |
| 20 | : > "$T/ran.log" |
| 21 | n=0 |
| 22 | |
| 23 | # expect NAME CODE LINE: the last compile ($T/p.err, exit $rc) refused exactly so. |
| 24 | expect() { |
| 25 | [ "$rc" = "$2" ] || bad "$1: exit $rc, wanted $2 ($(cat "$T/p.err"))" |
| 26 | [ "$(cat "$T/p.err")" = "omc: line $3: error $2" ] || |
| 27 | bad "$1: stderr '$(cat "$T/p.err")', wanted 'omc: line $3: error $2'" |
| 28 | printf '%s %s\n' "$1" "$2" >> "$T/ran.log" |
| 29 | n=$((n + 1)) |
| 30 | } |
| 31 | # run FILE [OUT]: compile FILE, stdout to OUT (default $T/p.bin). |
| 32 | run() { |
| 33 | set +e |
| 34 | "$S" < "$1" > "${2:-$T/p.bin}" 2> "$T/p.err" |
| 35 | rc=$? |
| 36 | set -e |
| 37 | } |
| 38 | |
| 39 | while IFS='|' read -r name want line src; do |
| 40 | [ -n "$name" ] || continue |
| 41 | printf '%b\n' "$src" > "$T/p.om" |
| 42 | run "$T/p.om" |
| 43 | expect "$name" "$want" "$line" |
| 44 | done <<'CASES' |
| 45 | e3_unknown_name|3|2|fn f to int\nret q\nend |
| 46 | e4_line_ends|4|2|struct S a uint\nfn main to int\nret 0\nend |
| 47 | e5_extra_words|5|2|fn f to int\nret 0 extra\nend |
| 48 | e6_bad_number|6|2|fn f to int\nx = 12a\nret 0\nend |
| 49 | e7_type_mismatch|7|2|fn f to int\nx = add int 1 uint 2\nret 0\nend |
| 50 | e8_out_of_range|8|2|fn f to int\nx = int 2147483648\nret 0\nend |
| 51 | e9_break_outside|9|2|fn f to int\nbreak\nret 0\nend |
| 52 | e10_duplicate_param|10|1|fn f x int x int to int\nret 0\nend |
| 53 | e11_ambiguous|11|2|fn f to int\nx = 5\nret 0\nend |
| 54 | e13_long_variable|13|2|fn f to int\nabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijkl = int 1\nret 0\nend |
| 55 | e15_missing_end|15|3|fn f to int\nret 0 |
| 56 | e16_syntax|16|1|wat |
| 57 | e17_after_path|17|3|fn f to int\nret 0\nret 1\nend |
| 58 | e18_missing_ret|18|3|fn f to int\nend |
| 59 | e19_global_passed|19|5|global g uchar 4\nfn f a edit uchar 4 to void\nend\nfn main to int\nf g\nret 0\nend |
| 60 | e20_readonly|20|3|text t "abc"\nfn main to int\nput t 0 1\nret 0\nend |
| 61 | e21_const_index|21|3|fn main to int\na = new uint 4 0\nput a 4 1\nret 0\nend |
| 62 | e22_text_literal|22|1|text t "a\\q"\nfn main to int\nret 0\nend |
| 63 | e23_size_capacity|23|2|fn main to int\na = new uchar 16777217 0\nret 0\nend |
| 64 | e25_target|25|1|target arm64li\nfn main to int\nret 0\nend |
| 65 | e27_fresh_get|27|3|om2\nfn f s edit uchar 8 fresh to ulong\nret ulong get s 0\nend\nfn main to int\nret 0\nend |
| 66 | e28_seal_outside|28|4|om2\nabstract h uint\nfn main to int\nx = seal h uint 1\nret 0\nend |
| 67 | e28_holds_dup32|28|3|om2\nabstract h uint\nholds h dup32\nfn main to int\nret 0\nend |
| 68 | e29_layout_past|29|3|om2\nlayout z 8\nfield a ulong at 1 little\nend\nfn main to int\nret 0\nend |
| 69 | e30_contract_after_ret|30|4|om2\nfn f x uint to uint\nret x\nrequires lt x 10\nend\nfn main to int\nret 0\nend |
| 70 | e30_ir_requires|30|3|ir\nfn f x uint to uint\nrequires lt x 10\nret x\nend |
| 71 | e30_ir_ensures|30|3|ir\nfn f x uint to uint\nensures lt x 10\nret x\nend |
| 72 | e30_ir_invariant|30|3|ir\nfn f x uint to uint\ninvariant lt x 10\nret x\nend |
| 73 | CASES |
| 74 | |
| 75 | # Valid control, also the program for the output-error case. |
| 76 | printf 'fn main to int\nret 0\nend\n' > "$T/ok.om" |
| 77 | run "$T/ok.om" |
| 78 | [ "$rc" = 0 ] || bad "valid control: exit $rc ($(cat "$T/p.err"))" |
| 79 | |
| 80 | # 1: stdin is a directory, so the first read fails before any line. |
| 81 | mkdir "$T/dir" |
| 82 | run "$T/dir" |
| 83 | expect e1_input_unreadable 1 0 |
| 84 | # 2: stdout is a full device; the write happens after the last line. |
| 85 | if [ -w /dev/full ]; then |
| 86 | run "$T/ok.om" /dev/full |
| 87 | expect e2_output_unwritable 2 4 |
| 88 | else |
| 89 | bad "e2_output_unwritable: /dev/full is not writable here" |
| 90 | fi |
| 91 | # 26: the compiler's environment entry OMC_MEMORY_MAX is malformed: refused before any input is read (line 0) |
| 92 | export OMC_MEMORY_MAX=12x |
| 93 | run "$T/ok.om" |
| 94 | unset OMC_MEMORY_MAX |
| 95 | expect e26_memory_max 26 0 |
| 96 | |
| 97 | # 12: the 17th live name exhausts the 16-register pool. |
| 98 | { |
| 99 | printf 'fn f to int\n' |
| 100 | i=1 |
| 101 | while [ "$i" -le 17 ]; do printf 'a%s = int %s\n' "$i" "$i"; i=$((i + 1)); done |
| 102 | printf 'ret add a1 add a2 add a3 add a4 add a5 add a6 add a7 add a8 add a9 add a10 add a11 add a12 add a13 add a14 add a15 add a16 a17\n' |
| 103 | printf 'end\n' |
| 104 | } > "$T/p.om" |
| 105 | run "$T/p.om" |
| 106 | expect e12_register_pool 12 18 |
| 107 | |
| 108 | # 14: a value nested past the depth omc's own 8 MiB stack can hold (32768 levels, OMEGESE 9.6). The |
| 109 | # arena-full refusal, the other emitting site, is checked by seed/omc/gate12.sh. |
| 110 | { |
| 111 | printf 'fn main to int\ny = ulong 7\nx = ' |
| 112 | awk 'BEGIN { for (i = 0; i < 32768; i++) printf "ulong " }' |
| 113 | printf 'y\nret int rem x 256\nend\n' |
| 114 | } > "$T/p.om" |
| 115 | run "$T/p.om" |
| 116 | expect e14_capacity 14 3 |
| 117 | |
| 118 | # 24: an `if` body of N one-word lines. N=262142 keeps the B.cond displacement in range (accept); |
| 119 | # N=262143 does not, and the refusal names the `end` that closes the `if` (line N+4). |
| 120 | br() { |
| 121 | { printf 'fn main to int\nx = uint 0\nif eq x 1\n'; yes 'x = add x 1' | head -n "$1"; printf 'end\nret 0\nend\n'; } > "$T/p.om" |
| 122 | } |
| 123 | br 262142 |
| 124 | run "$T/p.om" |
| 125 | [ "$rc" = 0 ] || bad "e24 accept side (262142 lines): exit $rc ($(cat "$T/p.err"))" |
| 126 | br 262143 |
| 127 | run "$T/p.om" |
| 128 | expect e24_branch_range 24 262147 |
| 129 | |
| 130 | [ "$n" = 34 ] || bad "ran $n of 34 refusal cases" |
| 131 | |
| 132 | # The registry drift check, compiled by the same omc. |
| 133 | run seed/omc/codereg.om "$T/codereg" |
| 134 | [ "$rc" = 0 ] || bad "codereg.om did not compile: $(cat "$T/p.err")" |
| 135 | chmod +x "$T/codereg" |
| 136 | REG=seed/omc/error-codes.reg |
| 137 | DOC=docs/one_layer/OMEGESE.md |
| 138 | SRC=seed/omc/omc.om |
| 139 | IRW=seed/wasm/irwasm.om |
| 140 | "$T/codereg" "$REG" "$SRC" "$DOC" "$IRW" "$T/ran.log" > "$T/cr.out" 2>&1 || bad "codereg: $(cat "$T/cr.out")" |
| 141 | say "$(cat "$T/cr.out")" |
| 142 | |
| 143 | # Negative controls: each mutation must make codereg fail. |
| 144 | neg() { # name registry omegese ranlog |
| 145 | if "$T/codereg" "$2" "$SRC" "$3" "$IRW" "$4" > "$T/neg.out" 2>&1; then |
| 146 | bad "negative control $1: codereg accepted it" |
| 147 | fi |
| 148 | say "PASS negative control $1: $(head -n 1 "$T/neg.out")" |
| 149 | } |
| 150 | sed 's/^omc|7|emitted|e7_type_mismatch|type mismatch$/omc|7|emitted|e7_type_mismatch|type mismatch or worse/' "$REG" > "$T/reg.mut" |
| 151 | cmp -s "$REG" "$T/reg.mut" && bad "negative control registry-meaning: sed changed nothing" |
| 152 | neg registry-meaning "$T/reg.mut" "$DOC" "$T/ran.log" |
| 153 | sed 's/^| omc 7 | type mismatch |$/| omc 7 | type mismatch or worse |/' "$DOC" > "$T/doc.mut" |
| 154 | cmp -s "$DOC" "$T/doc.mut" && bad "negative control omegese-row: sed changed nothing" |
| 155 | neg omegese-row "$REG" "$T/doc.mut" "$T/ran.log" |
| 156 | grep -v '^e30_ir_requires 30$' "$T/ran.log" > "$T/ran.mut" || true |
| 157 | cmp -s "$T/ran.log" "$T/ran.mut" && bad "negative control dropped-case: grep removed nothing" |
| 158 | neg dropped-case "$REG" "$DOC" "$T/ran.mut" |
| 159 | |
| 160 | say "PASS gate15 $n refusal cases (codes 1..30; 24 with its accept side) plus a valid control, registry drift check and 3 negative controls" |
| 161 | exit 0 |