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-seeded

46 lines · 2519 bytes Raw Blame History
1#!/bin/sh
2# Explicit checked frontends: frozen e5b32567 or --float-next draft #1049.
3# Authorized by Main acting for Drake for CUDApp native x86 portability.
4set -eu
5next=0
6runtime=0
7if [ "${1-}" = --runtime-views ]; then runtime=1; shift; fi
8if [ "${1-}" = --float-next ]; then next=1; shift; fi
9case ${1-} in c) mode=D;; python) mode=Q;; h) mode=H;; lib-c) mode=L;; lib-h) mode=M;; lib-map) mode=V;; *) echo 'usage: tools/bridge-seeded [--runtime-views | --float-next] c|python|h|lib-c|lib-h|lib-map source.om' >&2; exit 64;; esac
10case $mode in L|M|V) lib=1;; *) lib=0;; esac
11[ "$lib" = 0 ] || [ "$next$runtime" = 00 ] || { echo 'library modes use the frozen e5 profile' >&2; exit 24; }
12if [ "$next" = 1 ]; then
13 case $mode in D) mode=E;; H) mode=J;; *) echo 'next float profile supports c|h only' >&2; exit 24;; esac
14fi
15if [ "$runtime" = 1 ]; then
16 [ "$next" = 0 ] || { echo 'runtime views require the frozen e5 profile' >&2; exit 24; }
17 case $mode in D) mode=R;; H) mode=S;; *) echo 'runtime views support c|h only' >&2; exit 24;; esac
18fi
19[ "$#" = 2 ] || exit 64
20input=$(realpath -- "$2")
21cd "$(dirname "$0")/.."
22sha256sum --status -c build/compiler.sha256 || { echo 'rebuild required: tools/build.sh' >&2; exit 65; }
23want=2c82480596bbdc50cda9626866209ef662d5834f278f839ff4ce0250c495029f
24if [ "$next" = 1 ]; then
25 seed=${OMEGA_SEEDED_NEXT_OMC:-}
26 want=d89bdc08ca21ea9726f1117adc791f683287d3698ea112a9db5519df2e79aeec
27 label=OMEGA_SEEDED_NEXT_OMC
28else
29 seed=${OMEGA_SEEDED_OMC:-}
30 label=OMEGA_SEEDED_OMC
31fi
32[ -n "$seed" ] && [ -f "$seed" ] || { echo "NOT_RUN: set $label" >&2; exit 3; }
33[ "$(sha256sum "$seed" | cut -d' ' -f1)" = "$want" ] || { echo 'seeded frontend fingerprint mismatch' >&2; exit 65; }
34tmp=$(mktemp -d build/seeded-request.XXXXXX)
35trap 'find "$tmp" -type f -delete; rmdir "$tmp"' EXIT HUP INT TERM
36cat "$input" > "$tmp/input.om"
37"$seed" < "$tmp/input.om" > "$tmp/native"
38[ -s "$tmp/native" ] || exit 65
39if [ "$lib" = 1 ]; then
40 # cabi-1 provenance trailer: generator and source digests. src/toc.om recomputes both with its own
41 # SHA-256 (generator bytes on fd 3, source bytes from stdin) and refuses a mismatch with error 52.
42 # Successor: a seeded-Omega driver replaces this shell (ISSUES-TO-FILE.md, bridge-seeded successor).
43 { printf '%s' "$mode"; cat "$tmp/input.om"; printf '\n%s %s\n' "$(sha256sum src/toc.om | cut -d' ' -f1)" "$(sha256sum "$tmp/input.om" | cut -d' ' -f1)"; } | build/bridge 3< src/toc.om
44else
45 { printf '%s' "$mode"; cat "$tmp/input.om"; } | build/bridge
46fi