interplane.Get Omega
Read in your language

omega-bridge

Omega-first language interoperability: checked conversion backends and native language bindings

Brought by drakestapleton

branch main Branches Tags History

omega-bridge / tools / bridge-freest

35 lines · 1905 bytes Raw Blame History
1#!/bin/sh
2# Import-free scalar or checked borrowed-view profile; both emitters are seeded Omega.
3set -eu
4case ${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
6input=$(realpath -- "$2")
7cd "$(dirname "$0")/.."
8seed=${OMEGA_SEED:-build/bootstrap/omc}
9front=${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; }
14tmp=$(mktemp -d "${TMPDIR:-/tmp}/bridge-freest.XXXXXX")
15trap 'rm -f "$tmp/input.om" "$tmp/native" "$tmp/converter" "$tmp/generated"; rmdir "$tmp"' EXIT HUP INT TERM
16cat "$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
22chmod +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.
25rc=0
26{ printf '%s' "$views"; cat "$tmp/input.om"; } | "$tmp/converter" > "$tmp/generated" || rc=$?
27if [ "$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"
32elif [ "$rc" != 0 ]; then
33 exit "$rc"
34fi
35cat "$tmp/generated"