interplane.Get Omega
Read in your language

hop

Hop: a small native macOS launcher. Clipboard history, find, on-device dictation and your coding agent behind one key.

Brought by drakestapleton

branch main Branches Tags History

hop / Omega / gen.sh

49 lines · 3722 bytes Raw Blame History
1#!/bin/sh
2# Regenerates Generated/ from Omega/hopfact.om and Omega/hopfuse.om. Runs on Linux AArch64 only (the
3# seeded compiler is a Linux AArch64 executable). Usage, from a copy of the Hop tree on that host:
4# OMEGA_NATIVE_OMC=<omc sha256 734f0a39...> BRIDGE=<omega-bridge checkout at d8174ed> sh Omega/gen.sh OUT
5# Writes OUT/Generated (omega_native.c/.h, hopfact.bin, hopfuse.bin, ident.txt, SHA256SUMS),
6# OUT/mutant (the hopfact unknown->idle source mutant) and OUT/mutant-fuse (the hopfuse
7# unknown->trivial source mutant); the Mac checks must catch both. Copy all three back into the Hop
8# tree: Generated/, Omega/tests/mutant/ and Omega/tests/mutant-fuse/.
9set -eu
10OUT=${1:?usage: gen.sh OUT}
11BRIDGE=${BRIDGE:?set BRIDGE to an omega-bridge checkout at d8174ed}
12OMC=${OMEGA_NATIVE_OMC:?set OMEGA_NATIVE_OMC to the seeded omc}
13ROOT=$(cd "$(dirname "$0")/.." && pwd)
14want_bridge=d8174eddf953ad53e16f19eb5841459df99e24bb
15[ "$(git -C "$BRIDGE" rev-parse HEAD)" = $want_bridge ] || { echo "bridge is not at $want_bridge" >&2; exit 1; }
16[ -z "$(git -C "$BRIDGE" status --porcelain)" ] || { echo "bridge checkout is dirty" >&2; exit 1; }
17# tools/native itself refuses any compiler other than sha256 734f0a39... (the OM-1 pin).
18rm -rf "$OUT"; mkdir -p "$OUT/Generated" "$OUT/mutant/src" "$OUT/mutant-fuse/src"; OUT=$(cd "$OUT" && pwd)
19# Relative unit paths, so the identity records embedded in the binding name Omega/hopfact.om and Omega/hopfuse.om.
20cd "$ROOT"
21"$BRIDGE/tools/native" "$OUT/gen" Omega/hopfact.om Omega/hopfuse.om > /dev/null
22cp "$OUT/gen/omega_native.c" "$OUT/gen/omega_native.h" "$OUT/gen/work/hopfact.bin" "$OUT/gen/work/hopfuse.bin" "$OUT/gen/work/ident.txt" "$OUT/Generated/"
23# Negative control 1: hopfact catof's "unknown state -> UNKNOWN" turned into "-> IDLE" (fail-open mutant).
24awk 'BEGIN{d=0} /^fn catof /{d=1} d==1 && /^if eq s 0$/{print; getline; print "ret 12"; d=2; next} {print}' \
25 "$ROOT/Omega/hopfact.om" > "$OUT/mutant/src/hopfact.om"
26! cmp -s "$ROOT/Omega/hopfact.om" "$OUT/mutant/src/hopfact.om" || { echo "mutant not applied" >&2; exit 1; }
27"$BRIDGE/tools/native" "$OUT/genmut" "$OUT/mutant/src/hopfact.om" > /dev/null
28cp "$OUT/genmut/omega_native.c" "$OUT/mutant/"
29cp "$OUT/genmut/work/hopfact.bin" "$OUT/mutant/hopfact.bin"
30cp "$OUT/mutant/src/hopfact.om" "$OUT/mutant/mut.om"
31# Negative control 2: hopfuse level's "unknown difficulty counts as standard" turned into "as trivial"
32# (the shortcut the core exists to refuse).
33awk 'BEGIN{d=0} /^fn level /{d=1} d==1 && /^d = ulong 3$/{print "d = ulong 1"; d=2; next} {print}' \
34 "$ROOT/Omega/hopfuse.om" > "$OUT/mutant-fuse/src/hopfuse.om"
35! cmp -s "$ROOT/Omega/hopfuse.om" "$OUT/mutant-fuse/src/hopfuse.om" || { echo "fuse mutant not applied" >&2; exit 1; }
36"$BRIDGE/tools/native" "$OUT/genmutfuse" "$OUT/mutant-fuse/src/hopfuse.om" > /dev/null
37cp "$OUT/genmutfuse/omega_native.c" "$OUT/mutant-fuse/"
38cp "$OUT/genmutfuse/work/hopfuse.bin" "$OUT/mutant-fuse/hopfuse.bin"
39cp "$OUT/mutant-fuse/src/hopfuse.om" "$OUT/mutant-fuse/mut.om"
40rm -rf "$OUT/gen" "$OUT/genmut" "$OUT/genmutfuse" "$OUT/mutant/src" "$OUT/mutant-fuse/src"
41{
42 echo "# hopfact and hopfuse native binding, generated on $(uname -sm) by omega-bridge $want_bridge tools/native"
43 echo "# omc $(sha256sum "$OMC" | cut -d' ' -f1)"
44 echo "# bridge src/native.om $(sha256sum "$BRIDGE/src/native.om" | cut -d' ' -f1)"
45 echo "# bridge tools/native $(sha256sum "$BRIDGE/tools/native" | cut -d' ' -f1)"
46 (cd "$ROOT" && sha256sum Omega/hopfact.om Omega/hopfuse.om)
47 (cd "$OUT/Generated" && sha256sum omega_native.c omega_native.h hopfact.bin hopfuse.bin ident.txt | sed 's# # Generated/#')
48} > "$OUT/Generated/SHA256SUMS"
49cat "$OUT/Generated/ident.txt"