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 / gate-objhost.sh

54 lines · 3198 bytes Raw Blame History
1#!/bin/sh
2# gate-objhost.sh [OMC] -- host effects in native objects (DRA-542; spec/omegese-modules.md, OMEGESE "Native object output").
3# Python is an independent test oracle (seed/omc/tests/objhost/check.py), not a build dependency.
4# 1. OMC (default seed/out/omc) passes check.py: the object host subset compiles to function-mode code, the
5# rest still refuses, stack records cover host pushes, a linked two-module program does real I/O and
6# matches a single-unit build, and the module driver refuses a chain over 8 MiB only through a push.
7# 2. Controls, each built by OMC from a one-line change of seed/omc/omc.om and required to FAIL check.py
8# with its named contract:
9# record the object stack record drops the transient pushes (osmax), the under-report this gate exists for;
10# device the device words are let into objects;
11# count spsub stops counting, so pushes are never charged.
12# 3. CTRL (environment, optional): an older compiler that refuses host words in objects must FAIL check.py.
13set -eu
14R=$(CDPATH= cd -- "$(dirname "$0")/../.." && pwd)
15cd "$R"
16S=${1:-seed/out/omc}
17case "$S" in /*) ;; *) S="$R/$S";; esac
18test -x "$S"
19T=$(mktemp -d)
20trap 'rm -rf "$T"' EXIT HUP INT TERM
21python3 seed/omc/tests/objhost/check.py "$S" "$T/main"
22echo "PASS objhost check $(sha256sum "$S" | cut -d' ' -f1)"
23for mode in record device count; do
24 python3 - "$mode" "$T/$mode.om" <<'PY'
25from pathlib import Path
26import sys
27s = Path("seed/omc/omc.om").read_text()
28old, new = {
29 "record": ("a_p 86 sub get curfn 0 1 add get stkbytes 0 get osmax 0", "a_p 86 sub get curfn 0 1 get stkbytes 0"),
30 "device": ("\nif and ne get objmode 0 0 and ge c 166 le c 177\nnote d2site 174", "\nif and ne get objmode 0 0 and ge c 166 le c 99\nnote d2site 174"),
31 "count": ("put osp 0 add get osp 0 bytes\n", "put osp 0 get osp 0\n"),
32}[sys.argv[1]]
33assert s.count(old) == 1, sys.argv[1]
34Path(sys.argv[2]).write_text(s.replace(old, new))
35PY
36 "$S" < "$T/$mode.om" > "$T/$mode"
37 chmod +x "$T/$mode"
38 rc=0
39 python3 seed/omc/tests/objhost/check.py "$T/$mode" "$T/out-$mode" > "$T/$mode.log" 2>&1 || rc=$?
40 # record: the fopen record drops below 4112; device: mapdrop compiles; count: every save area pops
41 # past a zero count, so osbad refuses the first object function that calls a host word (finish, error 9).
42 want=$(case $mode in record) echo object-host-stack-record;; device) echo 'mapdrop';; count) echo 'error 9';; esac)
43 test "$rc" = 1 || { tail -5 "$T/$mode.log"; echo "FAIL objhost mutant $mode status=$rc"; exit 1; }
44 grep -q -e "$want" "$T/$mode.log" || { tail -5 "$T/$mode.log"; echo "FAIL objhost mutant $mode: wrong failure"; exit 1; }
45 echo "PASS objhost compiler mutant $mode caught"
46done
47if [ -n "${CTRL:-}" ]; then
48 rc=0
49 python3 seed/omc/tests/objhost/check.py "$CTRL" "$T/ctrl" > "$T/ctrl.log" 2>&1 || rc=$?
50 test "$rc" = 1 || { echo "FAIL objhost control $CTRL status=$rc"; exit 1; }
51 grep -q 'object-code-equals-function-mode\|AssertionError' "$T/ctrl.log" || { tail -5 "$T/ctrl.log"; exit 1; }
52 echo "PASS objhost control refused by older compiler $(sha256sum "$CTRL" | cut -d' ' -f1)"
53fi
54echo "OBJHOSTGATE PASS mutants=3"