omega-bridge
Omega-first language interoperability: checked conversion backends and native language bindings
Brought by drakestapleton
omega-bridge / tools / bridge
| 1 | #!/bin/sh |
| 2 | # The pinned Omega frontend checks the complete unit before either backend runs. |
| 3 | set -eu |
| 4 | case ${1-} in c) mode=C;; python) mode=P;; *) echo 'usage: tools/bridge c|python source.om' >&2; exit 64;; esac |
| 5 | [ "$#" = 2 ] || exit 64 |
| 6 | input=$(realpath -- "$2") |
| 7 | cd "$(dirname "$0")/.." |
| 8 | sha256sum --status -c build/compiler.sha256 || { echo "rebuild required: tools/build.sh" >&2; exit 65; } |
| 9 | seed=${OMEGA_SEED:-build/bootstrap/omc} |
| 10 | [ "$(sha256sum "$seed" | cut -d' ' -f1)" = 191b776ef98821597c3e30655da6d680a9b66edbc9ceaca3c39c61ea6df098e9 ] || exit 65 |
| 11 | # Snapshot once: validation and generation must read identical bytes. |
| 12 | tmp=$(mktemp -d build/request.XXXXXX) |
| 13 | trap 'find "$tmp" -type f -delete; rmdir "$tmp"' EXIT HUP INT TERM |
| 14 | cat "$input" > "$tmp/input.om" |
| 15 | "$seed" < "$tmp/input.om" > "$tmp/native" |
| 16 | [ -s "$tmp/native" ] || exit 65 |
| 17 | { printf '%s' "$mode"; cat "$tmp/input.om"; } | build/bridge |