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 / tests / checker2 / gen_valid.sh

120 lines · 3567 bytes Raw Blame History
1#!/bin/sh
2# SPDX-License-Identifier: Apache-2.0
3# Copyright 2026 Drake Stapleton (AIEN / aien-dev)
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17# Deterministic generator of valid OSC units for the checker2 gate (omega#446): writes
18# <out>/gen_NN.osc for NN in 00..(count-1). Each unit varies the scalar type, array length, loop
19# bound and shape (loops, borrows, structs, drop-flag moves, casts, contracts) by its index. No
20# randomness: the same count gives the same files. The producer (oscc) must accept every one;
21# that is checked by tests/checker2/differential.sh, not assumed here.
22# Usage: sh tests/checker2/gen_valid.sh <out-dir> [count]
23set -eu
24OUT=$1
25N=${2:-48}
26mkdir -p "$OUT"
27set -- u8 u16 u32 u64 i8 i16 i32 i64
28i=0
29while [ "$i" -lt "$N" ]; do
30 k=$((i % 8 + 1))
31 T=$(eval echo "\${$k}")
32 L=$((i % 7 + 2))
33 B=$((10 + i * 3))
34 C=$((i % 5 + 1))
35 f=$(printf '%s/gen_%02d.osc' "$OUT" "$i")
36 case $((i % 6)) in
37 0) cat > "$f" <<EOF
38// entry: main
39// generated shape 0: owned array, for loop, while-bound loop ($T, len $L, bound $B)
40fn main(x: $T) -> $T {
41 let a: own [$T; $L] = alloc(x);
42 for j in 0 .. $L { a[j] = a[j] ^ (j as $T); }
43 let mut n: u32 = 0;
44 while n < $C bound $B { n = n + 1; }
45 let r: $T = a[0] | a[$((L - 1))];
46 return r;
47}
48EOF
49 ;;
50 1) cat > "$f" <<EOF
51// entry: main
52// generated shape 1: shared and mutable borrows into helpers ($T, len $L)
53fn fill(a: &mut [$T; $L], v: $T) {
54 for j in 0 .. $L { a[j] = v; }
55}
56fn first(a: &[$T; $L]) -> $T { return a[0]; }
57fn main(v: $T) -> $T {
58 let a: own [$T; $L] = alloc(v);
59 fill(&mut a, v);
60 let r: $T = first(&a);
61 return r;
62}
63EOF
64 ;;
65 2) cat > "$f" <<EOF
66// entry: main
67// generated shape 2: struct with scalar and array fields ($T, len $L)
68struct S$i { tag: u8, vals: [$T; $L], ok: bool }
69fn main(v: $T, t: u8) -> $T {
70 let s: own S$i = S$i { tag: t, vals: [v; $L], ok: t > $C };
71 if s.ok { s.vals[0] = v & v; }
72 s.tag = s.tag | 1;
73 return s.vals[$((L - 1))];
74}
75EOF
76 ;;
77 3) cat > "$f" <<EOF
78// entry: main
79// generated shape 3: conditional move with a drop flag ($T, len $L)
80fn take(x: own [$T; $L]) -> $T { return x[0]; }
81fn main(c: bool, v: $T) -> $T {
82 let a: own [$T; $L] = alloc(v);
83 let mut r: $T = v;
84 if c { r = take(a); }
85 return r;
86}
87EOF
88 ;;
89 4) cat > "$f" <<EOF
90// entry: main
91// generated shape 4: casts, shifts, comparisons and a counted loop ($T, bound $B)
92fn main(x: $T, s: u8) -> u64 {
93 let mut acc: u64 = 0;
94 let mut n: u16 = 0;
95 while n < $C bound $B {
96 acc = acc + ((x as u64) >> (s & 7));
97 n = n + 1;
98 }
99 if (x as u64) >= acc { return acc; }
100 return acc << 1;
101}
102EOF
103 ;;
104 5) cat > "$f" <<EOF
105// entry: main
106// generated shape 5: contracts and a chain of calls ($T)
107fn clamp(v: $T, hi: $T) -> $T requires hi >= 0 ensures result <= hi {
108 if v > hi { return hi; }
109 return v;
110}
111fn main(v: $T) -> $T {
112 let a: $T = clamp(v, $C);
113 let b: $T = clamp(a, $((C + 1)));
114 return a + b;
115}
116EOF
117 ;;
118 esac
119 i=$((i + 1))
120done