interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / seed / json

c0718cd seed/json field gate: a probe's exit status is printed status=N, not rc=N Drake Stapleton committed 2026-11-13
..
tests/
README.md22100
json.om22922
jsonf.om13345
jsonw.om11308

README.md

seed/json: strict JSON reader and writer in seeded Omega

These units are part of omega-mv #788 (bounded HTTP/JSON for the private owner assistant). They are a strict RFC 8259 reader and writer written in seeded Omega (.om). No host implementation, generated code, heap, global or host word is used. They are written for the compiler pinned at befb8199db8c4bca188a494dfaac2a6f0ee5c36fcea11188c75666c55fce8a1d (omega-mv 19f014f2).

Status: EXERCISED on the host (Linux AArch64, DGX Spark) on 2026-10-26. tests/gate-json.sh printed JSONGATE PASS rows=8758 mutants=5 against compiler befb8199…a1d; see "Evidence" below. That is host evidence only. It is not a merge, a deployment, or qualification of any HTTP gateway.

FileContents
json.omReader: tokenizer and validator, tape accessors, string decoding, exact integers
jsonw.omWriter: checked JSON construction, escaping, lexeme-preserving numbers (needs json.om)
jsonf.omOptional exact binary64 conversion and shortest float text (needs both above)
tests/jsdrv.omTest driver program
tests/gen.pyDeterministic corpus and CPython oracle (test harness only)
tests/gate-json.shGate: parity, refusals, limits, mutants
tests/big.om, tests/growing.pyAbove-old-limit reader/writer/formatter driver and independent CPython oracle
tests/field.pyNative function-mode sparse uint-field edges, escape-end scans and guarded reads (test instrument)
tests/consumers.pyCompile compatibility of documented repository compositions; optional --base comparison

Composition

The units contain no om2 line, no global, no text and no host word. The caller composes them into one OM-2 program unit:

{ printf 'om2\n'; cat seed/json/json.om seed/json/jsonw.om [seed/json/jsonf.om] seed/net/http.om seed/net/notls.om app.om; } > app.full.om
nice -n 19 seed/out/omc < app.full.om > app

Arrays are caller-owned OM-2 unsized parameters (view uchar *, edit uint *). A global cannot be passed as an argument, so the input, tape and output must be locals of the caller or arrays that the caller received. The 4 MiB local-array limit of omc applies. For example, a 300 KiB body, a 65532-token tape and a 1 MiB writer buffer together use about 2.3 MiB.

Names: functions are js_*, constants js*. Locals are short lowercase names. A unit composed with these files must not define functions, globals or constants whose names collide with those names. Its own function names should also be longer than three characters.

Two limits of omc at pin befb8199 affect composition. Both were reported to the compiler owner (OmegaNext):

  • Any const makes a function-mode unit fail with error 9 at end of input. OmegaNext reports the fix as omega-mv PR #806. Until it lands, the library compiles only into a program (fn main); the gate checks it with an empty main.
  • A const defined after any fn makes a later signature that names an earlier const as an array length fail with error 16. Composed after jsonf.om, a unit that defines constants must therefore not write fs edit long jsfs in its own signatures. Pass the array to the js_* functions from the function that declares it (fs = new long jsfs 0), or write the length 2464 directly, as tests/jsdrv.om does.

Limits

LimitValueWhere
Input bytes per parse1 .. 4294967295 (jsmaxn, the 32-bit offset cell of the tape), chosen per tape at js_initrefusal 5
Nesting depth1 .. 65535 (jsdcap), chosen at js_initrefusal 4
Tokens(len tape - 16) / 4, at most 16777215refusal 11
Writer nesting1024writer refusal 25
Writer outputlen ob - 1040 byteswriter refusal 21

Until 2026-11-12 the input bound was 983040 bytes, chosen so that every loop bound stayed under the old limit 999999 of while ... bound N. omc now takes N up to 2^63 - 1, so the loops use that bound and the proof is unchanged: each parser step uses at least one distinct input byte, so the steps number at most n + 1. The input bound is now the tape format's 32-bit offset cell. What a caller can hold is set by omc: the input and tape are caller arrays (locals, at most 4 MiB per function, or parameters), because a global or a run-time pool cannot be passed as an argument (OMEGESE 9.15, error 19 / 7).

Remaining boundary for runtime input held by an Omega caller today: a source local can contain at most 4194304 bytes (the compiler's 4 MiB local-array allowance per function). Put input, tape and output in separate call frames if their sum exceeds that allowance; their combined live frames must still fit the compiler's 8 MiB program stack. Passing a pool as a view is not implemented here and remains Drake's decision. The 4294967295-byte tape-field boundary is therefore not a reachable all-Omega input-size promise. tests/field.py independently exercises actual sparse 4 GiB source views through the documented native function-mode pointer/length slots: that is host-ABI evidence, not a new Omega caller facility. Static text or native-supplied views are different constructions, not growing runtime input pools. The native test checks the inclusive field edge and refusal immediately beyond it, without scanning 4 GiB of bytes.

Sizes are checked before narrowing into the tape. A size refusal invalidates previous success/tokens and records error 5 at the configured limit, rather than trapping on the uint conversion. The internal number scanner and position-returning escape scanners use zero for failure: successful next/end positions are nonzero, so position 4294967295 is never confused with jsnone. Both writer loops consume the admitted span and stop immediately on sticky output failure, including before another source read. The decimal exponent is accumulated exactly until its magnitude exceeds the mantissa displacement plus the binary64 range; early exponent saturation cannot erase long-mantissa cancellation.

Reader API (json.om)

js_init  tape edit uint * slim ulong dlim ulong to long      0, or -13 (bad limits, tape < 20 cells)
js_parse src view uchar * tape edit uint * n ulong to long   token count, or -code (tape then empty)

js_init sets up the 16-cell header and the limits once. After that, js_parse may be called on the same tape any number of times. It parses src[0 .. n) as exactly one JSON text, optionally surrounded by whitespace. After a refusal, js_err and js_epos give the code and the byte position, and no token is visible.

Accessors take tape view uint * and return 0, or jsnone (4294967295), on a refused or uninitialised tape or an out-of-range token:

FunctionResult
js_ok tapebool: the last parse succeeded
js_ntok tapetoken count
js_err tape, js_epos taperefusal code and byte offset
js_maxdep tapedeepest nesting seen
js_dtotal tape, js_dmax tapedecoded bytes of all keys and strings, and of the longest one
js_type tape t1 {, 2 }, 3 [, 4 ], 5 key, 6 string, 7 number, 8 true, 9 false, 10 null
js_off tape t, js_span tape tsource byte offset and length. A container spans from its bracket to its closing bracket; a string includes its quotes; a number is its lexeme
js_match tape tfor a bracket, the index of the matching bracket
js_nkids tape tmembers of an object or elements of an array
js_slen tape tdecoded byte length of a key or string
js_nflags tape tnumber flags: 1 minus sign, 2 fraction, 4 exponent
js_last tape tlast token of the value at t
js_first tape tfirst key or element of a non-empty container, else jsnone
js_mnext tape kthe key after member key k, else jsnone. The value of key k is k + 1
js_enext tape ethe element after array element e, else jsnone

Each token occupies 4 cells starting at 16 + 4t. Cell 0 holds the type, the flags shifted left by 4 and the child count shifted left by 8. Cell 1 is the offset, cell 2 the span, and cell 3 holds the match for a bracket or the decoded length for a string. Tokens appear in source order. Duplicate member names are kept, in order. RFC 8259 section 4 leaves their meaning to the application.

Strings from the source:

js_sget  src view uchar * off ulong ob edit uchar * to long   decode the string at src[off]; bytes or -code (-13 short ob)
js_streq src view uchar * off ulong key view uchar * to bool  decoded string equals key bytes exactly

js_slen, or js_dmax for every string at once, gives the buffer size needed. Decoding writes UTF-8: escapes are resolved and a surrogate pair becomes one 4-byte code point.

Integers are exact. Nothing is ever rounded silently:

js_ilex src off   0 not an integer lexeme, 1 integer with |v| <= 2^64-1, 2 larger
js_isu  / js_tou  fits ulong (no minus sign) / its value (0 when not)
js_isl  / js_tol  fits long / its value (0 when not); "-0" is 0

Any other number keeps its lexeme. A caller can copy it, compare it, or write it back unchanged (js_wlex). Conversion to binary64 is an explicit opt-in (jsonf.om).

Reader refusals

js_parse returns minus the code. js_epos is the byte offset where the refusal was found.

CodeNameMeaning
1jseeofinput ended inside a value (also empty input)
2jsesynunexpected byte, including a byte-order mark, a trailing comma, a missing :
3jsetrlbytes after the root value
4jsedepan opening bracket would exceed the depth limit
5jsesizn is over the size limit (position = the limit)
6jseutfill-formed UTF-8 inside a string (RFC 3629 section 4: overlong, surrogate, > U+10FFFF, stray or missing continuation)
7jsesura \u surrogate that is not one high-then-low pair
8jsectla raw byte below 0x20 inside a string
9jseescan unknown escape or a non-hex \u digit
10jsenumnumber grammar (leading zero, 1., -, 1e)
11jsetokthe tape is full
12jselita misspelled true, false or null
13jseargbad arguments (n > len src, tape not initialised, limits out of range)

Outside strings only the four RFC whitespace bytes and the grammar's ASCII are accepted, so any non-ASCII byte there is refused as code 2. Strings are validated during the parse, and js_sget checks them again: it never trusts the offset it is given.

Writer API (jsonw.om)

The caller passes one ob edit uchar * array. Its first 1040 bytes are the writer state, and the JSON text is ob[1040 .. 1040 + js_wlen ob).

js_winit ob                       reset, 0 or -26 (ob <= 1040 bytes)
js_wobj / js_wobje / js_warr / js_warre ob
js_wnull ob, js_wbool ob b, js_wulong ob v, js_wlong ob v
js_wnumb ob s off n               s[off..off+n) must be exactly one RFC 8259 number lexeme; copied unchanged
js_wlex  ob src off               the lexeme of a parsed number token at src[off], unchanged
js_wsbuf ob s off n               a string from raw UTF-8 bytes (validated, escaped)
js_wsbeg ob / js_wsb ob c / js_wsend ob   the same, streamed one byte at a time
js_wsrc  ob src off               re-encode the parsed key or string at src[off]
js_wtok  ob src type off          write one parsed token (rewriting a whole tape in order reproduces the value)
js_wdone ob                       text length if exactly one complete value was written, else -code
js_wlen ob, js_werr ob

A string is written as a member key when the innermost open container is an object that is waiting for a key. Otherwise it is written as a value. Commas and colons are inserted automatically. Every call checks the state, so the writer can only produce RFC 8259 text. The first refused call records its code, and every call after it writes nothing.

Escaping follows RFC 8259 section 7 exactly as CPython json.dumps(..., ensure_ascii=False) does. " and \ are escaped. \b \f \n \r \t use their short forms. The other bytes below 0x20 become \u00xx with lowercase hex. Everything else, including /, DEL and all non-ASCII UTF-8, is copied unchanged.

CodeNameMeaning
21jswespoutput array full
22jswestcall not valid in this state (a value where a key is due, a second root, a key without a value, a mismatched close, an unfinished string, nothing written)
23jsweutill-formed UTF-8 in string bytes
24jswenmnot a number lexeme; infinity and NaN, which JSON cannot represent
25jswedpnesting over 1024
26jsweargbad array or slice
27jswesrcjs_wsrc offset is not a well-formed source string

Optional floats (jsonf.om)

js_f64   src off fs   -> f64     nearest binary64, ties to even; overflow +-inf, underflow +-0
js_f64st fs           -> ulong   0 finite, 1 overflowed to infinity, 2 no number lexeme at off (NaN returned)
js_fmt64 fs x         -> long    shortest round-trip text at fs[2416 ..], or -1 for inf/NaN
js_fmtch fs i         -> uchar   byte i of that text
js_wf64  ob x fs                 write it (inf/NaN refused with 24)

fs is a caller long array of jsfs = 2464 cells, about 19 KiB. The method is the arbitrary-precision decimal of Go strconv: decimal.go with its shifts, atof.go floatBits, and ftoa.go roundShortest. It uses 800 digits plus a truncation flag and is exact for every lexeme, including more than 800 significant digits and exact halfway cases. The text uses Python repr layout. Fixed notation is used when the decimal exponent x satisfies -4 <= x < 16, with .0 added to whole numbers. Otherwise the layout is d.ddde+XX.

This is deliberately not the numeric contract of serde_json 1.0.151. Its default float parser is not correctly rounded. Cortex's /tmp/cxo/cortex/om/f64.om replicates that behavior for Cortex parity and needs about 230 MB of pools. Neither its numeric contract nor its allocation is used here.

Tests

nice -n 19 sh seed/json/tests/gate-json.sh

The gate needs Linux AArch64, python3 >= 3.11, and the pinned seed/out/omc. If any of these is missing, it prints JSONGATE NOT_RUN and exits 3. It runs these steps:

  1. It checks that the library has no global, text, om2 line or host word, and that it compiles on its own with an empty main.
  2. It builds the driver tests/jsdrv.om. tests/gen.py writes a deterministic corpus (seed 788) containing the following inputs:
    • hand-written valid and invalid cases;
    • 39 refusals whose code and position are pinned (36 listed in PINNED, plus depth, capacity and gateway size);
    • the size and depth boundaries, both inclusive;
    • token capacity;
    • a 307200-byte (300 KiB) gateway chat request, which must be accepted at limit 307200 and refused at 307199;
    • about 1,900 float lexemes, including exact binary64 midpoints, midpoints plus or minus 10^-900 relative (more than 800 digits), subnormals and overflow;
    • 700 random documents with random escaping and whitespace;
    • 900 byte-level mutants of them;
    • 150 surrogate-escape documents;
    • writer scripts.
  3. Every parse case runs in four modes. The two token modes, the flat token stream and the walk through the navigation API, must both match CPython json.loads. That parse uses the C scanner with parse_int/parse_float hooks receiving exact lexemes and object_pairs_hook to keep order and duplicates. Every span, match, flag and decoded length is also self-checked. The f64 mode must match CPython float(), repr() and its bits, and the integer accessors must match int(). The rewrite must be byte-identical to a serializer built from json.encoder.c_encode_basestring with lexemes kept. Writer scripts must match pinned bytes and refusal codes.
  4. A driver input larger than its array exits 93. The 4 MiB driver distinguishes EOF, read error (90), and overflow (93), including an invalid byte appended to the full valid workflow fixture. Growth cases exercise reader, raw-string writer, number writer, token rewrite and float formatting beyond 983040 bytes. CPython float, binary64 bits and repr independently check balanced million-digit mantissas/exponents and randomized long numbers. Native sparse views check both uint-field edges and number consumers at the maximum end offset; guard pages prove exhausted output stops before reading another source byte. Escape probes also scan a real field-width string ending in a simple/Unicode escape and compare its closed control; a sparse valid writer string crosses the same next-position edge. Growth/field mutants restore each defect.
  5. Five mutants must each be caught:
    • an overlong E0 sequence accepted;
    • raw 0x1F accepted;
    • the depth limit off by one;
    • 0x1F written unescaped;
    • halfway cases rounded up instead of to even.

The oracle differs from CPython in four documented places. CPython accepts all of them, and RFC 8259 or the limits require refusing them:

  • lone surrogate escapes (RFC 8259 section 8.2: strings must be Unicode text);
  • NaN, Infinity and -Infinity, which CPython accepts by default (parse_constant refuses);
  • depth over the limit;
  • size or tape capacity over the limit.

CPython is a test-only referee, fixture generator and driver. The original corpus oracle writes no compiled implementation. The growth/field instruments compose the hand-written Omega driver/wrappers and explicit source mutants; all JSON implementation and conversion remains seeded Omega. All acceptance and mutant checks use explicit failure branches, not Python assertions. Test execution, including mprotect in the native guard probes, is never removed by PYTHONOPTIMIZE. Each Python gate accepts --wrong-expectation to make one expected result deliberately wrong; running that control with PYTHONOPTIMIZE=1 must fail. The existing corpus generator and local evidence instruments use the same unconditional-check rule. Long balanced exact midpoint cases straddle zero/min-subnormal, subnormal/normal and finite/overflow rounding thresholds, with both signs and both mantissa forms. Fixed-size callers must use a constant for their own allocation and signatures, not jsmaxn (the library format ceiling). The Node acceptance drivers use their own ndjsz declared in nodedrv.om. consumers.py compiles each concrete documented composition, including the Node drivers, benchmark chat/fake-model, agent, library variants and native probes. JSON_COMPAT_BASE=REF adds base/head compile-status parity; its manifest records exact inputs, citations and any new test application held identical across both library versions. Three width mutants must be compile refusal 23. The gate prints SOURCE, compiler/source hashes, and a final PASS naming the checkout head; retain that output from a clean committed tree as the exact-head receipt.

Driver modes and the writer-script language are documented at the top of tests/jsdrv.om. A writer script has one operation per line:

  • o O a A: object or array open and close;
  • s<hex>: a string from bytes;
  • S, b<hh>, E: a streamed string;
  • n<lexeme>: a number lexeme;
  • u<dec>, l<dec>: unsigned and signed integers;
  • t f z: true, false, null;
  • d<16 hex>: f64 bits.

Numeric constants were checked with WolframLanguageEvaluator:

  • {2^64-1, Quotient[2^64-1,10], Mod[2^64-1,10], 2^63} -> {18446744073709551615, 1844674407370955161, 5, 9223372036854775808};
  • surrogate bounds FromDigits[{"D800","DBFF","DC00","DFFF"},16] -> 55296, 56319, 56320, 57343;
  • UTF-8 lead and continuation bytes 80 C2 E0 ED F0 F4 A0 9F 90 8F BF -> 128 194 224 237 240 244 160 159 144 143 191;
  • 2^52-1 -> 4503599627370495, 2^53 -> 9007199254740992;
  • the quiet NaN FromDigits["7FF8000000000000",16] -> 9221120237041090560;
  • the scratch layout 16+3*800 -> 2416, +48 -> 2464.

Evidence

This run was on 2026-10-26, on Linux aarch64 (DGX Spark host), with Python 3.12.3. The tree was omega-mv 58d6fb6a2f72b1ab02c0eb0c01afe141303c968d with these units uncommitted on top.

ionice -c3 nice -n 19 sh seed/json/tests/gate-json.sh   -> exit 0
COMPILER befb8199db8c4bca188a494dfaac2a6f0ee5c36fcea11188c75666c55fce8a1d
SRC 456254fc754ea35103ced480407b24fc1a3896d094b90ae0e9623e7b6594e2d2 seed/json/json.om
SRC 464f649e8207495f5d67fe8795d31e42ea3ccebd9ed547274dab802d4f7c5f21 seed/json/jsonw.om
SRC bade33cef4b7edcc834c436d8499810aa573e02a97fb0dafded3736744e67a29 seed/json/jsonf.om
SRC 2f2f8ac522db876db55bca464060ab6e1071447180f51c4e53051d4ce3ddd710 seed/json/tests/jsdrv.om
gen.py 6e8169151790a07e1cca57505e0bbdce729b5b8db9ab121adbd2c0041f835985
DRIVER 15e928704eb5be7f078712c77e536940053541e245018472d58d9f9259c13778
GEN cases=2764 rows=8758
JSONGATE PASS rows=8758 mutants=5

Of the 2003 parse cases checked in mode t, 1094 were compared byte for byte and 909 were refusals checked by their ERR prefix. Pinned refusals are compared exactly. All five mutants made the parity run fail. If any of the hashes above change, this record no longer applies; rerun the gate.

Re-verified 2026-10-26 after refresh onto main c5d981041 with reseeded seed/out/omc 189ada82e00bb440cb41351bd252cc68c54a1b1050051cc42a1df700081c3b54: JSONGATE PASS rows=8758 mutants=5; gate pin updated.

Re-verified 2026-10-26 on integ/omc-batch2 with the batch 2 seed/out/omc 2c82480596bbdc50cda9626866209ef662d5834f278f839ff4ce0250c495029f: JSONGATE PASS rows=8758 mutants=5; gate pin updated. Negative controls: the 189ada82 compiler, and the old pin given through JSON_OMC_PIN, both end in JSONGATE FAIL ... differs from pin (exit 1).

Re-verified 2026-10-27 on build/omc-batch3-896-897-898-903 with the batch 3 seed/out/omc 397346de169d78e8a5ce53dce6cf9f0ca56a8f527128165bbfb4fb62a335f93e: JSONGATE PASS rows=8758 mutants=5; gate pin updated. Negative control: the 2c824805 compiler ends in JSONGATE FAIL ... differs from pin (exit 1).