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

157 lines · 10927 bytes Raw Blame History
1#!/bin/sh
2# gate16.sh -- named integer constants and loop bounds. `const NAME TYPE INTEGER` is a top-level typed
3# value, visible to later functions only (define before use). The first table runs programs and compares
4# exit status; the second requires a compile refusal with the exact code (including function mode, where
5# a global, a text or a host word stays error 9); the third compiles function-mode units (no `fn main`)
6# with constants and requires words byte-identical to the same unit written with literals. The tables
7# also pin `while ... bound N` and `for ... bound N`: N 1 .. 2^63-1 (a number or an integer constant),
8# more passes trap 4 (exit 104), bound 0 and 2^63 are error 8; a for with a value count and no bound
9# keeps the 1000000 default. OMC selects the compiler (default seed/out/omc; a relative path is taken
10# from the repository root).
11set -eu
12R=$(CDPATH= cd -- "$(dirname "$0")/../.." && pwd)
13cd "$R"
14S=${OMC:-seed/out/omc}
15[ -x "$S" ] || { printf 'FAIL: %s missing; run sh seed/omega-from-seed.sh first\n' "$S" >&2; exit 1; }
16mkdir -p build/seed/r16
17T=$(mktemp -d build/seed/r16/const.XXXXXX)
18trap 'rm -rf "$T"' EXIT HUP INT TERM
19bad() { printf 'FAIL: %s\n' "$*" >&2; exit 1; }
20say() { printf '%s\n' "$*"; }
21
22n=0
23while IFS='|' read -r name want src; do
24 [ -n "$name" ] || continue
25 n=$((n + 1))
26 printf '%b\n' "$src" > "$T/p.om"
27 set +e
28 "$S" < "$T/p.om" > "$T/p.bin" 2> "$T/p.err"
29 rc=$?
30 set -e
31 [ "$rc" = 0 ] || bad "$name: compile $rc: $(cat "$T/p.err")"
32 chmod +x "$T/p.bin"
33 set +e
34 "$T/p.bin" > /dev/null 2>&1
35 got=$?
36 set -e
37 [ "$got" = "$want" ] || bad "$name: exit $got, wanted $want"
38done <<'RUN'
39basic|5|const N uint 5\nfn main to int\nret int N\nend
40long_name_ok|7|const loop_count_limit uint 7\nfn main to int\nret int loop_count_limit\nend
41negative|253|const M long -3\nfn main to int\nret int M\nend
42expression|6|const N uint 4\nfn main to int\nx = add N uint 2\nret int x\nend
43call_argument|8|const K int 7\nfn f a int to int\nret add a K\nend\nfn main to int\nret f int 1\nend
44bool_flag|3|const B bool 1\nfn main to int\nif B\nret 3\nend\nret 4\nend
45ulong_max|255|const U ulong 18446744073709551615\nfn main to int\nret int rem U ulong 256\nend
46long_min|0|const L long -9223372036854775808\nfn main to int\nret int rem L long 256\nend
47between_fns|9|fn f to int\nret 1\nend\nconst N int 9\nfn main to int\nret N\nend
48length_local|7|const N uint 4\nfn main to int\na = new uint N 0\nput a 3 7\nret int get a 3\nend
49length_global|4|const N uint 4\nglobal g uchar N\nfn main to int\nret int len g\nend
50length_param|4|const N uint 4\nfn f a view uint N to int\nret int len a\nend\nfn main to int\nx = new uint N 0\nret f x\nend
51float_bits|154|const H f64 0.1\nfn main to int\nret int rem bitcast ulong H ulong 256\nend
52float32_bits|205|const H f32 0.1\nfn main to int\nret int rem bitcast uint H uint 256\nend
53float_arith|0|const H f64 0.1\nfn main to int\nx = add H f64 0.2\nif eq x f64 0.3\nret 1\nend\nret 0\nend
54struct_length|32|const N uint 4\nstruct S a uchar N end\nfn main to int\np = new S 0\nret int sizeof S\nend
55const_bound|2|const B ulong 3\nfn main to int\nx = ulong 0\nwhile lt x ulong 2 bound B\nx = add x 1\nend\nret int x\nend
56trap_const|102|const T uint 2\nfn main to int\ntrap T\nend
57for_const|4|const K ulong 4\nfn main to int\nx = ulong 0\nfor i ulong K\nx = add x 1\nend\nret int x\nend
58const_order|12|const kk ulong 4\nfn a fs edit long kk to void\nput fs 0 1\nend\nconst k2 ulong 3\nfn b fs edit long kk gs edit long k2 to long\nput fs 3 7\nput gs 2 5\nret add get fs 3 get gs 2\nend\nfn main to int\nx = new long kk 0\ny = new long k2 0\na x\nret int b x y\nend
59big_bound|54|const B ulong 3000000\nfn main to int\nx = ulong 0\nwhile lt x 2000000 bound B\nx = add x 1\nend\nret int rem x 97\nend
60big_bound_trap|104|fn main to int\nx = ulong 0\nwhile lt x 2000000 bound 1500000\nx = add x 1\nend\nret 0\nend
61max_bound|5|fn main to int\nx = ulong 0\nwhile lt x 5 bound 9223372036854775807\nx = add x 1\nend\nret int x\nend
62for_bound|54|const B ulong 3000000\nfn main to int\nn = ulong 2000000\nx = ulong 0\nfor i ulong n bound B\nx = add x 1\nend\nret int rem x 97\nend
63for_num_bound|89|const B ulong 3000000\nfn main to int\nx = ulong 0\nfor i ulong 1500000 bound B\nx = add x 1\nend\nret int rem x 97\nend
64for_bound_trap|104|fn main to int\nn = ulong 2000000\nx = ulong 0\nfor i ulong n bound 1500000\nx = add x 1\nend\nret 0\nend
65for_num_bound_trap|104|fn main to int\nx = ulong 0\nfor i ulong 5000 bound 4097\nx = add x 1\nend\nret 0\nend
66for_bound_exact|3|fn main to int\nn = uint 3\nx = ulong 0\nfor i uint n bound 3\nx = add x 1\nend\nret int x\nend
67for_num_bound_exact|7|fn main to int\nx = ulong 0\nfor i ulong 7 bound 7\nx = add x 1\nend\nret int x\nend
68for_max_bound|5|fn main to int\nn = ulong 5\nx = ulong 0\nfor i ulong n bound 9223372036854775807\nx = add x 1\nend\nret int x\nend
69for_default_trap|104|fn main to int\nn = ulong 2000000\nx = ulong 0\nfor i ulong n\nx = add x 1\nend\nret 0\nend
70RUN
71[ "$n" = 31 ] || bad "value table ran $n of 31 cases"
72
73n=0
74while IFS='|' read -r name want src; do
75 [ -n "$name" ] || continue
76 n=$((n + 1))
77 printf '%b\n' "$src" > "$T/p.om"
78 set +e
79 "$S" < "$T/p.om" > /dev/null 2> "$T/p.err"
80 rc=$?
81 set -e
82 [ "$rc" = "$want" ] || bad "$name: exit $rc, wanted $want ($(cat "$T/p.err"))"
83 grep -q "error $want\$" "$T/p.err" || bad "$name: stderr lacks error $want"
84done <<'REF'
85assign|7|const N uint 5\nfn main to int\nN = uint 6\nret 0\nend
86duplicate|10|const N uint 5\nconst N uint 6\nfn main to int\nret 0\nend
87out_of_range|8|const N uchar 300\nfn main to int\nret 0\nend
88ir_float_const|9|ir\nconst H f64 0.1\nfn f to f64\nret H\nend
89extra_word|5|const N uint 5 6\nfn main to int\nret 0\nend
90long_name|13|const abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijkl uint 5\nfn main to int\nret 0\nend
91reserved|16|const while uint 5\nfn main to int\nret 0\nend
92missing_value|4|const N uint\nfn main to int\nret 0\nend
93inside_fn|16|fn main to int\nconst N uint 5\nret 0\nend
94use_before|3|fn f to int\nret int N\nend\nconst N int 9\nfn main to int\nret f\nend
95len_zero|8|const N uint 0\nfn main to int\na = new uint N 0\nret 0\nend
96len_big|23|const N uint 16777217\nfn main to int\na = new uint N 0\nret 0\nend
97len_varname|16|fn main to int\nn = uint 4\na = new uint n 0\nret 0\nend
98len_after|16|fn f to int\na = new uint N 0\nret 0\nend\nconst N uint 4\nfn main to int\nret f\nend
99float_as_length|16|const H f64 0.1\nfn main to int\na = new uchar H 0\nret 0\nend
100float_int_literal|16|const H f64 5\nfn main to int\nret 0\nend
101struct_length_big|14|const N uint 65\nstruct S a uchar N end\nfn main to int\nret 0\nend
102float_bound|16|const B f64 0.5\nfn main to int\nwhile eq int 1 int 1 bound B\nend\nret 0\nend
103trap_range|8|const T uint 0\nfn main to int\ntrap T\nend
104fm_global|9|const N ulong 5\nglobal g ulong 4\nfn f a ulong to ulong\nret add a N\nend
105fm_text|9|const N ulong 5\ntext t "hi"\nfn f a ulong to ulong\nret add a N\nend
106fm_global_only|9|global g ulong 4\nfn f a ulong to ulong\nret a\nend
107fm_text_only|9|text t "hi"\nfn f a ulong to ulong\nret a\nend
108fm_host_word|9|const N ulong 5\nfn f a ulong to long\nx = getpid\nret x\nend
109fm_trap_range|8|const T uint 15\nfn f a ulong to ulong\ntrap T\nend
110fm_float_length|16|const H f64 0.1\nfn f a view uchar H to ulong\nret 0\nend
111fm_assign|7|const N ulong 5\nfn f a ulong to ulong\nN = ulong 6\nret a\nend
112bound_zero|8|fn main to int\nwhile eq int 1 int 1 bound 0\nend\nret 0\nend
113bound_over|8|fn main to int\nwhile eq int 1 int 1 bound 9223372036854775808\nend\nret 0\nend
114for_bound_zero|8|fn main to int\nn = ulong 2\nfor i ulong n bound 0\nend\nret 0\nend
115for_num_bound_zero|8|fn main to int\nfor i ulong 2 bound 0\nend\nret 0\nend
116for_bound_over|8|fn main to int\nn = ulong 2\nfor i ulong n bound 9223372036854775808\nend\nret 0\nend
117for_num_bound_over|8|fn main to int\nfor i ulong 2 bound 9223372036854775808\nend\nret 0\nend
118for_bound_missing|4|fn main to int\nn = ulong 2\nfor i ulong n bound\nend\nret 0\nend
119for_bound_local|16|fn main to int\nn = ulong 2\nfor i ulong n bound n\nend\nret 0\nend
120REF
121[ "$n" = 35 ] || bad "refusal table ran $n of 35 cases"
122
123# Function mode (no `fn main`): an integer or float constant folds to its literal, so the bare function
124# words must be byte-identical to the same unit written with literals. Each line: name|const unit|literal unit.
125n=0
126while IFS='|' read -r name csrc lsrc; do
127 [ -n "$name" ] || continue
128 n=$((n + 1))
129 printf '%b\n' "$csrc" > "$T/c.om"
130 printf '%b\n' "$lsrc" > "$T/l.om"
131 set +e
132 "$S" < "$T/c.om" > "$T/c.bin" 2> "$T/c.err"
133 rc=$?
134 "$S" < "$T/l.om" > "$T/l.bin" 2> "$T/l.err"
135 lrc=$?
136 set -e
137 [ "$rc" = 0 ] || bad "$name: const unit compile $rc: $(cat "$T/c.err")"
138 [ "$lrc" = 0 ] || bad "$name: literal unit compile $lrc: $(cat "$T/l.err")"
139 [ -s "$T/c.bin" ] || bad "$name: no function words"
140 cmp -s "$T/c.bin" "$T/l.bin" || bad "$name: const words differ from literal words"
141done <<'FM'
142fm_value|const AB ulong 5\nfn top a ulong to ulong\nret add a AB\nend|fn top a ulong to ulong\nret add a 5\nend
143fm_negative|const M long -3\nfn top a long to long\nret mul a M\nend|fn top a long to long\nret mul a -3\nend
144fm_param_len|const N ulong 4\nfn f a view ulong N to ulong\nret get a sub N 1\nend|fn f a view ulong 4 to ulong\nret get a sub ulong 4 1\nend
145fm_new_len|const N uint 4\nfn f k uint to uint\nb = new uint N k\nret get b 3\nend|fn f k uint to uint\nb = new uint 4 k\nret get b 3\nend
146fm_bound|const B ulong 3\nfn f a ulong to ulong\nx = ulong 0\nwhile lt x a bound B\nx = add x 1\nend\nret x\nend|fn f a ulong to ulong\nx = ulong 0\nwhile lt x a bound 3\nx = add x 1\nend\nret x\nend
147fm_trap|const T uint 5\nfn f a ulong to ulong\nif eq a 1\ntrap T\nend\nret a\nend|fn f a ulong to ulong\nif eq a 1\ntrap 5\nend\nret a\nend
148fm_for|const K ulong 4\nfn f a ulong to ulong\nx = a\nfor i ulong K\nx = add x i\nend\nret x\nend|fn f a ulong to ulong\nx = a\nfor i ulong 4\nx = add x i\nend\nret x\nend
149fm_two_fns|const N ulong 7\nfn g a ulong to ulong\nret add a N\nend\nfn f a ulong to ulong\nret g mul a N\nend|fn g a ulong to ulong\nret add a 7\nend\nfn f a ulong to ulong\nret g mul a 7\nend
150fm_float|const H f64 0.1\nfn f a f64 to f64\nret add a H\nend|fn f a f64 to f64\nret add a f64 0.1\nend
151fm_for_bound|const B ulong 3\nfn f a ulong to ulong\nx = ulong 0\nfor i ulong a bound B\nx = add x 1\nend\nret x\nend|fn f a ulong to ulong\nx = ulong 0\nfor i ulong a bound 3\nx = add x 1\nend\nret x\nend
152fm_for_default|const B ulong 1000000\nfn f a ulong to ulong\nx = ulong 0\nfor i ulong a bound B\nx = add x 1\nend\nret x\nend|fn f a ulong to ulong\nx = ulong 0\nfor i ulong a\nx = add x 1\nend\nret x\nend
153FM
154[ "$n" = 11 ] || bad "function-mode table ran $n of 11 cases"
155
156say "PASS gate16 31 constant programs, 35 refusals and 11 function-mode units"
157exit 0