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 / docs / WALKTHROUGH.md

198 lines · 11491 bytes Raw Blame History Source

How Omega Bridge works, and how it was built

This page is for an engineer who has not seen the project before. It explains the problem, the mechanism and the design choices, and records one approach that failed. It ends with a recipe you can run offline from a fresh checkout. Every claim links to the file it comes from.

Revision described: main at 7af4d11c3a9c853abc20a99f97d0a4f01524bb66.

The problem

Omega programs compile to AArch64 machine code with the seeded Omega compiler, which has no outside toolchain. That keeps Omega trustworthy, but an existing C or Python application cannot use an Omega function unless something connects the two. The goal recorded in DESIGN.md is to let existing languages and tools adopt Omega with as little change as possible, and to say exactly what is supported instead of claiming that any language translates perfectly.

The mechanism

There are two separate routes. Do not confuse them.

  1. Conversion (src/toc.om). A bounded subset of Omega is turned into GNU C11 or Python 3 source. The generated program prints the same output, exits with the same status and traps with the same code as the natively compiled Omega program.
  2. Native call bindings (src/native.om, NATIVE-ABI.md). These leave the program as Omega machine code in a shared library and generate the header or module that C, C++, Python, Rust, Zig or Go needs to call it. Nothing is translated.

This walkthrough covers route 1. A conversion request goes through tools/bridge in this order:

  1. Check build/compiler.sha256, so the converter binary matches its source. A mismatch exits 65.
  2. Check that the seed compiler's SHA-256 is 191b776ef98821597c3e30655da6d680a9b66edbc9ceaca3c39c61ea6df098e9. A mismatch exits 65.
  3. Copy the input once into a private temporary directory. Validation and generation both read that copy, so a file changed during the request cannot pass one step and fail the other.
  4. Compile the copy with the seed compiler as a whole-unit semantic check. If the seed rejects the program, nothing is emitted.
  5. Feed the copy to build/bridge, the converter compiled from src/toc.om. Its front end (lexer, name tables, two-pass signature scan; tok, namescan and walk_sig in src/toc.om) builds bounded typed expression nodes (node, expr, callnode). Separate writers then emit C or Python from those nodes (eexpr, eassign, efor, generate). This is code generation from parsed nodes, not text substitution (DESIGN.md, "Implemented architecture").
  6. Write the output to stdout only after the whole conversion succeeds. A refused feature exits with the compiler's error code and leaves stdout empty.

The generated code keeps Omega's observable rules: fixed-width arithmetic, arrays that carry their length, checked bounds, and defined traps. Python is made to wrap at fixed widths instead of using its unbounded integers. The full list of supported features and their limits is in CAPABILITIES.md. The calling convention for host programs is in ABI.md: every exported function returns a status code and writes its result through a pointer.

How it was built

A failed approach: the recovered emitter as found

The first step was to run the recovered converter unchanged against the inherited test corpus. It failed 8 of 20 cases (evidence/01-recovered-red.log):

FAIL t_conv ('C mismatch', 105, 0, b'', b'', b'')
FAIL t_exit ('conversion', 16, b'toc: line 2: error 16\n')
FAIL t_ovf ('gcc', ... implicit declaration of function 'o_add_s' ...)
FAIL t_stack ('C mismatch', 106, -11, b'', b'', b'')
cases=20 failures=8 RC=1

The emitter copied source text through with too few checks. A conversion trap (exit 105) became a C program that exited 0, and a stack trap (106) became a segmentation fault (-11). That is why the emitter was replaced by typed nodes with separate writers instead of being patched case by case. A second red run, evidence/22-inherited-text-red.log, showed that the inherited text.om program was not covered. It is now refused explicitly (see the recipe below).

Limitations

Reproduce it

Offline part (no GPU, no model, no network after the fetch)

The host used for the run below: Linux 7.0.0-1019-nvidia aarch64, gcc 13.3.0, Python 3. The bootstrap needs network access once, to fetch the pinned omega commit. To avoid that, point OMEGA_SOURCE at an existing checkout.

git clone https://github.com/aien-dev/omega-bridge && cd omega-bridge
sh tools/bootstrap.sh   # ends: bootstrap fixpoint RC=0, seed 191b776e...
sh tools/build.sh       # writes build/bridge and build/compiler.sha256

The fetch URL in tools/bootstrap.sh still uses the old name, https://github.com/aien-spark/omega.git. GitHub redirects it to aien-dev/omega-mv (checked 2026-11-04 with gh api repos/aien-spark/omega). The pinned commit and its hash checks do not depend on the name. This page leaves the script unchanged, because AGENTS.md asks for review before any change to the bootstrap supply chain.

Positive case. Convert tests/fixtures/fib.om to both targets and compare against the natively compiled program:

build/bootstrap/omc < tests/fixtures/fib.om > build/fib.native && chmod +x build/fib.native
build/fib.native > build/fib.native.out
tools/bridge c tests/fixtures/fib.om > build/fib.c
gcc -std=gnu11 -O2 build/fib.c -o build/fib && build/fib > build/fib.c.out
tools/bridge python tests/fixtures/fib.om > build/fib.py && python3 build/fib.py > build/fib.py.out
sha256sum build/fib.*.out

Expected: all three exit 0, print the 26 Fibonacci numbers from 0 to 75025, and have the same hash, 327ac5f5a3f39c7248466ce0c5863fb988abbed4ab983eb2ac039ad86b06fddd.

The same trap in all three. tests/fixtures/t_div0.om divides by zero. Native, C and Python all exit 102, as tests/fixtures/t_div0.want records.

A host caller. python3 tests/attachments.py converts examples/attachment.om, builds examples/caller.c with UBSan and runs it and examples/caller.py:

C caller: values, mutation, traps, invalid lengths and recovery OK
Python caller: values, mutation, traps, invalid lengths and recovery OK
attachment cases=2 failures=0 RC=0

Refusal case. tests/unsupported/five_params.om is valid Omega; the native compiler accepts it. Its function takes five scalar parameters, above the converter's four-parameter limit:

tools/bridge c tests/unsupported/five_params.om > build/five.c; echo rc=$?; wc -c < build/five.c

Expected: toc: line 1: error 24, unsupported bridge capability, rc=24, and 0 bytes of output.

Text case. tests/fixtures/text_program.om (the inherited seed text program) now converts: its text becomes static const uint8_t g0[9]={97,9,98,92,99,34,100,10,101,}; in C and immutable bytes in Python, and tests/differential.py checks both against the native program. python3 tests/text.py runs the full text suite (exact bytes, refusals, bounds, library views, compiled mutants).

Negative control on the pin. A seed with one extra byte is refused before conversion:

cp build/bootstrap/omc /tmp/omc-tampered && printf '\0' >> /tmp/omc-tampered
OMEGA_SEED=/tmp/omc-tampered tools/bridge c tests/fixtures/fib.om; echo rc=$?   # rc=65, no output

Full suite. sh tools/test.sh ends with ALL SUITES RC=0. The suite's lines include cases=113 failures=0 RC=0 (differential), refusal cases=50 failures=0 RC=0, control cases=7 failures=0 RC=0 and robustness cases=225 target_accepts=6 target_refusals=444 failures=0 RC=0. It took 19 s on the host above.

Optional parts (not needed for the recipe above)

Source map

WhatWhere
Conversion CLI and pin checkstools/bridge
Converter (front end, typed nodes, C and Python writers)src/toc.om
Seed bootstrap from pinned sourcetools/bootstrap.sh
Native, C and Python differential teststests/differential.py, text: tests/text.py
Refusalstests/refusals.py, tests/unsupported/
Host callerstests/attachments.py, examples/caller.c, examples/caller.py
Damaged-output controlstests/controls.py
Design decisionsDESIGN.md
Supported features and limitsCAPABILITIES.md
Caller ABIABI.md
ProvenancePROVENANCE.md, RECOVERY.json