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 / qualification / om2 / oracle / s3s4 / pinned_rule.py
| 1 | #!/usr/bin/env python3 |
| 2 | # SPDX-License-Identifier: Apache-2.0 |
| 3 | # Expected refusal of each OM-2 fixture of sec/s3s4 by the pinned OM-1 compiler 734f0a39, from the |
| 4 | # OM-1 rules, without running any compiler: |
| 5 | # - OMEGESE 9.2: a names pass reads every fn signature before any code, so a signature that is not |
| 6 | # OM-1 is refused first, at its line, before the om2 line (a code line) is reached. |
| 7 | # In a signature, the first non-OM-1 token decides the code: |
| 8 | # `*` as an array length: error 16 (OMEGESE 9.4: an array parameter without its length); |
| 9 | # `out` as a parameter kind: error 16 (OMEGESE 9.11: an unknown type name is error 16); |
| 10 | # a word after the return type (`to T inline`): error 5 (OM-1 "tokens left after the |
| 11 | # statement" code; contract section 2 line 59-61 says it is pinned by fixtures; the value 5 is |
| 12 | # the one reported by the QualPhaseB.FixInvariants lane, 2026-10-25, and is checked by the gate). |
| 13 | # - Otherwise the first non-note line `om2`, `om2 diag` or `om2 fmt` is refused with error 16 |
| 14 | # (contract section 0 lines 13-14). |
| 15 | # Output: "<fixture path> <line> <code>" per OM-2 fixture (first non-note line starts with om2). |
| 16 | import glob |
| 17 | import os |
| 18 | import sys |
| 19 | |
| 20 | HERE = os.path.dirname(os.path.abspath(__file__)) |
| 21 | SEC = os.path.normpath(os.path.join(HERE, "..", "..", "sec", "s3s4")) |
| 22 | ROOT = os.path.normpath(os.path.join(HERE, "..", "..", "..", "..", "..")) |
| 23 | |
| 24 | |
| 25 | def sig_error(toks): |
| 26 | # toks: fn NAME (PARAM KIND ...)* [to T [extra]] |
| 27 | i = 2 |
| 28 | while i < len(toks) and toks[i] != "to": |
| 29 | name, kind = toks[i], toks[i + 1] |
| 30 | if kind == "out": |
| 31 | return 16 |
| 32 | if kind in ("view", "edit"): |
| 33 | if toks[i + 3] == "*": |
| 34 | return 16 |
| 35 | i += 4 |
| 36 | else: |
| 37 | i += 2 |
| 38 | if i < len(toks) and len(toks) > i + 2: |
| 39 | return 5 |
| 40 | return None |
| 41 | |
| 42 | |
| 43 | def rule(path): |
| 44 | lines = open(path).read().split("\n") |
| 45 | first = next(j for j, l in enumerate(lines) if not l.startswith("note")) |
| 46 | if not lines[first].startswith("om2"): |
| 47 | return None |
| 48 | for j, l in enumerate(lines): |
| 49 | if l.startswith("fn "): |
| 50 | c = sig_error(l.split()) |
| 51 | if c is not None: |
| 52 | return j + 1, c |
| 53 | return first + 1, 16 |
| 54 | |
| 55 | |
| 56 | out = [] |
| 57 | for p in sorted(glob.glob(os.path.join(SEC, "*.om"))): |
| 58 | r = rule(p) |
| 59 | if r: |
| 60 | out.append("%s %d %d" % (os.path.relpath(p, ROOT), r[0], r[1])) |
| 61 | sys.stdout.write("".join(o + "\n" for o in out)) |