Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-zip/blob/main/corpus/src/omegese65536 # omega-zip omega-zip: ZIP archive reader in seeded Omega (store and deflate, CRC-32, fail-closed refusals) Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-zip / corpus / src / omegese65536` 853 lines · 65536 bytes Raw Blame History 1 # Omegese: a program language built for the AI writer 2 3 Status: v1 (nested values, exact next oracle, 2026-10-15). Phase 1 done (language, translator, checks, token measurement); 4 phase 2 started (section 7). 5 Tool: `tools/omegese/omegese.c`; tests: `make test-omegese`. Named Glyph until 2026-10-15 (the name was 6 taken); evidence recorded before then says glyph. Home: omegese.com (owned by Drake since 2026-10-15). 7 8 ## 1. Why 9 10 exp445 (`docs/one_layer/EXP445_PROTOCOL.md`) asks AIs to write Omega programs as OSC text, as a 11 JSON op list (`tools/omega_emit/SCHEMA.md`) and as hex bytes of the binary IR. The cost and the 12 errors come from the same places: punctuation and keys (JSON), two characters per byte (hex), and 13 bookkeeping the writer must do in its head: numbered registers with declared types, numbered blocks, 14 byte offsets. Text avoids the bookkeeping but needs a compiler for a human-readable language. 15 16 Omegese keeps the machine-first path (no human source language in production) and removes the 17 bookkeeping and the punctuation. Its words are chosen from the writer model's own vocabulary. 18 19 ## 2. Design rules 20 21 1. **Efficiency metric: verified programs per unit of inference cost.** Language design optimizes 22 for verified programs produced per unit of inference cost (measured on held-out tasks by 23 first-attempt correctness, successful compilation, verified behavior, completion time, and total 24 compute cost), rather than treating single-token vocabulary as a rigid language rule. 25 Fitting fixed words into single tokens under a specific tokenizer (e.g. Qwen3 where ops, types, 26 and keywords were verified as single tokens with a leading space) is an empirical token-cost 27 consideration, not a binding constraint on the language definition. The compiler-guided interface 28 must remain portable across models and tokenizers. 29 There is no punctuation besides `=` (also one token, and optional) and the optional brackets `( )`; 30 no commas, no indentation. Values nest in prefix order (every op takes a fixed number of values), 31 so brackets are never needed. Numbers cost one token for the space plus one per digit under tokenizers 32 that split digits. 33 2. **Types are inferred.** Only parameters, the return type, conversions, typed numbers 34 (`uint 5`) and new arrays name a type. A value's type comes from the op that makes it, bottom-up 35 through nested values; a number takes the type of the other value in its op. This removes the 36 "register declared one type, written with another" error class. 37 3. **Names, not numbers.** Values are named; registers, blocks and branch targets are numbered by 38 the translator. Control is structured (`if`/`else`/`end`, `while`, `for`). 39 4. **Scope gives definite assignment.** A name first written inside an `if`, `else`, `while` or 40 `for` dies at its `end`; to carry a value out, write it before the block. So every read is 41 written on every path by construction. 42 Every name written must be read before its scope ends (parameters and loop counters excepted), so a 43 misspelled word (the short form turns `rte a` into a new name) or a forgotten value is refused. 44 No name hides a visible one (loop names included). Parameter names are distinct. Calls go to earlier functions only, with each argument checked 45 against the parameter (arrays: own from own, edit from own or edit, view from any). 46 5. **Loops are proven to end.** Every loop lowers to the shape checker2 proves terminating 47 (`src/checker2/c2_check.c`, "loop bounds"; the shape oscc emits for `while ... bound N`). 48 6. **Prefix-decidable.** After any prefix the checker knows which words may come next 49 (`omegese next`): the mask an inference engine can apply while the model writes, so an invalid 50 program cannot be written. 51 7. **Same trust chain.** Omegese -> omega_emit op list -> canonical OSC binary IR -> checker2 -> 52 signed receipt. Omegese changes nothing after the op list. 53 54 ## 3. The language 55 56 A program is one or more functions. A line holds one statement; words are separated by spaces. 57 58 ``` 59 fn ( )* to | void a function; `end` closes it 60 = write a value (a new name, or an existing one of the same type); 61 the same, with `=` left out 62 if / else / end 63 while [bound N] / end N 1..`9223372036854775807` (a number or any integer const; IR 64 mode: 1..`1000000`), default `1000000`; past N iterations: trap 4 65 for [bound N] / end name = 0 .. count-1 (count a number, or a value of that 66 type; IR mode: a number count 0..`1000000`); N as for while. With no bound a 67 number count is not guarded and any other count traps 4 after `1000000` 68 passes; with `bound N` any count traps 4 after N passes (the counter may 69 be written in the body) 70 break leave the innermost loop; outside a loop: error 9. Like ret, it ends the 71 path (a later line in the same block is error 17) 72 continue jump to the next iteration: a while's head, a for's increment. Outside a 73 loop: error 9. Like ret, it ends the path (a later line is error 17) 74 ret [] 75 put store 76 trap stop with that code (out of range: error 8). Program mode exits 100 + code; 77 function mode calls OscRt.trap. Like ret, it ends the path (a later line in 78 the same block is error 17) 79 call a function that returns nothing 80 ``` 81 82 Values are prefix expressions. Every op takes a fixed number of values, and each of those values may 83 itself be an op, so no brackets are needed: `add mul r r 4` is add(mul(r, r), 4), and 84 `eq rem n 2 0` is eq(rem(n, 2), 0). 85 86 | value | takes | meaning | IR | 87 |---|---|---|---| 88 | `` / number | 0 | copy | mov / const | 89 | `add sub mul div rem and or xor shl shr` a b | 2 | arithmetic, bitwise, shifts (shift amount any whole-number type) | bin | 90 | `eq ne lt le gt ge` a b | 2 | comparison, gives bool | cmp | 91 | `neg` a / `not` a | 1 | negate (signed) / logical not (bool) or bitwise not (number) | un | 92 | `` a | 1 | a typed number (`uint 5`) or a conversion (`ulong x`, `ulong add a b`) | const / cast | 93 | `get` arr i | 2 | load (arr is an array name) | load | 94 | `new` type len init | 3 | a new own array of len elements (omc: 1..`16777216`, at most 4 MiB of local arrays, s.9.4; the C reference path through OSC IR: 1..64, `OSC_MAX_ARRAY_LEN`); only as the whole value of ` =` | alloc | 95 | `own` / `edit` / `view` arr | 1 | move / mutable borrow / shared borrow (arr is an array name) | mov | 96 | `` args | its parameter count | call an earlier function | call | 97 98 Brackets are optional grouping: `( )` holds exactly one complete value and changes nothing 99 else (`sub diff (i64 b)` = `sub diff i64 b`). A `(` without its `)`, a `)` without its `(`, an empty 100 `( )`, or a `( )` holding more than one value is refused. `(` and `)` are separate words even when 101 written against a name. 102 103 Typing is bottom-up. A value's type comes from its op; a bare number takes the type of the other 104 value of its op (`add x 1`, `sub 15 i`, `shl 1 sh`), or the type the place needs when it stands 105 alone (`ret 0`, `x = 5` for an existing x, a call argument, an index is uint). Two bare numbers in one 106 op are refused (`add 1 2`, also when nested: `add a mul 2 3`). Comparisons give bool. In a shift a 107 bare number on the left takes the type of the shift amount (`shl 1 sh` with sh uchar shifts a uchar); 108 write its type when you mean another (`shl ulong 1 sh`). A typed number inside a conversion is 109 converted (`long int 5` is the int 5 converted to long; `uchar int 300` traps 5). 110 111 A condition is any value that gives bool (`while ne b 0`, `if or lt p -32768 gt p 32767`). Values may 112 be nested wherever a value goes: after `=`, `ret`, `if`, `while`, `put` (index and value), call 113 arguments, a `for` count, inside conversions. `and`, `or` evaluate both sides (no short cut). 114 115 A wrong number of values is refused with its place: `line 3: le has 3 values after it; it takes 2`, 116 `line 2: sub has 1 value after it; it takes 2`, `extra words at the end of the line: 'b'`. 117 118 Types: `bool uchar ushort uint ulong byte short int long` = bool u8 u16 u32 u64 i8 i16 i32 i64 119 (the IR names `u8` .. `i64` are accepted too, as the task signature writes them; they cost 2 or 3 tokens) 120 (`u32` is three Qwen3 tokens; `uint` is one). Arrays: `own|edit|view `. 121 122 Example (dev04): 123 124 ``` 125 fn gcd a uint b uint to uint 126 while ne b 0 bound 100 127 t = rem a b 128 a = b 129 b = t 130 end 131 ret a 132 end 133 ``` 134 135 ## 4. Lowering 136 137 Numbers are hoisted into the entry block, one CONST per distinct value and type (so the loop bound 138 is defined exactly once, as checker2 requires). Blocks are numbered in the order they start. 139 140 - `while c bound N`: hidden ulong counter = 0; head: c -> guard | exit; guard: `ge counter N` -> 141 trap block (trap 4, br exit) | body; the body starts with `counter = add counter 1`. 142 - `for i T K` (K a number or an integer constant, no bound): i = 0; head: `lt i K` -> body | exit; 143 latch: `i = add i 1`. IR mode refuses a number or integer-constant count outside 0..`1000000` (bound 144 or not), a minus sign included, with error 8 (the C oracle's count range), so this unguarded loop 145 is also one checker2 proves. 146 - `for i T n` (n a name or any value that is not a number), and any `for ... bound N` (omc's IR mode 147 only): as `while lt i n bound N` (N `1000000` when omitted), with the hidden guard, plus 148 `i = add i 1` at the latch. IR mode refuses N above `1000000` with error 8 (as the C oracle does), 149 so every emitted guard is one checker2 proves. 150 - `if c` -> cbr then | else-or-join; a join block exists only if some branch reaches it. 151 - Nested values: each op inside a value writes a fresh hidden register (a local with the op's type, 152 never a name, so the unread-name rule does not apply), in evaluation order: innermost first, left 153 to right (`x = add mul a b c` -> `t = mul a b; x = add t c`). Only the outermost op writes the 154 target name, after every operand has been read. Call arguments are evaluated left to right before 155 the call; a `put` evaluates its index, then its value, then stores. 156 - A typed number used as a value (`uint 5`) is the hoisted CONST itself; a bare name or number used 157 as an operand is read in place (no copy). 158 - `while`: the condition's ops are emitted in the head block, so the whole nested condition is 159 computed again before every pass. 160 - `for i T ` (a count that is not a number): a name is read at every pass (as v0); any other 161 value is computed once, before the loop. 162 - `trap N`: `trap N`, then a `ret` that is never reached (with a zero of the return type), because 163 the IR block still needs a terminator. 164 165 ## 5. Measured (phase 1) 166 167 The 10 public dev tasks (`tests/one_layer/exp445/dev`), reference solutions in each spelling, 168 tokens counted offline with the Qwen3 tokenizer (the measure.sh method: text = reference.osc; 169 bytes = hex of the compiled IR; structured = `omega_emit lift` of that IR; Omegese = 170 `tests/one_layer/omegese/dev/*.omegese`; Omegese short = the same with `=` left out). 171 172 | task | text | bytes | structured | Omegese | Omegese short | 173 |---|---|---|---|---|---| 174 | dev01 | 64 | 281 | 309 | 48 | 45 | 175 | dev02 | 60 | 256 | 286 | 43 | 40 | 176 | dev03 | 81 | 567 | 624 | 57 | 53 | 177 | dev04 | 82 | 441 | 507 | 41 | 38 | 178 | dev05 | 27 | 118 | 91 | 17 | 17 | 179 | dev06 | 27 | 112 | 91 | 17 | 17 | 180 | dev07 | 120 | 594 | 750 | 72 | 65 | 181 | dev08 | 103 | 807 | 926 | 84 | 77 | 182 | dev09 | 75 | 488 | 547 | 55 | 50 | 183 | dev10 | 22 | 98 | 79 | 15 | 15 | 184 | **total** | **661** | **3762** | **4210** | **449** | **417** | 185 186 Omegese is 9.4x fewer tokens than the structured op list and 32% fewer than OSC text, for the same 187 IR shape (all 10: harness `ola.sh experiment` set omegese-1 accepted 10/10, RUN VALID, run 188 `20261015T094000Z-`e27a33ee052d`-562014`; checker2 ACCEPT on all 10). 189 190 Limits: the Omegese programs were written by the designer, not by a model, and in places use the 191 shortest form (writing to parameters instead of copies), so the text column is not an equal-effort 192 rewrite. Whether models write Omegese reliably is not measured yet. 193 194 ## 6. The next oracle and the checks (`make test-omegese`) 195 196 ### 6.1 What `omegese next` promises 197 198 `omegese next ` reads a prefix of a program (any text, cut anywhere, even inside a word) and 199 prints what may come next. It is **exact**: an item is printed if and only if some text that starts 200 with it turns the prefix into a program `omegese emit` accepts. Nothing that can still lead to an 201 accepted program is missing (within the limits in 6.4), and nothing printed leads to a dead end. When no text can, it prints one 202 `REFUSED omegese: ...` line and exits 1: a defect in its complete words gets the reason `emit` would 203 give; otherwise (also when the word being written cannot be finished) the line says `no text after this prefix makes a program emit accepts` with the reason the 204 nearest attempt failed. 205 206 How it decides. The prefix is split into its complete lines, the complete words of the last line, and 207 the word still being written (empty after a space, a bracket or at a line start). For each candidate 208 item a witness is built: the line is finished with the words it still needs (a `ret` line also reads 209 the names the ending path would otherwise leave unread), every open block is closed (`x = x` for each 210 unread name, a `ret` of a zero where a value is owed, `end`), and the real parser that `emit` runs 211 re-reads that line and the closing lines from the state after the complete lines, with every 212 end-of-input check. An item is printed only when its witness is accepted, so every printed item is 213 legal by construction. Completeness rests on the witness finder; the test fuzz below checks it. 214 215 Names stay open at the character level. When a line binds a new name, any identifier is legal except 216 a reserved word (`omegese words` and the IR type names `u8` .. `i64`) or one equal to a visible 217 name; that is printed as one class item. When a line reads a name, the names printed are the 218 visible names (and earlier functions) of the right type and kind. 219 Numbers come as intervals: the parser only compares a number with fixed bounds (type ranges, array 220 lengths 1..64, trap codes 1..14, loop bounds and counts up to `1000000`) and with the lengths of the 221 arrays in scope, so one test per breakpoint and per gap between breakpoints decides every number, and 222 neighbouring legal pieces merge. Numbers are written as decimal digits with an optional minus sign and 223 no leading zeros; `-0` is refused by `emit` as well (it is not a number). 224 225 ### 6.2 `omegese next --machine`: the fixed grammar 226 227 One item per line, in this order, nothing else on stdout. Exit 0 with at least one item, or exit 1 228 with exactly one line starting `REFUSED omegese: `. Let U be the word still being written. 229 230 | line | meaning | 231 |---|---| 232 | `word X` | finish the current word as X (X starts with U): a fixed word, a visible name, a function, or a name written earlier on the same line (a new parameter) | 233 | `newname E1 E2 ...` | finish the current word as any new name: a letter or `_`, then letters, digits or `_`, at most 63 characters, starting with U, not a reserved word, and not one of E1 E2 ... (the visible names, functions and names earlier on the line that start with U; the list may be empty) | 234 | `number LO HI` | finish the current word as a number v with LO <= v <= HI whose decimal text starts with U | 235 | `(` | an opening bracket (it also ends the current word) | 236 | `)` | a closing bracket (it also ends the current word) | 237 | `space` | a space or tab: ends the current word, or adds blank space between words | 238 | `newline` | ends the current word and the line | 239 | `eof` | the input may end here: the prefix is already an accepted program | 240 241 A writer (an engine's mask) may append text s to the current word exactly when U followed by s is 242 still the start of some `word`, `newname` or `number` item; the soundness fuzz checks that a word 243 stays legal after each of its first characters. 244 245 Example, after `fn f a uint to uint` and a newline: `word if`, `word while`, `word for`, `word ret`, 246 `word trap`, `word a`, `newname a f`, `space`, `newline`. 247 248 ### 6.3 Human output and `omegese complete` 249 250 `omegese next` without `--machine` prints the same set for a person, one labelled line per kind, 251 empty lines left out: `assign:` (at a line start, the names that may be assigned) or `names:`, 252 `number: LO..HI, ...`, `new-name: any name not in use`, and `words:` (fixed words, functions, `(`, 253 `)`, `(space)` inside a word, `(newline)`, `(end of input)`). 254 255 `omegese complete ` prints one text that, appended to the prefix, gives a program `emit` 256 accepts (finish the word and the line, then close everything); nothing when the prefix is already a 257 program; exit 1 (`REFUSED`) when there is none. 258 259 ### 6.4 Limits (where exact can miss) 260 261 There is no over-approximation: every printed item was accepted by the real parser. An item can be 262 missed only when the witness finder fails although a completion exists, which needs one of these 263 limits: a line longer than 96 words (a witness can be longer than the shortest completion), more than 264 480 registers, 256 distinct constants or the block and frame limits in one program, more than 64 265 tries when several names of the right kind could be read, or a new name within a few characters of 266 the 63-character limit (the class is decided by one representative name). None of these is reached 267 by any program in the suite or the fuzz. 268 269 **Ownership (checker2's C2-OWN rules), folded into `emit` on 2026-10-15.** checker2 follows every own 270 array along every path (it holds an array, holds nothing yet, or was freed or moved) and rejects a use, 271 a move or a free where it holds nothing on every path (C2-OWN-USE-DEAD, C2-OWN-DOUBLE-RELEASE), and a 272 new array or a return where it still holds one on some path (C2-OWN-LEAK). `emit` keeps the same 273 states along the lines it reads and refuses such a line where it is written, so `next` leaves out the 274 word that leads there. Inside an open loop a state that includes the loop head is not known until the 275 loop's `end` line (a later line of the body can change it); such a check waits and is decided at 276 `end`. `complete` (and every witness) settles what it can: before a loop's `end` it gives a name the 277 loop head needs an array (`x = new ...`, after `free x` when the name may still hold the array an 278 earlier pass gave it) or frees one that would still hold its array there, and at the function's end 279 it frees each array that still holds one on some path (or ends the path with `trap 1` when that 280 array's name is out of scope). Since omega#465 a leak on some path is refused, so a loop that gives 281 an array a second one while it still holds the first (`x = new ...` before the loop and again in its 282 body, with no `free x` before it) leaks on its first pass, and no line after it repairs that: `next` 283 and `complete` report that no completion exists. 284 285 Measured with the residual walk in 6.5 (1000 walks from each of two starts, seed 4453): completed 286 walks that `emit` accepts and omega_emit or checker2 then rejects. 287 288 | build | rejected later | by rule | 289 |---|---|---| 290 | before (2026-10-15, ``f6b44356``) | 154 of 2000 (7.7%) | 136 C2-OWN-LEAK, 15 C2-OWN-USE-DEAD, 3 C2-OWN-DOUBLE-RELEASE | 291 | ownership states only, no loop checks | 2 of 2000 (0.1%) | 2 C2-OWN-USE-DEAD (a use in a loop head of an array freed before it) | 292 | after | 0 of 2000 | none | 293 | `emit` leak checks on some path (omega#465) | 1 of 2000 (0.05%) | 1 C2-OWN-DOUBLE-RELEASE | 294 295 Not folded, so a program `emit` accepts can still be rejected later: 296 - C2-OWN-DOUBLE-RELEASE after a branch whose condition is a constant (`if true`): `emit` follows 297 both sides, so an array freed on one side holds one on some path and `complete` frees it again; 298 checker2 follows the constant and sees the second free on every path (1 of 2000 walks); 299 - C2-BORROW-OUTLIVES-OWNER: checker2 ties each view to the array it was taken from over the whole 300 function (a view filled from two arrays loses its origin); `emit` does not follow borrows (0 of 301 2000 walks met it); 302 - C2-BORROW-MUT-ALIAS (omega#465): `emit` does not follow borrows, so a mutable view copied and used 303 beside its copy is refused by checker2 only (0 of 2000 walks met it); 304 - more than 64 own arrays in one function: the ones past 64 are not tracked; 305 - C2-OWN-ARENA-MOVE and C2-OWN-RELEASE-ARENA: Omegese has no arenas, so no program reaches them. 306 307 The other way, `emit` refuses a function with more than 256 distinct ownership checks waiting for loops to end, 308 which checker2 might accept. And where exact can miss: a waiting check whose name is out of scope (or 309 hidden by a newer name) at the loop's `end` gets no settling line, so the word that led there is left 310 out; a `ret` whose value moves the array into a call is not tried by the witness. 311 312 ### 6.5 The checks 313 314 - the 10 dev programs: omegese -> omega_emit -> checker2 ACCEPT; 315 - nested values: 6 dev programs rewritten with nested values (`tests/one_layer/omegese/nested`) and 5 316 trial 2 answers kept verbatim (`trial2`), all ACCEPT; the trial 2 isqrt answer (dev07) is still refused 317 with `line 3: le has 3 values after it; it takes 2` (it has one value too many); 318 - 8 coverage programs (IR type names, break, nested loops, else-if, a for with a name or a value as count, 319 arrays and calls, calls without values, a bool function as a condition, nested values); 320 - 46 refusals, each with its expected reason, each with a fixed control that is accepted (arity, brackets, 321 two numbers in one op, extra words, `new` inside a value, lines after trap, and 12 ownership cases: a 322 leak at a return or at a second `new`, a second free, a use after a move, an out-of-scope array at a 323 return, and five decided at a loop's `end`, one of them through a nested loop); 324 - review fixes: a conversion of a typed number converts it (`ret long int 5`, `uchar int 300`); a for 325 count in brackets lowers exactly as the bare count and has the same limit; 326 - `omegese next` on 69 prefixes and cases, red before green (the open-type list after a binary op, a typed second 327 value, a bracket waiting for `)`, a `ret` that must read the names its path leaves unread, a cut 328 inside a word, the exact number range of every scalar type and of trap codes, array lengths, loop 329 bounds and counts, a minus sign where none fits, `-0`, the `--machine` lines including the 6.2 330 example and the new-name exclusion list, `complete`, refusals as soon as a prefix is wrong, and 331 ownership: no `ret` or second free while it would be refused, `end` left out of a loop whose head 332 needs an array, `complete` settling a loop and freeing at the function's end, a loop opened at the 333 nesting limit refused, 300 uses of one array in a loop accepted); 334 - next oracle: at all 2636 word boundaries of the 75 accepted programs in the suite, the real next 335 word, and the end of input at the end, are legal; 336 - completeness: 150 single-word mutants of those programs (a word dropped, doubled, or replaced by a 337 number, a name, a fresh name or a fixed word): `emit` accepts a mutant if and only if every word of 338 it was legal when it was written (2906 word boundaries); 339 - soundness fuzz: 40 random walks of up to 25 legal items from random cut points (a number item is 340 tried at its ends and at a random value inside); the legal set is 341 never empty, a word picked stays legal after each of its first characters, and `omegese complete` 342 then finishes the walk into a program `emit` accepts within a bounded number of lines; 343 - checker2 residual: 40 walks from each of two starts (an empty file and a cut point in a suite 344 program), each closed with `complete` and sent through omega_emit and checker2; at most 345 `OMEGESE_RESIDUAL_MAX` (default 0) may be rejected there (`OMEGESE_RESIDUAL_WALKS` sets the count, 346 `OMEGESE_RESIDUAL_KEEP` a folder that keeps the rejected programs; the table in 6.4 used 1000); 347 - truncation fuzz: all 2799 byte prefixes of the nested, trial and coverage programs through `emit`, 348 `next` and `next --machine`, which must answer (accept or refuse with a reason) and never crash; at 349 the 2698 prefixes of accepted programs, `next` must also allow the byte that follows (the whole 350 word it belongs to) and `complete` must finish the prefix into a program `emit` accepts; 351 - loop guard negative control: the dev04 op list without the hidden counter increment passes 352 omega_emit and is REJECTED by checker2 (`C2-LOOP-UNBOUNDED`); 353 - tokenizer measurement: when `OMEGESE_TOKCOUNT` (a counter: ` words ...` 354 printing the token count of " word" first) and `OMEGESE_TOKENIZER` are set, records empirical token 355 efficiency across candidate vocabularies (an observational cost consideration rather than a language rule). 356 357 The same suite then runs again on a build with AddressSanitizer and UndefinedBehaviorSanitizer 358 (memory and undefined-behaviour checks), with 10 walks and one mutant per program; every sanitizer 359 finding fails the run. Its negative control: two canary builds (`-DOMEGESE_CANARY=1`, a read after 360 free; `=2`, a signed overflow) must each be caught first. Clean. A stress run with 25 mutants per 361 program (1575 mutants) and 500 walks of up to 40 items (17386 items) found no failure. 362 363 ## 7. Phase 2 364 365 1. Prompt-only trial on the dev tasks, no mask (done once, 2026-10-15): the 30B on my own engine, one 366 attempt, harness run `20261015T105049Z-`e27a33ee052d`-`1500714`` (RUN VALID): Omegese 3/10, text 3/10, 367 structured 0/10; completion tokens 1015 / 1346 / 12027. 8 of 10 first answers were refused only for 368 writing the task signature's type names (`u8`, `u32`); those are now accepted. 369 Trial 2 (same model, one attempt plus one repair round): Omegese 2/10, text 3/10. 6 of the 8 Omegese 370 failures wrote nested values (`n = add (mul (uint 3) n) 1`), which v0 refused. Values now nest (section 3): 5 of 371 those 6 answers, kept verbatim in `tests/one_layer/omegese/trial2`, now pass checker2; the sixth 372 (dev07) has one value too many and is still refused, with its place. Rerun owed. 373 2. The mask inside my own engine: `omegese next` as a table on the GPU, one lookup per token; 374 positions with one legal word need no model step. 375 3. A pre-registered held-out comparison: exp445 revision r3 (`docs/one_layer/EXP445_PROTOCOL.md` 376 section 13), Omegese against OSC text. The `omegese` arm's system prompt is 377 `tools/exp445/arms/common.md`, then `tools/exp445/arms/omegese.md` (the language and a word card: 378 every fixed word on one line with what it does), then the worked examples 379 (`tools/exp445/arms/examples/`, built by `reader.sh system_prompt`): 14 dev-style tasks in the 380 many-shot mode, the r2 single example (`clamp_sub`) in the one-shot mode (Stage 0 only). The `text` 381 arm gets the same tasks with the program in OSC. `make test-exp445` checks every example in both 382 forms (reader, back end, the sealed harness on its own inputs), that the word card is exactly 383 `omegese words`, the one-token gate on every word of the examples, and that no example shares an 384 entry name with a held-out task. 385 4. Where the r3 Stage 1 answers failed, by reader stage (config A, attempt 1, 60 held-out tasks per 386 arm; aggregate counts and refusal categories from the score output only, no task text read): 387 388 | arm | round | passed the reader | refused | where refused, by category | 389 |---|---|---|---|---| 390 | Omegese | first answer | 35 | 25 | all at `omegese emit`: type 13, structure 6, arity 4, scope 1, range 1 | 391 | Omegese | repair round | 4 | 21 | all at `omegese emit`: type 11, structure 6, arity 3, scope 1 | 392 | text | first answer | 44 | 16 | the OSC compiler | 393 | text | repair round | 5 | 11 | the OSC compiler | 394 395 No Omegese answer was refused at omega_emit, at the signature check or by the back end. Final 396 verdicts: Omegese 23 ACCEPT, 21 no candidate, 16 wrong behaviour (7 unexpected trap, 8 wrong result, 397 1 wrong trap); text 34 ACCEPT, 11 compile refused, 15 wrong behaviour (6 missing trap, 8 unexpected 398 trap, 1 wrong result). 399 What a legal-word mask (`omegese next` in the engine) prevents: every one of those Omegese refusals, 400 since each was an `emit` refusal and the mask only lets through words that some accepted program 401 continues. With the ownership rules folded in, what the mask lets through also passes checker2's 402 ownership rules, within the limits in 6.4. 403 What it does not prevent: an answer whose function has the wrong name, parameters or return type is 404 still an accepted program, so only a forced signature header (the task's `fn` line written for the 405 model) prevents a signature mismatch; none was seen, but every Omegese refusal stopped at `emit` 406 before the signature check, so mismatches could be hidden behind them. Neither prevents the 16 407 wrong-behaviour answers. The 11 text refusals would need a mask for OSC text. 408 409 ## 8. Prior art (quick search, not exhaustive) 410 411 Grammar-constrained decoding (Outlines, XGrammar, llguidance, SynCode), grammar-aligned decoding 412 (NeurIPS 2024), type-constrained decoding for TypeScript (Mündler et al., PLDI 2025), and a grammar 413 redesigned for fewer tokens (SimPy, 2024). Not found: a lexicon chosen so one terminal is one vocab 414 token, with type-aware prefix checking feeding an independently checked, signed IR. "New" is 415 UNVERIFIED. 416 417 ## 9. Systems words (seed chain om4 and omc, ledger L408) 418 419 Added 2026-10-22 for the Omega compiler written in Omegese (`seed/omc/omc.om`) and the translator that 420 first builds it (`seed/rung4/om4.s`). Every word below is used by omc or by the seed test corpus 421 (`seed/rung4/tests`); the C path (`tools/omegese`) does not read these words yet. Each rule names the 422 gate that tests it (`seed/rung4/gate4.sh`, section numbers of that script). Decisions 16-24 are those of 423 `docs/PROGRAM.md` (branch doc/program). 424 425 ### 9.1 Two kinds of output 426 427 - A program with a line `fn main` is a whole Linux program (program mode); otherwise the output is the 428 functions' machine words under the OSC-1 native rules (function mode), entry = word 0. (gate 4 s.4-6) 429 - `fn main` has no parameters and returns a whole-number type or void. The program's exit status is 430 main's value modulo 256 (Linux keeps the low 8 bits), 0 for a void main. (s.6 t_exit, s.7) 431 - A trap in program mode ends the program with exit status 100 + the trap code; in function mode it 432 calls OscRt.trap as the C path does. (s.6 t_*, s.4-5) 433 - A conditional branch (B.cond, CBZ, CBNZ) carries a signed 19-bit word displacement. A block layout 434 that needs more than 2^18 - 1 words forward or 2^18 words back (1,048,572 or 1,048,576 bytes) is 435 refused with error 24 before any output is accepted; it is never silently truncated. Unconditional 436 B uses a 26-bit field, which the 8 MiB output capacity cannot exceed. (gate 669) 437 438 An initial line `target x86linux` selects the candidate FR-9 native x86-64 Linux backend. 439 Without it, the existing AArch64 output remains unchanged. Whole-program output is a 440 static ELF64 image with Linux x86-64 syscalls. A bare x86 unit has six-byte 441 `JMP rel32`/`NOP` entry slots and uses omc's private frame ABI; it is not a SysV 442 C-callable object. In bare mode, physical R14 points to an immutable runtime 443 entry table: a trap places its code in ESI and jumps through entry 2, whose 444 landing pad recovers the wrapper stack through R12 without storing a result. 445 This is not the AArch64 register ABI. Whole-program traps still terminate with 446 `100 + code`. Explicit raw AArch64 `emit` is refused on x86 (error 25). 447 OS flag values remain target-native. 448 See [the backend design and evidence](../X86-LINUX.md) for the register map, 449 syscall adaptation, seed-chain boundaries and qualification status. 450 451 An initial line `target x86efi` selects the x86-64 UEFI backend: the same x86-64 code 452 generator wrapped in a PE32+ EFI application image with the UEFI entry/exit and Microsoft 453 x64 firmware calls. Only whole programs (`fn main`) are accepted; a bare unit is refused 454 at line 1 with error 25, and Linux host words such as `read` and `write` are refused with 455 error 25 at their line. The firmware is reached through one word, `efi` 456 (keyword id 178), recognised only under `target x86efi` (elsewhere it is an ordinary name, 457 and a call to it is error 3): `r = efi OP ARG A OFF N`, OP a literal 0..14 (a literal outside 458 0..14 is error 25, an OP that is not a literal, such as a name, is error 16), `OFF+N <= len A` 459 (else trap 3), bit 63 of the ulong result marks an error code. A trap T returns the 460 EFI_STATUS `2^63 | (100 + T)`. See [the x86efi design and evidence](../X86-EFI.md) for 461 the operations, the efi 12 file contract and qualification status. 462 463 ### 9.2 Functions and calls 464 465 - `fn` may appear many times. A names pass reads every signature before any code is written, so a call 466 names any function in the unit, earlier or later. A name that is a function never becomes a new 467 scalar: a value-returning function used as a statement is error 7, including `name = value`. 468 (s.6 r5b_fwd, r5b_assign, r5b_fwd_fm) 469 - In program mode a function may call itself, and two functions may call each other. In function mode 470 a call cycle, including a function calling itself, is error 9, so the stack a call chain uses is 471 bounded. (s.6 fib, r5b_mut, r5b_cycle, s.7) 472 - ` ` as a value calls a function that returns a value; as a line it calls a void one. 473 Using the one where the other is needed is error 7. (s.7) 474 - `to void` makes a void function; `ret` with no value returns from it, and so does reaching its `end`. 475 A function with a return type whose `end` can be reached is error 18. (s.6 t_void, s.7) 476 - Arguments are read left to right, each fully before the next. (s.5 fm5) 477 - Function names may have up to 63 characters; other names up to 8 (error 13). (s.4 dev01, s.7) A 478 function name longer than 8 characters is never a keyword, even when its first 8 spell one 479 (`continue_x`, `truncate_number`); a name that is exactly a keyword is error 16. (s1 kw-long-names) 480 - A function has at most 6 parameters; a seventh is error 9. `main` has none (error 9). A new name 481 may not reuse a name already in scope, a function or a struct: error 10. 482 - In program mode the stack is a fixed 8 MiB pool; a call or a local array that would go below it traps 483 6 before it writes anything. (s.6 t_stack) 484 - omc sets no recursion depth limit of its own; only the 8 MiB stack bounds it. A program that takes 485 input-driven recursion bounds it itself, checking the depth before the call, as 486 `seed/omc/tests/recursion/nest.om` does: depth 16 accepted, depth 17 refused with status 40 before 487 any frame for it exists, plus a work bound (fuel, status 42). (`seed/omc/gate-recursion.sh`, #645) 488 489 ### 9.3 Numbers (decision 19: one meaning per word and width) 490 491 - Unsigned add, sub, mul, shl, neg, not wrap modulo 2^width (uchar 8, ushort 16, uint 32, ulong 64 bits). 492 (gate 3, s.4) 493 - Signed add, sub, mul, neg, div and shl trap 1 when the exact result is outside the type (byte 8, 494 short 16, int 32, long 64 bits), including the minimum divided by -1. (s.5 fm1-fm4, fm9) 495 - div and rem trap 2 when the divisor is 0. Signed div rounds toward zero; signed rem has the sign of 496 the dividend, and the minimum rem -1 is 0. (s.5 fm1, fm2, fm9) 497 - A shift amount outside 0 .. width - 1 traps 7, for every type. shr of a signed value keeps the sign. 498 (s.5 fm3, fm4) 499 - A conversion ` v` traps 5 when the value is outside the new type. (s.6 t_conv) 500 - There are no implicit conversions (decision 20): the two values of an op, a value and the name it is 501 written to, an argument and its parameter, all have the same type, or the line is refused (error 7). 502 A bare number takes the type the place needs. `uchar` is an 8-bit unsigned number, never a character. (s.7) 503 - A number is written in decimal, with a `-` in front when negative, in at most 20 digits; it must be a 504 value of the type it takes: -2^63 .. 2^63 - 1 for long, 0 .. 2^64 - 1 for ulong, and so on (error 8 505 outside; more than 20 digits, or a character that is not a digit, is error 6). (s.6 t_u63, t_u64max, 506 t_cmp_unsigned, t_conv_sign, t_write_wrap, s.7) 507 - `true` and `false` are the bool numbers 1 and 0. (s.6 t_loop) 508 509 ### 9.4 Arrays (decisions 16, 17, 18, 23, 24) 510 511 - Every array has a fixed element type (uchar .. long, never bool) and a fixed length written as a 512 number; the length travels with the array's name, never as a terminator byte. An array parameter or 513 a pool written without its length is refused (error 16). (s.7) 514 - `global NAME T N`: a pool of N elements (1 .. `16777216`), all 0 when the program starts, in the 515 program's own memory image (no heap, no allocation call); at most 1 GiB of pools, else error 23. 516 Program mode only (error 9). (s.6 echo, bytecopy, s.7) 517 - `text NAME "bytes"`: a read-only array of uchar holding the bytes between the quotes, with its 518 length; `\n` is 10, `\t` is 9, `\\` is 92, `\"` is 34; any other escape, or a quote missing its end, 519 is error 22. An empty text `""` is a sized array of length 0: `len` is 0, a number index is error 21, 520 a run-time index or `part`/`write` past 0 traps 3, and as a `view` argument its count is 0. Program 521 mode only. (s.7) 522 - `NAME = new T N v`: a local array of N elements, each v, on the stack, given back when the function 523 returns. Only in a function's outermost block (error 9); at most 4 MiB of local arrays (error 23). 524 There is no `free`: nothing is given back by hand (decision 24), and the word is refused (error 9). 525 (s.5 fm7, fm8, s.6 sort, s.7) 526 - A parameter `NAME view T N` or `NAME edit T N` takes an array of exactly that type and length (error 7 527 otherwise). A view is read-only; `put`, `read` into it, or passing it as edit is error 20. A text is 528 read-only in the same way. (s.7) 529 - An argument is a local array or an array parameter, optionally after `view` or `edit`. A global is 530 never passed (error 19), and the arrays of one call are distinct names (error 19); so two live 531 references in one function are always distinct storage, and no write is ever seen through another 532 name. (s.7) 533 - `get A i` reads element i; `put A i v` reads i, then v, then writes. `len A` is A's length as a ulong. 534 A number index must be inside A when om4 reads it (error 21); any other index is checked when it runs 535 and traps 3 when it is not below the length (a negative signed index traps too). There is no word that 536 turns an array into an address or adds to one. (s.5 fm8, s.6 t_bounds, s.7) 537 538 ### 9.5 System calls and lines 539 540 - `read fd A off n` and `write fd A off n` (fd int, off and n ulong) move n bytes between the open file 541 fd and A's elements off .. off + n - 1 with the Linux read and write calls, and give a long: the bytes 542 moved, or minus the Linux error number. They trap 3 unless n <= len A and off <= len A - n, before the 543 call. `read` needs a writable array (error 20). A must be an array of uchar for the counts to be bytes. 544 `pread fd A off n pos` / `pwrite fd A off n pos` (pos long) do the same at an explicit file position 545 without changing the descriptor's offset, with the same slice checks and result. Like `read`, `pread` 546 needs a writable array (error 20); `pwrite`, like `write`, also takes a text or a view. (s.6 echo, 547 bytecopy, t_rw; s4 v-bad-pread-text, v-pwrite-text) 548 - `exit v` (v int) ends the program with status v modulo 256. Like `ret`, it ends the path: a line after 549 it in the same block is error 17. (s.6 t_exit, s.7) 550 - `note ...` is a line the translator does not read beyond its first word. (s.6 sort, fib) 551 552 ### 9.6 Capacities (decision 23) 553 554 Input over a capacity is refused with error 14, never overrun: om4 reads at most 8 MiB - 1 bytes and 555 writes at most 8 MiB, 1024 names in scope, values nested 1024 deep, 4096 functions, 8192 trap sites per function, 512 nested 556 blocks. A function that needs more than the 16 registers it hands out is error 12. omc keeps the same 557 input, output, nesting, trap-site, block and function limits but holds 8192 names in scope and 558 524288 call sites per unit (`seed/omc/gate12.sh`, `gate15.sh`), so whole programs such as an 559 interpreter fit in one unit; om4 itself keeps its own smaller name and call tables. om4's function 560 table (512 entries through om4 ``d0da40e4``) bounds `seed/omc/omc.om` itself, which om4 must compile; 561 `seed/rung4/gate4.sh` section 7b checks 4096 accepted and the 4097th error 14. 562 The candidate `target x86linux` backend has a 16 MiB output pool because native 563 x86 instruction sequences can require more bytes than their AArch64 counterparts. 564 The AArch64 output ceiling remains 8 MiB; input and frontend limits are unchanged. 565 An exhausted target output pool still refuses with error 14. 566 A single AArch64 conditional branch span is limited to 2^18 - 1 words forward or 2^18 words back 567 (section 9.1); a larger span is error 24, even when the input and output pools still fit. 568 569 ### 9.7 Structs (omc only, rung 6) 570 571 om4 does not grow for this. A struct program is refused by om4. omc.om does not use these words, so 572 om4(omc.om) stays equal to omc(omc.om). Checked by `seed/omc/gate6.sh`. 573 574 - `struct Name field type [len] ... end`, one line, before the first `fn`. 1 to 16 fields, at most 16 575 structs, at most 64 cells (error 14 over that, error 16 if empty, error 4 if the line ends before `end`). A field is a name 576 and a scalar type; a number after the type is an array field of that length (1 .. 64). Every field 577 is one or more 8-byte cells, in order, no padding. (gate6 t7, t8, t9: a wrong scale overlaps a 578 neighbour and changes the result; the expected results are 1, from the layout, not from this compiler) 579 - The struct's name is a word from that line on. No function, variable, or field may be spelled the 580 same (error 10). Field names are unique in their struct (error 10). A variable may share a field's name. 581 - `p = new S v1 .. vn`, only as the whole of an assignment, and only in the function's outermost block 582 (error 9 inside `if` / `while` / `for`). One value per field; an array field takes one value, stored 583 in every element. The cells are a stack slot, 16-byte aligned, given back when the function returns. 584 There is no `free` (decision 24); the word stays error 9. (gate6 t1-t6, still_free, new_in_if) 585 - `get p f` reads a scalar field. `get p f i` reads an element of an array field. `put p f v` and 586 `put p f i v` write. A view cannot be written (error 20). An unknown field is error 3. A number index 587 outside the field is error 21; any other index is checked when it runs and traps 3, as for arrays. 588 - A parameter is `p view S` or `p edit S`. A call passes an own or edit struct to edit, and any struct 589 to view, always of the same struct (error 7 otherwise, error 20 for a view passed to edit). The 590 structs of one call are distinct names (error 19). A function does not return a struct. 591 - `len` of a struct is refused (error 7). `read` and `write` of a struct are refused (error 7). 592 593 ### 9.8 Break, continue and trap (omc only, gate7) 594 595 `break`, `continue` and `trap` are the path-ending statements §3 lists. omc implements all three; 596 om4 refuses them, so they are omc-only like structs. Checked by `seed/omc/gate7.sh`; it is run by 597 `seed/host/check.sh`. 598 599 - `break` scans the open blocks for the innermost loop (kind 3 while, 4 for), emits an 600 always-taken `B.AL` to that loop's exit and records the word. When the loop closes, `s_end` 601 patches only the entries recorded for that block and marks them spent, so a later loop that 602 reuses the block slot cannot move an earlier break. Outside a loop it is error 9. Like `ret`, 603 the line ends the path: a later line in the same block is error 17. At most 1024 break sites 604 per function (error 14 over that), reset when the function ends. (gate7 w1, f1, n1-n3) 605 - `continue` finds the innermost loop the same way, but its recorded branch is patched to the loop's 606 latch, not its exit: the head of a while, so the condition and the bound count run again, or the 607 increment of a for, so the counter still advances. Outside a loop it is error 9; a later line in the 608 same block is error 17; at most 1024 sites per function (error 14). (gate7 c1-c5, bad_continue, 609 bad_after_continue) 610 - `trap N` takes a decimal number 1..14 (error 4 when the line ends, 16 when the token is not a 611 number, 8 out of range). It emits the same always-taken branch the runtime trap checks use; 612 `finish` makes one stub per code, so program mode exits 100 + N and function mode calls 613 `OscRt.trap`. The line ends the path (error 17 for a later line in the same block). 614 (gate7 t1, t2, bad_trap0, bad_trap15) 615 - None of the three may be a name; all are reserved from the keyword table. (gate7 om4 refusal) 616 617 618 ### 9.9 Floating point (omc only, gate8) 619 620 The words are `bitcast`, `fsqrt`, `fabs`, `fmin`, `fmax` and `fma`, not `bits`, `sqrt`, `abs`, `min` and 621 `max`: the benchmark corpus uses those shorter spellings as ordinary identifiers, and a keyword may 622 not take a name that existing `.om` code already uses. gate11 pins both halves of that rule. 623 624 `f32` and `f64` are IEEE-754 binary32 and binary64. A float value is its bit pattern held in an 625 ordinary integer register or its SIMD twin; arithmetic runs one scalar FP instruction. 626 FPCR is never written: under the Linux default it is round to nearest even with subnormals kept. 627 Ordinary `mul` then `add` stay separate operations and round separately; only explicit `fma` fuses. 628 There is no implicit conversion: mixing f32 and f64, or float and integer, without a conversion 629 is error 7. 630 631 - Literals: `digits.digits[(e|E)[+|-]digits][f32|f64]`; a digit must be present on both sides of the 632 dot, and a leading `-` negates. A literal with no suffix takes its type from context exactly as an 633 integer literal does; where no context gives a float type it is error 11. An integer literal where 634 a float is expected (assignment, `ret`, argument, `put`, `new` fill) is error 7; write `f64 1` or 635 `1.0`. The decimal text is converted exactly: digits times a power of ten is held as an exact 636 quotient of two integers, long division gives a 64-bit significand and the remainder gives the 637 sticky bit, then the value is rounded once to nearest even: 0.1f64 is 0x3FB999999999999A and 638 6816.`702656e`-27 is 0x3B207B55A6D4A130. The full binary32 and binary64 range is covered, including 639 subnormals (5e-324, 1e-45; 2.`4703282292062328e`-324 is 0x1) and signed zero. A literal that 640 rounds to infinity is refused (error 8); one at or below half the smallest subnormal rounds to signed 641 zero. The significant digits must still fit in 2^63-1 (error 8 beyond that). (gate8 f64_bits, 642 f32_bits, lit_round, neg_int_*, neg_ambiguous, neg_dot, neg_overflow, neg_overflow2, 643 neg_overflow3; `seed/omc/float-lits.py diff OMC N SEED` is the randomized differential) 644 - Operators: `+ - * /` and unary `neg`; comparisons `eq ne lt le gt ge`. Bit operators, shifts and 645 `rem` on a float are error 7. IEEE results: division by zero and overflow give infinity, 0/0 gives 646 NaN, and no float operation traps. NaN compares false everywhere except `ne`, which is true. -0.0 647 compares equal to 0.0; `bitcast` exposes the sign. (gate8 arith, compare) 648 - Intrinsics `fsqrt x` and `fabs x` take one float; `fmin a b` and `fmax a b` take two of one float 649 type and follow FMINNM/FMAXNM (IEEE minNum/maxNum: one quiet NaN returns the other operand; -0.0 650 orders below +0.0). A bare integer operand is error 7 and an unresolved literal is error 11. 651 (gate8 intrinsics, neg_intr_*) 652 - `fma a b c` multiplies `a` by `b` and adds `c` with **one rounding of the exact combined result**. 653 All three operands must have the same explicit f32 or f64 type (error 7 otherwise; an unresolved 654 decimal literal is error 11). AArch64 emits one scalar FMADD; its IEEE/Arm FPMulAdd behavior follows 655 FPCR, including subnormals, infinities, signed zero, quieting signaling NaNs and invalid operations 656 such as zero times infinity. NaN payload selection is Arm's rule, not a host-library rule. 657 In particular `(1+2^-52)*(1-2^-52)-1` is `-2^-104` for f64 rather than the zero from separately 658 rounded multiply and add. x86linux and x86efi refuse a well-typed `fma` with error 9: their SSE2 659 baseline does not provide a fused instruction, and no unfused fallback is permitted. The operands 660 are typed first, so errors 7 and 11 have the same line and code on every target. IR mode refuses 661 float words with error 3. (gate8 fma, neg_fma_* on AArch64, x86linux and x86efi; gate-fma 662 wrong-opcode, unfused and rounding mutants) 663 - Conversions ` value` handle int<->float, f32<->f64 and float->int. Int to float is SCVTF/UCVTF 664 (round to nearest even); float to int is FCVTZS/FCVTZU (truncate, saturate, NaN -> 0); f32<->f64 is 665 FCVT. `bitcast T value` reinterprets a value of the same width (f32/i32/u32, f64/i64/u64, and 666 i8/u8, i16/u16 between integers) without changing its bits; any other width or a bool is error 7. 667 The result is an ordinary value of T: `bitcast int uint `4294967295`` equals -1 and 668 `bitcast uint int -1` equals `4294967295`; an 8/16/32-bit integer or f32 is extended again for T into 669 a new register, so the source name keeps its value (omc `2c824805` kept the source's extension). 670 (gate8 convert, bitcast_int, neg_bitcast_width) 671 - Floats are allowed in `global` pools, `new` arrays, parameters, returns and struct fields. 672 Arrays are packed by element type: f32 occupies four bytes and f64 eight (`tlog` and `sa_arr` 673 in `seed/omc/omc.om`). Struct fields retain eight-byte cells, including f32 in the low half. 674 A float cannot index an array or be a `for` count 675 (error 7), `read`/`write` still need a uchar array (error 7), and IR mode refuses float words 676 (error 3). (gate8 arrays, globals, params, structs, neg_*) 677 678 679 ### 9.10 Grouping parentheses (omc only, gate9) 680 681 `(` and `)` are separate words even when written against a value (`(int 2)`, `((7))`); the lexer 682 splits them out of the surrounding word. A group returns exactly the value inside it and adds no 683 code. A group whose only value has no type is still ambiguous (error 11), and a group missing its 684 `)` is error 16. Checked by `seed/omc/gate9.sh`, which `seed/host/check.sh` runs. 685 686 687 ### 9.11 Layout queries (omc only, gate10) 688 689 `sizeof T` is the size in bytes of a scalar type (bool 1; uchar/byte 1; ushort/short 2; 690 uint/int/f32 4; ulong/long/f64 8). `sizeof S` is a struct's size: 8 bytes for each of its cells. 691 `offsetof S f` is the byte offset of field `f`; an array field gives its first element. Both are 692 compile-time constants of type ulong and add no code, so they compose in expressions. 693 694 An unknown type name is error 16, an unknown struct or field is error 3, and `sizeof void` is 695 error 9. Checked by `seed/omc/gate10.sh`, which `seed/host/check.sh` runs. 696 697 698 ### 9.12 Constants (omc only, gate16) 699 700 `const NAME TYPE LITERAL` at top level defines a named value before use. `NAME` is at most 701 8 characters and may not collide with a visible name, a function or a struct (error 10); the value 702 must fit the type (error 8). The constant is a typed number: an integer (`uint 5`, `long -3`) or a 703 float literal (`f64 0.1`, `f32 0.1`); an integer literal under a float type is refused (error 16). 704 It composes wherever a value goes, including inside functions and as a call argument, and it cannot 705 be assigned (error 7). In IR mode an integer constant is folded to its literal, including as a 706 `trap` code, a `while` bound, or a `for` count; a float constant there is refused (error 9), as are 707 struct/global/text declarations. Definitions are sequential, so a 708 constant defined after a function is not visible to that function. 709 710 A constant needs no program image, so it is also accepted in function mode (a unit without 711 `fn main`): every read folds to the typed number, and the function words are byte for byte those of 712 the same unit written with the literal (gate16 `fm_*`: value, negative value, parameter and `new` 713 length, `while` bound, `trap` code, `for` count, two functions, f64). A `global` or `text` in a 714 function-mode unit is still error 9 at the end of the input, with or without constants beside it, 715 and a host word is still error 9 at its line (gate16 `fm_global`, `fm_text`, `fm_host_word`). 716 717 An integer constant is also accepted as an array length in `new`, `global`, a parameter declaration 718 (`view T N` / `edit T N`) and a struct field length (1..64, error 14); a float constant used as a 719 length is error 16. A length token that is a name other than an integer constant is error 16, and 720 `arrlen` still enforces 1..`16777216` for arrays (errors 8 and 23). Signatures are pre-scanned, so a 721 constant used in a parameter length must be defined before that function. 722 723 An integer constant is also accepted as a `trap` code (1..14) and as a `while ... bound` or 724 `for ... bound` count (1..`9223372036854775807`; 1..`1000000` in IR mode); a `for` count is an ordinary value, so a constant 725 works there too (0..`1000000` in IR mode). Out-of-range values keep error 8, and a float constant in any of these positions is 726 error 16. 727 728 ### 9.13 Profile OM-2 (omc only, `spec/omegese-om2.md`, ledger L834) 729 730 OM-2 is opt-in per unit; the contract `spec/omegese-om2.md` and its errata are normative, and this 731 section lists what omc implements of it. Fixtures, expected results and compiled mutants: 732 `seed/omc/om2/` (run by the #748 gate `seed/qualification/om2/gate.om`). Every OM-1 unit keeps its 733 meaning and, for the C2 manifest, its exact output bytes or error. 734 735 - **Opt-in.** Leading blank lines and `note` lines are skipped; when the next line is exactly `om2`, 736 `om2 diag` or `om2 fmt` (no other bytes on it) the unit is OM-2. Any other line leaves the unit OM-1, 737 where the `om2` line itself is error 16 as before. The words of this section are reserved only in an 738 OM-2 unit: `rotr rotl unroll inline fresh abstract seal open holds layout field at little big part out 739 export ops dit scrub`. Using one as a name there is error 16; an OM-1 unit keeps them as ordinary names. 740 - **`om2 diag`.** After the human line `omc: line N: error E` (unchanged), stderr gets one record 741 `omc-diag 1 code=E sev=S line=N col=C span=A-B expect=K found=H obligation=O profile=OM-2`. `line` is 742 the human line. `A-B` is the half-open byte span of the token being read (the LF for a line that ends 743 too early; `len-len` at the end of input) and `col` the 1-based byte column of A on its line. `found` is 744 the span's bytes in hex (at most 32 bytes), `-` when empty. `expect` is the class being read: `number` 745 for errors 6 and 8, `end` for error 15, `name` for an unknown name, otherwise `value`, `type`, `name`, 746 `newline` or `word` from the reader that failed. `sev` is `unknown` for an undeclared function or struct 747 (errors 3 and 13 at a call or `offsetof`; error 16 for an undeclared word where a type or struct is 748 read, as in `new Pt` or `p view Pt`), `incomplete` when the failure is on the end-of-input token or 749 in a text cut by the end (except the call-cycle error 9), else `error`. `obligation` is `bounds` (21), 750 `growth` (14), `regs` (12), `init` (27), `ctor` (28), `layout` (29) or `-`. 751 - **Hex literals.** `0x` and 1..16 digits `0-9a-f` is the unsigned value and takes the type the place 752 needs under the decimal range rule (error 8 outside; `int 0xffffffff` is error 8). A `-` before it, `0X`, 753 no digits, more than 16 digits, an uppercase digit, `_` or any other character is error 6. 754 - **`om2 fmt`.** Only when the input's first line, at byte 0, is `om2 fmt` (error 16 elsewhere). The rest 755 (the bytes after the first LF) is compiled as a unit of its own, OM-1 or OM-2 by its own first line; 756 if it is refused, the error is reported against the whole input and nothing is written. If it is 757 accepted, stdout gets its canonical text: note lines and text literal bytes exactly as written; the 758 indentation as written; each other run of blanks between words one space, except next to `(` or `)` 759 where it is kept; no blanks at a line end; a whitespace-only line empty; one LF after the last line. A 760 CR anywhere and blank lines at the end are error 6. fmt never adds or removes a line, is idempotent, 761 and compile(fmt(x)) is byte-identical to compile(x). 762 - **Rotate.** `rotr x n` and `rotl x n`: x and n of one unsigned type (uchar, ushort, uint, ulong; else 763 error 7), the result x's type. n outside 0..w-1 traps 7 at run time, a number n included. uint/ulong 764 with a number n give one `ROR` (immediate, EXTR); otherwise the amount check, then `RORV` (rotl through 765 `NEG`). uchar/ushort replicate the value into a 32-bit pattern, rotate it, then truncate. 766 - **Unroll.** `for i T K unroll`: K a number 1..64 (error 8 outside; a name or other value is error 16). 767 The body is compiled K times with `i` the constant 0..K-1 (a write to it is error 7). `break` or 768 `continue` whose innermost loop is the unrolled one is error 9; inside a rolled loop in the body they 769 work as usual. No loop branch or counter is emitted. Removing `unroll` leaves behaviour unchanged. 770 - **Inline.** `fn NAME ... to T inline`: every call is compiled in place. Arguments are read left to 771 right as for a call; a scalar argument in a named register is copied, one in a temporary is used as it 772 is. The caller's locals are hidden from the body, and `ret` becomes a branch to the body's end (a last 773 one is dropped). The standalone function is still emitted. `new` in it, or an inline function reached 774 again while it is being inlined (itself included), is error 9; so is an inline function that reaches 775 itself anywhere in the call graph, through non-inline calls too (checked at the end of the input). A 776 fifth nested inline level is error 14. Calls to other functions stay calls. Removing `inline` leaves 777 behaviour unchanged. An argument that is a number is copied to a register, so folding does not reach 778 through parameters. 779 - **Folding and checks.** Only inside an unrolled or inlined body, an operation (`add` .. `shr`, 780 comparisons, `rotr`/`rotl`, `neg`, `not`) on two typed numbers is computed with OM-1 arithmetic. One 781 that would trap (signed overflow, a divisor 0, an amount at or above the width) is not folded and keeps 782 its runtime trap. Conversions are never folded. A number index into a sized array is checked when it 783 is compiled (error 21), as in OM-1, and in an OM-2 unit up to 4095 it is an immediate offset (LDR/STR 784 unsigned offset) with no runtime check. Every other index keeps its runtime check. 785 - **Bounds.** At most 65536 emitted words per function after unrolling and inlining, 64 copies per 786 unrolled loop and 4 inline levels (error 14, `obligation=growth`). 16 registers stay the limit 787 (error 12, `obligation=regs`). Expansion fuel (E14, E16): each function has 65536; an unrolled loop is 788 charged K when it starts, at its line, before any copy expands, and an inline expansion 1 at its call 789 line, in emission order at every nesting depth (nested unrolls multiply). The charge that takes the 790 total above 65536 is error 14 (`growth`) on its line; exactly 65536 is allowed. So two nested 64-copy 791 unrolls (4160) compile and three do not. An inline function's standalone body is compiled with its own 792 fuel where it stands in the source. The inline call graph keeps each edge once. 793 - **Trap sites.** With `om2 diag`, an accepted unit's stderr gets one `omc-site 1 line=N iter=k` record 794 per runtime trap site, in emission order: N the source line, k the counters of the open unrolled loops 795 outer to inner joined by `.`, or `-`. stdout is unchanged. 796 - **External layout.** `layout NAME SIZE`, then one line `field F T [COUNT] at OFF little|big` per field 797 (note lines allowed), then `end`, at top level before the first `fn`. NAME and F at most 8 bytes and not 798 OM-2 words; NAME is a new name (error 10), F unique in its layout (error 10); T an integer type 799 (`uchar` .. `long`; else error 7). SIZE outside 1..4096 or a `layout` after the first `fn` is error 29 800 on the layout line; a COUNT outside 1..4096, an OFF or field extent past SIZE, or a byte shared with an 801 earlier field is error 29 on the field line (`obligation=layout`). No COUNT is a scalar field (E5). 802 A parameter `c view NAME` / `c edit NAME` is a `uchar` array of exactly SIZE bytes (another array is 803 error 7; ABI: one pointer). `get c F` / `get c F i` and `put c F v` / `put c F i v` load / store the field 804 at OFF + i * width with its width and byte order (unscaled register-offset LDR/STR, REV16/REV for 805 big; signed fields sign-extended). The index is checked like an array's: a number outside COUNT is 806 error 21, a run-time one traps 3. A missing index on an array field is error 4, an extra one on a 807 scalar field error 5, `put` through a view error 20. Any other word after `c` reads it as the plain 808 `uchar` array (`get c i`, `len c`, passing it on). Structs (9.7) are unchanged. 809 - **Fresh scratch.** A parameter `s edit T N fresh` (N at most 64, else error 14 `obligation=init`; on 810 a view error 16) has unspecified incoming elements. omc tracks, per such array, which elements are 811 definitely written on the path being compiled: a `put` with a number index (after unrolling, 812 inlining and folding) marks its element; a `get` with a number index needs that element, any other 813 `get` all N (else error 27, `obligation=init`, on the get line). An if without else, a while and a 814 rolled for leave the set as it was when they opened (no induction); an if/else keeps the elements 815 written in both arms, or in the arm that does not end in `ret`; an unrolled or inlined body keeps 816 what it wrote. Passing the array to a non-inline call, `read`, `write` or a host operation is error 817 27 on that line; an inline callee works on the same set, and its own `fresh` parameter starts empty. 818 At most 16 fresh arrays per function, inline ones included (error 14). The generated code is unchanged. 819 - **Abstract types.** `abstract NAME T [ops W ...]` (T `uint` or `ulong`, else error 7; W from `rotr rotl 820 and or xor`, else error 16) and `holds NAME dup32`, at top level before the first `fn` (error 9 after 821 it). NAME is a type distinct from T. A value of it is made only by `seal NAME v` (v of type T) in the 822 function named NAME followed by `mk` that returns NAME, inlined or not; a `seal` anywhere else is 823 error 28 (`obligation=ctor`) on its line. `open v` gives the T value. A T value or a number where NAME 824 is needed, a conversion, comparison or any operation on it not listed by `ops`, an array or struct 825 field or `const` of it, `sizeof`/`bitcast` of it, and NAME as a parameter or result of the entry of a 826 function-mode unit are error 7. Listed operations run on T and give NAME: `rotr`/`rotl` of NAME by a T 827 count (E9; 64 traps 7), `and`/`or`/`xor` of two NAME values. `holds NAME dup32` (ulong only; any 828 other predicate, or a uint NAME, is error 28 on the holds line) makes every seal check high32 == 829 low32 at run time (LSR, CMP UXTW, B.NE trap 10), except when the constructor's body is exactly the 830 line `ret seal NAME or shl ulong x 32 ulong x`, x a uint parameter, then `end` (the check is erased, 831 rule `dup32`: uint values are held zero-extended). With `om2 diag` each seal compiled writes 832 `omc-check 1 kept|erased line=N rule=dup32|-` (N the seal line) with the omc-site records. 833 - **Unsized views.** A parameter `NAME view T *` / `NAME edit T *` takes an array of element type T of any 834 length (error 7 for another type): a sized array (E2, also on internal functions), an unsized one or a 835 text (view only). `len NAME` is its run-time count, a ulong value. Every index into it, a number too, 836 is checked at run time against the count (CMP, B.HS trap 3; no error 21, no elimination); `read`, 837 `write`, `pread`, `pwrite` and the host words keep their slice checks against the count. An unsized 838 array never goes to a sized parameter (error 7); view / edit rules, distinct names (19) and fresh (27) 839 are as for sized arrays. `new` stays sized; `fresh` needs a length (error 16). 840 - **Parameter slots.** Parameters take x0..x5 in order, in both modes: an unsized view or edit two slots 841 (pointer, then count), every other parameter one (a scalar, a sized array, a layout or a struct by its 842 pointer). A parameter that needs a seventh slot is error 9 on the fn line. 843 - **Part.** `part A o k` (o, k ulong; another type is error 7), only as an argument for an unsized 844 parameter of a call (a sized parameter is error 7; anywhere else, `read`/`write` included, error 9), is 845 the k elements of A from o. A is a name: a local, a view, an edit or a text (a global is error 19, a fresh 846 array error 27). o is read, then k, then the checks run in this order: o <= len A, then k <= len A - o 847 (CMP, B.HI trap 3; the wrapped o + k is never formed). The callee gets A + o * size and count k. A part 848 of a local or an edit is an edit, or a view with `view` in front; a part of a view or a text is a view 849 (to an edit parameter error 20). For distinct names a part is its base A: A and a part of it, or two 850 parts of A, in one call are error 19 whatever the ranges. 851 - **Out.** A parameter `NAME out T N` (N a length; `*` or `fresh` is error 16) is written by the unit; 852 the bridge owns the buffer and copies it out after status 0 (spec 6, E1). Inside the unit it is an edit 853 of T N in one slot (its pointer): `get`, `put`, passing it on as an edit; a view or an array of ano