omega-bridge
Omega-first language interoperability: checked conversion backends and native language bindings
Brought by drakestapleton
omega-bridge / tools / bridge-freest
| 1 | #!/bin/sh |
| 2 | # Import-free scalar or checked borrowed-view profile; both emitters are seeded Omega. |
| 3 | set -eu |
| 4 | case ${1-} in c) mode=F; views=W;; h) mode=H; views=Y;; *) echo 'usage: tools/bridge-freest c|h source.om' >&2; exit 64;; esac |
| 5 | [ "$#" = 2 ] || exit 64 |
| 6 | input=$(realpath -- "$2") |
| 7 | cd "$(dirname "$0")/.." |
| 8 | seed=${OMEGA_SEED:-build/bootstrap/omc} |
| 9 | front=${OMEGA_SEEDED_OMC:-} |
| 10 | [ -f "$seed" ] || { echo 'NOT_RUN: set OMEGA_SEED to baseline compiler' >&2; exit 3; } |
| 11 | [ -n "$front" ] && [ -f "$front" ] || { echo 'NOT_RUN: set OMEGA_SEEDED_OMC' >&2; exit 3; } |
| 12 | [ "$(sha256sum "$seed" | cut -d' ' -f1)" = 191b776ef98821597c3e30655da6d680a9b66edbc9ceaca3c39c61ea6df098e9 ] || { echo 'baseline seed fingerprint mismatch' >&2; exit 65; } |
| 13 | [ "$(sha256sum "$front" | cut -d' ' -f1)" = 2c82480596bbdc50cda9626866209ef662d5834f278f839ff4ce0250c495029f ] || { echo 'seeded frontend fingerprint mismatch' >&2; exit 65; } |
| 14 | tmp=$(mktemp -d "${TMPDIR:-/tmp}/bridge-freest.XXXXXX") |
| 15 | trap 'rm -f "$tmp/input.om" "$tmp/native" "$tmp/converter" "$tmp/generated"; rmdir "$tmp"' EXIT HUP INT TERM |
| 16 | cat "$input" > "$tmp/input.om" |
| 17 | # The exact snapshot passes full language/type validation before the structural profile. |
| 18 | "$front" < "$tmp/input.om" > "$tmp/native" |
| 19 | [ -s "$tmp/native" ] || exit 65 |
| 20 | "$seed" < src/toc.om > "$tmp/converter" |
| 21 | [ -s "$tmp/converter" ] || exit 65 |
| 22 | chmod +x "$tmp/converter" |
| 23 | # The signature scan selects one profile before body conversion. A borrowed-view |
| 24 | # unit never retries the scalar profile after a capability or runtime refusal. |
| 25 | rc=0 |
| 26 | { printf '%s' "$views"; cat "$tmp/input.om"; } | "$tmp/converter" > "$tmp/generated" || rc=$? |
| 27 | if [ "$rc" = 25 ]; then |
| 28 | "$seed" < src/freest.om > "$tmp/converter" |
| 29 | [ -s "$tmp/converter" ] || exit 65 |
| 30 | chmod +x "$tmp/converter" |
| 31 | { printf '%s' "$mode"; cat "$tmp/input.om"; } | "$tmp/converter" > "$tmp/generated" |
| 32 | elif [ "$rc" != 0 ]; then |
| 33 | exit "$rc" |
| 34 | fi |
| 35 | cat "$tmp/generated" |