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-mv/blob/main/docs/one_layer/OMEGESE.md # 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 Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / docs / one_layer / OMEGESE.md` 1899 lines · 143992 bytes Raw Blame History Rendered 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 (128 MiB): omc's AArch64 output stops at `134217728` bytes (error 14 at its first 437 byte past them, section 9.6), so every B and BL stays in reach. (gate 669) 438 439 An initial line `target x86linux` selects the candidate FR-9 native x86-64 Linux backend. 440 Without it, the existing AArch64 output remains unchanged. Whole-program output is a 441 static ELF64 image with Linux x86-64 syscalls. A bare x86 unit has six-byte 442 `JMP rel32`/`NOP` entry slots and uses omc's private frame ABI; it is not a SysV 443 C-callable object. In bare mode, physical R14 points to an immutable runtime 444 entry table: a trap places its code in ESI and jumps through entry 2, whose 445 landing pad recovers the wrapper stack through R12 without storing a result. 446 This is not the AArch64 register ABI. Whole-program traps still terminate with 447 `100 + code`. Explicit raw AArch64 `emit` is refused on x86 (error 25). 448 OS flag values remain target-native. 449 See [the backend design and evidence](../X86-LINUX.md) for the register map, 450 syscall adaptation, seed-chain boundaries and qualification status. 451 452 An initial line `target x86efi` selects the x86-64 UEFI backend: the same x86-64 code 453 generator wrapped in a PE32+ EFI application image with the UEFI entry/exit and Microsoft 454 x64 firmware calls. Only whole programs (`fn main`) are accepted; a bare unit is refused 455 at line 1 with error 25, and Linux host words such as `read` and `write` are refused with 456 error 25 at their line. The firmware is reached through one word, `efi` 457 (keyword id 178), recognised only under `target x86efi` (elsewhere it is an ordinary name, 458 and a call to it is error 3): `r = efi OP ARG A OFF N`, OP a literal 0..14 (a literal outside 459 0..14 is error 25, an OP that is not a literal, such as a name, is error 16), `OFF+N <= len A` 460 (else trap 3), bit 63 of the ulong result marks an error code. A trap T returns the 461 EFI_STATUS `2^63 | (100 + T)`. See [the x86efi design and evidence](../X86-EFI.md) for 462 the operations, the efi 12 file contract and qualification status. 463 464 An initial line `target a64efi` selects the AArch64 UEFI backend: the default AArch64 code 465 generator, a PE32+ image a 64-bit Arm firmware starts with no operating system, base-relative 466 addresses, and no host words (error 25, as is function mode and a run-time pool). Its `efi` word 467 keeps the x86efi contract and compiles to a call of the program's own `fn efirt` 468 (`seed/a64efi/efirt.om`); the firmware words `fwcall`, `fwld`, `fwst`, `fwsys`, `fwadr` and `fwop` exist 469 under this target only. See [the a64efi design and evidence](../A64-EFI.md). 470 471 ### 9.2 Functions and calls 472 473 - `fn` may appear many times. A names pass reads every signature before any code is written, so a call 474 names any function in the unit, earlier or later. A name that is a function never becomes a new 475 scalar: a value-returning function used as a statement is error 7, including `name = value`. 476 (s.6 r5b_fwd, r5b_assign, r5b_fwd_fm) 477 - In program mode a function may call itself, and two functions may call each other. In function mode 478 a call cycle, including a function calling itself, is error 9, so the stack a call chain uses is 479 bounded. (s.6 fib, r5b_mut, r5b_cycle, s.7) 480 - ` ` as a value calls a function that returns a value; as a line it calls a void one. 481 Using the one where the other is needed is error 7. (s.7) 482 - `to void` makes a void function; `ret` with no value returns from it, and so does reaching its `end`. 483 A function with a return type whose `end` can be reached is error 18. (s.6 t_void, s.7) 484 - Arguments are read left to right, each fully before the next. (s.5 fm5) 485 - A name may have up to 63 characters (error 13 beyond): functions, locals, parameters, `for` 486 counters, globals, texts, constants, structs and struct fields. Abstract, layout and layout-field 487 names, and every name in IR mode, stay at 8 characters (error 13). Names are compared in full: 488 `counter_a`, `counter_b` and `counter_` are three names. (s.4 dev01, s.7, `seed/omc/gate-longnames.sh`) 489 om4 keeps names other than functions at 8. A name longer than 8 characters is never a keyword, even 490 when its first 8 spell one (`continue_x`, `truncate_number`); a name that is exactly a keyword is 491 error 16. (s1 kw-long-names, s1-kw-long-field) 492 - A function has at most 6 parameters; a seventh is error 9. `main` has none (error 9). A new name 493 may not reuse a name already in scope, a function or a struct: error 10. 494 - In program mode the stack is a fixed 8 MiB pool; a call or a local array that would go below it traps 495 6 before it writes anything. (s.6 t_stack) 496 - omc sets no recursion depth limit of its own; only the 8 MiB stack bounds it. A program that takes 497 input-driven recursion bounds it itself, checking the depth before the call, as 498 `seed/omc/tests/recursion/nest.om` does: depth 16 accepted, depth 17 refused with status 40 before 499 any frame for it exists, plus a work bound (fuel, status 42). (`seed/omc/gate-recursion.sh`, #645) 500 501 ### 9.3 Numbers (decision 19: one meaning per word and width) 502 503 - Unsigned add, sub, mul, shl, neg, not wrap modulo 2^width (uchar 8, ushort 16, uint 32, ulong 64 bits). 504 (gate 3, s.4) 505 - Signed add, sub, mul, neg, div and shl trap 1 when the exact result is outside the type (byte 8, 506 short 16, int 32, long 64 bits), including the minimum divided by -1. (s.5 fm1-fm4, fm9) 507 - div and rem trap 2 when the divisor is 0. Signed div rounds toward zero; signed rem has the sign of 508 the dividend, and the minimum rem -1 is 0. (s.5 fm1, fm2, fm9) 509 - A shift amount outside 0 .. width - 1 traps 7, for every type. shr of a signed value keeps the sign. 510 (s.5 fm3, fm4) 511 - A conversion ` v` traps 5 when the value is outside the new type. (s.6 t_conv) 512 - There are no implicit conversions (decision 20): the two values of an op, a value and the name it is 513 written to, an argument and its parameter, all have the same type, or the line is refused (error 7). 514 A bare number takes the type the place needs. `uchar` is an 8-bit unsigned number, never a character. (s.7) 515 - A number is written in decimal, with a `-` in front when negative, in at most 20 digits; it must be a 516 value of the type it takes: -2^63 .. 2^63 - 1 for long, 0 .. 2^64 - 1 for ulong, and so on (error 8 517 outside; more than 20 digits, or a character that is not a digit, is error 6). (s.6 t_u63, t_u64max, 518 t_cmp_unsigned, t_conv_sign, t_write_wrap, s.7) 519 - `true` and `false` are the bool numbers 1 and 0. (s.6 t_loop) 520 521 ### 9.4 Arrays (decisions 16, 17, 18, 23, 24) 522 523 - Every array has a fixed element type (uchar .. long, never bool) and a fixed length written as a 524 number; the length travels with the array's name, never as a terminator byte. An array parameter or 525 a pool written without its length is refused (error 16). (s.7) 526 - `global NAME T N`: a pool of N elements (1 .. `16777216`), all 0 when the program starts, in the 527 program's own memory image (no heap, no allocation call); at most 1 GiB of pools, else error 23. 528 Program mode only (error 9). (s.6 echo, bytecopy, s.7) A run-time pool, `global NAME T *` (omc only, 529 section 9.15), is the one array whose length is set while the program runs. 530 - `text NAME "bytes"`: a read-only array of uchar holding the bytes between the quotes, with its 531 length; `\n` is 10, `\t` is 9, `\\` is 92, `\"` is 34; any other escape, or a quote missing its end, 532 is error 22. An empty text `""` is a sized array of length 0: `len` is 0, a number index is error 21, 533 a run-time index or `part`/`write` past 0 traps 3, and as a `view` argument its count is 0. Program 534 mode only. (s.7) 535 - `NAME = new T N v`: a local array of N elements, each v, on the stack, given back when the function 536 returns. Only in a function's outermost block (error 9); at most 4 MiB of local arrays (error 23). 537 There is no `free`: nothing is given back by hand (decision 24), and the word is refused (error 9). 538 (s.5 fm7, fm8, s.6 sort, s.7) 539 - A parameter `NAME view T N` or `NAME edit T N` takes an array of exactly that type and length (error 7 540 otherwise). A view is read-only; `put`, `read` into it, or passing it as edit is error 20. A text is 541 read-only in the same way. (s.7) 542 - An argument is a local array or an array parameter, optionally after `view` or `edit`. A global is 543 never passed (error 19), and the arrays of one call are distinct names (error 19); so two live 544 references in one function are always distinct storage, and no write is ever seen through another 545 name. (s.7) 546 - `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. 547 A number index must be inside A when om4 reads it (error 21); any other index is checked when it runs 548 and traps 3 when it is not below the length (a negative signed index traps too). There is no word that 549 turns an array into an address or adds to one. (s.5 fm8, s.6 t_bounds, s.7) 550 551 ### 9.5 System calls and lines 552 553 - `read fd A off n` and `write fd A off n` (fd int, off and n ulong) move n bytes between the open file 554 fd and A's elements off .. off + n - 1 with the Linux read and write calls, and give a long: the bytes 555 moved, or minus the Linux error number. They trap 3 unless n <= len A and off <= len A - n, before the 556 call. `read` needs a writable array (error 20). A must be an array of uchar for the counts to be bytes. 557 `pread fd A off n pos` / `pwrite fd A off n pos` (pos long) do the same at an explicit file position 558 without changing the descriptor's offset, with the same slice checks and result. Like `read`, `pread` 559 needs a writable array (error 20); `pwrite`, like `write`, also takes a text or a view. (s.6 echo, 560 bytecopy, t_rw; s4 v-bad-pread-text, v-pwrite-text) 561 - `exit v` (v int) ends the program with status v modulo 256. Like `ret`, it ends the path: a line after 562 it in the same block is error 17. (s.6 t_exit, s.7) 563 - `note ...` is a line the translator does not read beyond its first word. (s.6 sort, fib) 564 565 ### 9.6 Capacities (decision 23, amended 2026-11-11) 566 567 A refusal is defined behaviour: input past a real capacity is refused with error 14, never overrun, 568 truncated or corrupted. Since 2026-11-11 (Drake: "no hard caps on our own software; notice and fix 569 instead") omc has no table capacity of its own; om4 keeps its own. 570 571 **om4** reads at most 8 MiB - 1 bytes and writes at most 8 MiB, 1024 names in scope, values nested 1024 572 deep, 4096 functions, 8192 trap sites per function, 512 nested blocks (error 14 past each). om4's function 573 table (512 entries through om4 ``d0da40e4``) bounds `seed/omc/omc.om` itself, which om4 must compile; 574 `seed/rung4/gate4.sh` section 7b checks 4096 accepted and the 4097th error 14. 575 576 **omc** keeps every table that grows with the unit in one arena: the input, the output, names in scope 577 (globals, texts, constants, locals), names of 9 to 63 characters, functions and their parameters, call 578 sites, trap sites, open blocks, breaks and continues, inline returns and edges, the per-depth value cells, 579 the x86 fixups and the `om2 diag` site records. A table starts small and doubles when it fills. The 580 arena itself is a run-time pool (`global a_ar ulong *`, section 9.15; since landing 2 of the run-time 581 pools, `docs/RUNTIME-POOLS.md` section 6): its length is 0 when omc starts, and when a table's doubling 582 does not fit in the words left, `enlarge` grows the arena to twice its length (or to what the tables 583 need, when that is more). Only when the host refuses that growth (enlarge's negative result, for example 584 under `prlimit --as`) is the arena compacted (the words that moved tables left behind are reclaimed) and 585 the table grown in place, to the largest size that fits; a table is refused only when the host refused 586 and all the live tables, with that one grown by one entry, no longer fit in the arena as it is. Measured 587 2026-11-11: 1,500,000 globals (61,354,864 words handed out) and a 512 MiB input compile and run 588 (`seed/omc/gate-nocaps.sh` section 3); the static 128 MiB arena before it refused that globals unit at its line 877,501. Name, long-name 589 and function lookups are hashed, and the call graph is settled in linear time, so compile time stays 590 linear (`seed/omc/gate-usage.sh` times units up to 100,000 names, calls and trap sites). 591 `seed/omc/gate-nocaps.sh` drives every table past its first room and compiles those units with a checked 592 twin of omc as well, in which an index past its table is trap 3 (omc `c52e986e` and `1e628c80` stopped with 593 trap 3 on a unit with more inline edges than its call table held; fixed 2026-11-11). 594 What is left, and why: 595 596 - The arena: no size of its own. It grows while the host gives it memory; the host's refusal is error 14 597 on the line being read, followed on stderr by an `omc-use` record with `full=1` (below), which says what 598 held the arena. Until landing 2 of the run-time pools it was a static pool of `16777216` 8-byte words 599 (128 MiB), sized by omc's whole image under the smallest RLIMIT_AS omc runs under (`prlimit 600 --as=`268435456`` in the interplane-forge salvage compile) and by the `16777216`-element limit of a sized 601 pool (section 9.4); a run-time pool is bounded by neither. Measured 2026-11-11 (omc `a06777de`) under that 602 salvage limit: omc.om compiles; cortex's 87,019,650-byte page unit (`docs/RUNTIME-POOLS.md` section 11) 603 is error 14 with `full=1` at 256 MiB of address space and compiles at 512 MiB. 604 - The memory ceiling (`docs/RUNTIME-POOLS.md` section 6). A cgroup memory limit (`memory.max`) never makes 605 mmap or mremap fail: pages are charged when touched, so without a ceiling a compile past such a limit is 606 not refused. Measured 2026-11-11 (omc `59d7cb5e`, the page unit, `MemoryMax=`536870912``, swap 0): an OOM 607 kill (SIGKILL, exit 137), after 175 s of reclaim thrash in one run and after 2.4 s in another. A caller 608 states its ceiling in the environment, `OMC_MEMORY_MAX` (decimal bytes, read once before the input; empty 609 or 0: none; anything else but 1 to 19 digits below 2^63, or an entry too long to read whole, is error 26 on 610 line 0). Under it every growth keeps H + 16 MiB + H / 128 + R within the ceiling: H the most arena bytes ever 611 handed out, R the capacities of the artifact's region and of the om2 diag site records' region (both are 612 written after the compile, as page cache of the caller's cgroup). A growth never moves a group past H (it 613 compacts and grows in place) and never stops short of a doubling, so the result is monotonic in the 614 ceiling: refused (error 14, `full=1`, `ceiling=` set in the record) below one C, compiled from it. Measured 615 with `OMC_MEMORY_MAX` equal to `MemoryMax` and stdout and stderr on files: the page unit is error 14 below 616 512 MiB and compiles from 512 MiB; an om2 diag unit of 1,200,000 lines, error 14 below 496 MiB; every run 617 with no OOM kill (`seed/omc/gate-nocaps.sh` section 5). 618 - Value nesting: omc reads a value by recursion on its own fixed 8 MiB program stack (section 9.2). A 619 value nested deeper than 32768 levels is error 14 on its line, before that stack could run out 620 (measured: at most 144 bytes per level; 32768 allows 256). `seed/omc/gate-nocaps.sh` compiles every 621 measured shape 32767 deep, so a frame that grows is noticed. The same holds in IR mode. 622 - The output: AArch64 output stops at `134217728` bytes, the reach of B and BL (imm26), so every call 623 and jump stays encodable; x86 code at 0x400000 ends below the pools at 0x10000000, at `264241152` 624 bytes. Either is error 14 at its first byte. 625 - A single AArch64 conditional branch span is limited to 2^18 - 1 words forward or 2^18 words back 626 (section 9.1); a larger span (an `if` or loop body over 1 MiB) is error 24. Trap branches no longer 627 wait for the function's end: when a function's oldest waiting trap branch is 512 KiB back, omc 628 places the waiting stubs there, behind a B (an island), between two body lines that are outside 629 every `if`, `else`, `while` and `for` (unrolled bodies take islands; no block ever gets longer, so 630 block spans are as before). A trap branch can still reach error 24 inside one line that emits more 631 than 512 KiB (a value of some 18,000 nested calls) or inside a block that is itself near 1 MiB. 632 - A function that needs more than the 16 registers it hands out is error 12 (no spilling). 633 - Fixed tables omc still has, each error 14 past its number, kept in this change and listed so that 634 none is hidden (each a candidate for the arena): the OM-2 expansion bounds of `spec/omegese-om2.md` 635 section 4 (64 unrolled copies, 4 inline levels, 65536 units of expansion fuel per function); 16 structs, 636 16 fields and 64 cells a struct (9.7; struct and abstract types are encoded in the uchar type codes 637 16 + i and 64 + i); 16 abstract types; 16 layouts and 256 layout fields; 32 `export fn`; 64 entry and 64 638 head contract clauses; 16 `fresh` slots of at most 64 elements; the IR mode tables of 64 registers, 639 32 blocks, 256 ops, 32 literals, 32 bindings and 32 functions (OSC IR v1, which the C oracle shares); and 640 256 error and 256 done branches per x86efi operation. 641 642 **The alarm** in place of the old capacities: a unit whose first line (after notes and blank lines) is 643 `usage` is compiled as usual; instead of the artifact omc writes one line to stdout and exits 0: 644 645 omc-use 1 arena=A top=T waste=W full=F GROUP=N/H ... 646 647 A the arena's words (its length when the record is written: the arena grows), T the words handed out, 648 W the words left behind when a table moved, F 1 when the host refused to grow the arena (or the memory 649 ceiling stopped it) and the tables no longer fit (error 14); for each group (`inp out site names namehash long longhash fns fnhash calls traps x86addr 650 x86exit blocks breaks conts inlret inledge depth kahnfn kahncall`) N what the unit asked it to hold (bytes 651 for `inp`, `out` and `site`, else the highest index plus 1) and H the words it holds; last, `ceiling=C`, 652 the `OMC_MEMORY_MAX` in force (0: none). A refused `usage` 653 unit writes the human line and then the record to stderr. `seed/omc/gate-usage.sh` compiles the largest 654 units of the stack (omc.om itself, omega-mcp, cortex, forged) and scale units, and fails loudly, naming 655 the unit, the measure and the number, when the words handed out pass `4194304` (`12582912` for a scale 656 unit), one group holds more than `2097152` words (`16777216`), the host refused (`full=1`), a compile takes more than 2 s (10 s) or more than 64 MiB (256 MiB) resident. Since the arena grows to fit, the words are 657 absolute (the old fractions of the `16777216`-word static arena). Its mutant control, tables that never 658 double (a_need's growth made +512 entries), must be caught (measured 2026-11-11: calls100k, 94,048,221 659 words handed out and 730 MB resident). 660 661 ### 9.7 Structs (omc only, rung 6) 662 663 om4 does not grow for this. A struct program is refused by om4. omc.om does not use these words, so 664 om4(omc.om) stays equal to omc(omc.om). Checked by `seed/omc/gate6.sh`. 665 666 - `struct Name field type [len] ... end`, one line, before the first `fn`. 1 to 16 fields, at most 16 667 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 668 and a scalar type; a number after the type is an array field of that length (1 .. 64). Every field 669 is one or more 8-byte cells, in order, no padding. (gate6 t7, t8, t9: a wrong scale overlaps a 670 neighbour and changes the result; the expected results are 1, from the layout, not from this compiler) 671 - The struct's name is a word from that line on. No function, variable, or field may be spelled the 672 same (error 10). Field names are unique in their struct (error 10). A variable may share a field's name. 673 - `p = new S v1 .. vn`, only as the whole of an assignment, and only in the function's outermost block 674 (error 9 inside `if` / `while` / `for`). One value per field; an array field takes one value, stored 675 in every element. The cells are a stack slot, 16-byte aligned, given back when the function returns. 676 There is no `free` (decision 24); the word stays error 9. (gate6 t1-t6, still_free, new_in_if) 677 - `get p f` reads a scalar field. `get p f i` reads an element of an array field. `put p f v` and 678 `put p f i v` write. A view cannot be written (error 20). An unknown field is error 3. A number index 679 outside the field is error 21; any other index is checked when it runs and traps 3, as for arrays. 680 - A parameter is `p view S` or `p edit S`. A call passes an own or edit struct to edit, and any struct 681 to view, always of the same struct (error 7 otherwise, error 20 for a view passed to edit). The 682 structs of one call are distinct names (error 19). A function does not return a struct. 683 - `len` of a struct is refused (error 7). `read` and `write` of a struct are refused (error 7). 684 685 ### 9.8 Break, continue and trap (omc only, gate7) 686 687 `break`, `continue` and `trap` are the path-ending statements §3 lists. omc implements all three; 688 om4 refuses them, so they are omc-only like structs. Checked by `seed/omc/gate7.sh`; it is run by 689 `seed/host/check.sh`. 690 691 - `break` scans the open blocks for the innermost loop (kind 3 while, 4 for), emits an 692 always-taken `B.AL` to that loop's exit and records the word. When the loop closes, `s_end` 693 patches only the entries recorded since that loop opened and gives them back, so a later loop 694 that reuses the block slot cannot move an earlier break. Outside a loop it is error 9. Like `ret`, 695 the line ends the path: a later line in the same block is error 17. Break sites have no count of 696 their own since 2026-11-11 (they were 1024 per function; section 9.6). (gate7 w1, f1, n1-n3) 697 - `continue` finds the innermost loop the same way, but its recorded branch is patched to the loop's 698 latch, not its exit: the head of a while, so the condition and the bound count run again, or the 699 increment of a for, so the counter still advances. Outside a loop it is error 9; a later line in the 700 same block is error 17; continue sites have no count of their own (section 9.6). (gate7 c1-c5, 701 bad_continue, bad_after_continue) 702 - `trap N` takes a decimal number 1..14 (error 4 when the line ends, 16 when the token is not a 703 number, 8 out of range). It emits the same always-taken branch the runtime trap checks use; 704 `finish` makes one stub per code, so program mode exits 100 + N and function mode calls 705 `OscRt.trap`. The line ends the path (error 17 for a later line in the same block). 706 (gate7 t1, t2, bad_trap0, bad_trap15) 707 - None of the three may be a name; all are reserved from the keyword table. (gate7 om4 refusal) 708 709 710 ### 9.9 Floating point (omc only, gate8) 711 712 The words are `bitcast`, `fsqrt`, `fabs`, `fmin`, `fmax` and `fma`, not `bits`, `sqrt`, `abs`, `min` and 713 `max`: the benchmark corpus uses those shorter spellings as ordinary identifiers, and a keyword may 714 not take a name that existing `.om` code already uses. gate11 pins both halves of that rule. 715 716 `f32` and `f64` are IEEE-754 binary32 and binary64. A float value is its bit pattern held in an 717 ordinary integer register or its SIMD twin; arithmetic runs one scalar FP instruction. 718 FPCR is never written: under the Linux default it is round to nearest even with subnormals kept. 719 Ordinary `mul` then `add` stay separate operations and round separately; only explicit `fma` fuses. 720 There is no implicit conversion: mixing f32 and f64, or float and integer, without a conversion 721 is error 7. 722 723 - Literals: `digits.digits[(e|E)[+|-]digits][f32|f64]`; a digit must be present on both sides of the 724 dot, and a leading `-` negates. A literal with no suffix takes its type from context exactly as an 725 integer literal does; where no context gives a float type it is error 11. An integer literal where 726 a float is expected (assignment, `ret`, argument, `put`, `new` fill) is error 7; write `f64 1` or 727 `1.0`. The decimal text is converted exactly: digits times a power of ten is held as an exact 728 quotient of two integers, long division gives a 64-bit significand and the remainder gives the 729 sticky bit, then the value is rounded once to nearest even: 0.1f64 is 0x3FB999999999999A and 730 6816.`702656e`-27 is 0x3B207B55A6D4A130. The full binary32 and binary64 range is covered, including 731 subnormals (5e-324, 1e-45; 2.`4703282292062328e`-324 is 0x1) and signed zero. A literal that 732 rounds to infinity is refused (error 8); one at or below half the smallest subnormal rounds to signed 733 zero. The significant digits must still fit in 2^63-1 (error 8 beyond that). (gate8 f64_bits, 734 f32_bits, lit_round, neg_int_*, neg_ambiguous, neg_dot, neg_overflow, neg_overflow2, 735 neg_overflow3; `seed/omc/float-lits.py diff OMC N SEED` is the randomized differential) 736 - Operators: `+ - * /` and unary `neg`; comparisons `eq ne lt le gt ge`. Bit operators, shifts and 737 `rem` on a float are error 7. IEEE results: division by zero and overflow give infinity, 0/0 gives 738 NaN, and no float operation traps. NaN compares false everywhere except `ne`, which is true. -0.0 739 compares equal to 0.0; `bitcast` exposes the sign. (gate8 arith, compare) 740 - Intrinsics `fsqrt x` and `fabs x` take one float; `fmin a b` and `fmax a b` take two of one float 741 type and follow FMINNM/FMAXNM (IEEE minNum/maxNum: one quiet NaN returns the other operand; -0.0 742 orders below +0.0). A bare integer operand is error 7 and an unresolved literal is error 11. 743 (gate8 intrinsics, neg_intr_*) 744 - `fma a b c` multiplies `a` by `b` and adds `c` with **one rounding of the exact combined result**. 745 All three operands must have the same explicit f32 or f64 type (error 7 otherwise; an unresolved 746 decimal literal is error 11). AArch64 emits one scalar FMADD; its IEEE/Arm FPMulAdd behavior follows 747 FPCR, including subnormals, infinities, signed zero, quieting signaling NaNs and invalid operations 748 such as zero times infinity. NaN payload selection is Arm's rule, not a host-library rule. 749 In particular `(1+2^-52)*(1-2^-52)-1` is `-2^-104` for f64 rather than the zero from separately 750 rounded multiply and add. x86linux and x86efi refuse a well-typed `fma` with error 9: their SSE2 751 baseline does not provide a fused instruction, and no unfused fallback is permitted. The operands 752 are typed first, so errors 7 and 11 have the same line and code on every target. IR mode refuses 753 float words with error 3. (gate8 fma, neg_fma_* on AArch64, x86linux and x86efi; gate-fma 754 wrong-opcode, unfused and rounding mutants) 755 - Conversions ` value` handle int<->float, f32<->f64 and float->int. Int to float is SCVTF/UCVTF 756 (round to nearest even); float to int is FCVTZS/FCVTZU (truncate, saturate, NaN -> 0); f32<->f64 is 757 FCVT. `bitcast T value` reinterprets a value of the same width (f32/i32/u32, f64/i64/u64, and 758 i8/u8, i16/u16 between integers) without changing its bits; any other width or a bool is error 7. 759 The result is an ordinary value of T: `bitcast int uint `4294967295`` equals -1 and 760 `bitcast uint int -1` equals `4294967295`; an 8/16/32-bit integer or f32 is extended again for T into 761 a new register, so the source name keeps its value (omc `2c824805` kept the source's extension). 762 (gate8 convert, bitcast_int, neg_bitcast_width) 763 - Floats are allowed in `global` pools, `new` arrays, parameters, returns and struct fields. 764 Arrays are packed by element type: f32 occupies four bytes and f64 eight (`tlog` and `sa_arr` 765 in `seed/omc/omc.om`). Struct fields retain eight-byte cells, including f32 in the low half. 766 A float cannot index an array or be a `for` count 767 (error 7), `read`/`write` still need a uchar array (error 7), and IR mode refuses float words 768 (error 3). (gate8 arrays, globals, params, structs, neg_*) 769 770 771 ### 9.10 Grouping parentheses (omc only, gate9) 772 773 `(` and `)` are separate words even when written against a value (`(int 2)`, `((7))`); the lexer 774 splits them out of the surrounding word. A group returns exactly the value inside it and adds no 775 code. A group whose only value has no type is still ambiguous (error 11), and a group missing its 776 `)` is error 16. Checked by `seed/omc/gate9.sh`, which `seed/host/check.sh` runs. 777 778 779 ### 9.11 Layout queries (omc only, gate10) 780 781 `sizeof T` is the size in bytes of a scalar type (bool 1; uchar/byte 1; ushort/short 2; 782 uint/int/f32 4; ulong/long/f64 8). `sizeof S` is a struct's size: 8 bytes for each of its cells. 783 `offsetof S f` is the byte offset of field `f`; an array field gives its first element. Both are 784 compile-time constants of type ulong and add no code, so they compose in expressions. 785 786 An unknown type name is error 16, an unknown struct or field is error 3, and `sizeof void` is 787 error 9. Checked by `seed/omc/gate10.sh`, which `seed/host/check.sh` runs. 788 789 790 ### 9.12 Constants (omc only, gate16) 791 792 `const NAME TYPE LITERAL` at top level defines a named value before use. `NAME` is at most 793 63 characters and may not collide with a visible name, a function or a struct (error 10); the value 794 must fit the type (error 8). The constant is a typed number: an integer (`uint 5`, `long -3`) or a 795 float literal (`f64 0.1`, `f32 0.1`); an integer literal under a float type is refused (error 16). 796 It composes wherever a value goes, including inside functions and as a call argument, and it cannot 797 be assigned (error 7). In IR mode an integer constant is folded to its literal, including as a 798 `trap` code, a `while` bound, or a `for` count; a float constant there is refused (error 9), as are 799 struct/global/text declarations. Definitions are sequential, so a 800 constant defined after a function is not visible to that function. 801 802 A constant needs no program image, so it is also accepted in function mode (a unit without 803 `fn main`): every read folds to the typed number, and the function words are byte for byte those of 804 the same unit written with the literal (gate16 `fm_*`: value, negative value, parameter and `new` 805 length, `while` bound, `trap` code, `for` count, two functions, f64). A `global` or `text` in a 806 function-mode unit is still error 9 at the end of the input, with or without constants beside it, 807 and a host word is still error 9 at its line (gate16 `fm_global`, `fm_text`, `fm_host_word`). 808 809 An integer constant is also accepted as an array length in `new`, `global`, a parameter declaration 810 (`view T N` / `edit T N`) and a struct field length (1..64, error 14); a float constant used as a 811 length is error 16. A length token that is a name other than an integer constant is error 16, and 812 `arrlen` still enforces 1..`16777216` for arrays (errors 8 and 23). Signatures are pre-scanned, so a 813 constant used in a parameter length must be defined before that function. 814 815 An integer constant is also accepted as a `trap` code (1..14) and as a `while ... bound` or 816 `for ... bound` count (1..`9223372036854775807`; 1..`1000000` in IR mode); a `for` count is an ordinary value, so a constant 817 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 818 error 16. 819 820 ### 9.13 Profile OM-2 (omc only, `spec/omegese-om2.md`, ledger L834) 821 822 OM-2 is opt-in per unit; the contract `spec/omegese-om2.md` and its errata are normative, and this 823 section lists what omc implements of it. Fixtures, expected results and compiled mutants: 824 `seed/omc/om2/` (run by the #748 gate `seed/qualification/om2/gate.om`). Every OM-1 unit keeps its 825 meaning and, for the C2 manifest, its exact output bytes or error. 826 827 - **Opt-in.** Leading blank lines and `note` lines are skipped; when the next line is exactly `om2`, 828 `om2 diag` or `om2 fmt` (no other bytes on it) the unit is OM-2. Any other line leaves the unit OM-1, 829 where the `om2` line itself is error 16 as before. The words of this section are reserved only in an 830 OM-2 unit: `rotr rotl unroll inline fresh abstract seal open holds layout field at little big part out 831 export ops dit scrub`. Using one as a name there is error 16; an OM-1 unit keeps them as ordinary names. 832 - **`om2 diag`.** After the human line `omc: line N: error E` (unchanged), stderr gets one record 833 `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 834 the human line. `A-B` is the half-open byte span of the token being read (the LF for a line that ends 835 too early; `len-len` at the end of input) and `col` the 1-based byte column of A on its line. `found` is 836 the span's bytes in hex (at most 32 bytes), `-` when empty. `expect` is the class being read: `number` 837 for errors 6 and 8, `end` for error 15, `name` for an unknown name, otherwise `value`, `type`, `name`, 838 `newline` or `word` from the reader that failed. `sev` is `unknown` for an undeclared function or struct 839 (errors 3 and 13 at a call or `offsetof`; error 16 for an undeclared word where a type or struct is 840 read, as in `new Pt` or `p view Pt`), `incomplete` when the failure is on the end-of-input token or 841 in a text cut by the end (except the call-cycle error 9), else `error`. `obligation` is `bounds` (21), 842 `growth` (14), `regs` (12), `init` (27), `ctor` (28), `layout` (29) or `-`. 843 - **Hex literals.** `0x` and 1..16 digits `0-9a-f` is the unsigned value and takes the type the place 844 needs under the decimal range rule (error 8 outside; `int 0xffffffff` is error 8). A `-` before it, `0X`, 845 no digits, more than 16 digits, an uppercase digit, `_` or any other character is error 6. 846 - **`om2 fmt`.** Only when the input's first line, at byte 0, is `om2 fmt` (error 16 elsewhere). The rest 847 (the bytes after the first LF) is compiled as a unit of its own, OM-1 or OM-2 by its own first line; 848 if it is refused, the error is reported against the whole input and nothing is written. If it is 849 accepted, stdout gets its canonical text: note lines and text literal bytes exactly as written; the 850 indentation as written; each other run of blanks between words one space, except next to `(` or `)` 851 where it is kept; no blanks at a line end; a whitespace-only line empty; one LF after the last line. A 852 CR anywhere and blank lines at the end are error 6. fmt never adds or removes a line, is idempotent, 853 and compile(fmt(x)) is byte-identical to compile(x). 854 - **Rotate.** `rotr x n` and `rotl x n`: x and n of one unsigned type (uchar, ushort, uint, ulong; else 855 error 7), the result x's type. n outside 0..w-1 traps 7 at run time, a number n included. uint/ulong 856 with a number n give one `ROR` (immediate, EXTR); otherwise the amount check, then `RORV` (rotl through 857 `NEG`). uchar/ushort replicate the value into a 32-bit pattern, rotate it, then truncate. 858 - **Unroll.** `for i T K unroll`: K a number 1..64 (error 8 outside; a name or other value is error 16). 859 The body is compiled K times with `i` the constant 0..K-1 (a write to it is error 7). `break` or 860 `continue` whose innermost loop is the unrolled one is error 9; inside a rolled loop in the body they 861 work as usual. No loop branch or counter is emitted. Removing `unroll` leaves behaviour unchanged. 862 - **Inline.** `fn NAME ... to T inline`: every call is compiled in place. Arguments are read left to 863 right as for a call; a scalar argument in a named register is copied, one in a temporary is used as it 864 is. The caller's locals are hidden from the body, and `ret` becomes a branch to the body's end (a last 865 one is dropped). The standalone function is still emitted. `new` in it, or an inline function reached 866 again while it is being inlined (itself included), is error 9; so is an inline function that reaches 867 itself anywhere in the call graph, through non-inline calls too (checked at the end of the input). A 868 fifth nested inline level is error 14. Calls to other functions stay calls. Removing `inline` leaves 869 behaviour unchanged. An argument that is a number is copied to a register, so folding does not reach 870 through parameters. 871 - **Folding and checks.** Only inside an unrolled or inlined body, an operation (`add` .. `shr`, 872 comparisons, `rotr`/`rotl`, `neg`, `not`) on two typed numbers is computed with OM-1 arithmetic. One 873 that would trap (signed overflow, a divisor 0, an amount at or above the width) is not folded and keeps 874 its runtime trap. Conversions are never folded. A number index into a sized array is checked when it 875 is compiled (error 21), as in OM-1, and in an OM-2 unit up to 4095 it is an immediate offset (LDR/STR 876 unsigned offset) with no runtime check. Every other index keeps its runtime check. 877 - **Bounds.** 64 copies per unrolled loop and 4 inline levels (error 14, `obligation=growth`); a 878 function's emitted words have no bound since 2026-11-11 (it was 65536 words; section 9.6). 16 registers 879 stay the limit (error 12, `obligation=regs`). Expansion fuel (E14, E16): each function has 65536; an unrolled loop is 880 charged K when it starts, at its line, before any copy expands, and an inline expansion 1 at its call 881 line, in emission order at every nesting depth (nested unrolls multiply). The charge that takes the 882 total above 65536 is error 14 (`growth`) on its line; exactly 65536 is allowed. So two nested 64-copy 883 unrolls (4160) compile and three do not. An inline function's standalone body is compiled with its own 884 fuel where it stands in the source. The inline call graph keeps each edge once. 885 - **Trap sites.** With `om2 diag`, an accepted unit's stderr gets one `omc-site 1 line=N iter=k` record 886 per runtime trap site, in emission order: N the source line, k the counters of the open unrolled loops 887 outer to inner joined by `.`, or `-`. stdout is unchanged. 888 - **External layout.** `layout NAME SIZE`, then one line `field F T [COUNT] at OFF little|big` per field 889 (note lines allowed), then `end`, at top level before the first `fn`. NAME and F at most 8 bytes and not 890 OM-2 words; NAME is a new name (error 10), F unique in its layout (error 10); T an integer type 891 (`uchar` .. `long`; else error 7). SIZE outside 1..4096 or a `layout` after the first `fn` is error 29 892 on the layout line; a COUNT outside 1..4096, an OFF or field extent past SIZE, or a byte shared with an 893 earlier field is error 29 on the field line (`obligation=layout`). No COUNT is a scalar field (E5). 894 A parameter `c view NAME` / `c edit NAME` is a `uchar` array of exactly SIZE bytes (another array is 895 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 896 at OFF + i * width with its width and byte order (unscaled register-offset LDR/STR, REV16/REV for 897 big; signed fields sign-extended). The index is checked like an array's: a number outside COUNT is 898 error 21, a run-time one traps 3. A missing index on an array field is error 4, an extra one on a 899 scalar field error 5, `put` through a view error 20. Any other word after `c` reads it as the plain 900 `uchar` array (`get c i`, `len c`, passing it on). Structs (9.7) are unchanged. 901 - **Fresh scratch.** A parameter `s edit T N fresh` (N at most 64, else error 14 `obligation=init`; on 902 a view error 16) has unspecified incoming elements. omc tracks, per such array, which elements are 903 definitely written on the path being compiled: a `put` with a number index (after unrolling, 904 inlining and folding) marks its element; a `get` with a number index needs that element, any other 905 `get` all N (else error 27, `obligation=init`, on the get line). An if without else, a while and a 906 rolled for leave the set as it was when they opened (no induction); an if/else keeps the elements 907 written in both arms, or in the arm that does not end in `ret`; an unrolled or inlined body keeps 908 what it wrote. Passing the array to a non-inline call, `read`, `write` or a host operation is error 909 27 on that line; an inline callee works on the same set, and its own `fresh` parameter starts empty. 910 At most 16 fresh arrays per function, inline ones included (error 14). The generated code is unchanged. 911 - **Abstract types.** `abstract NAME T [ops W ...]` (T `uint` or `ulong`, else error 7; W from `rotr rotl 912 and or xor`, else error 16) and `holds NAME dup32`, at top level before the first `fn` (error 9 after 913 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 914 function named NAME followed by `mk` that returns NAME, inlined or not; a `seal` anywhere else is 915 error 28 (`obligation=ctor`) on its line. `open v` gives the T value. A T value or a number where NAME 916 is needed, a conversion, comparison or any operation on it not listed by `ops`, an array or struct 917 field or `const` of it, `sizeof`/`bitcast` of it, and NAME as a parameter or result of the entry of a 918 function-mode unit are error 7. Listed operations run on T and give NAME: `rotr`/`rotl` of NAME by a T 919 count (E9; 64 traps 7), `and`/`or`/`xor` of two NAME values. `holds NAME dup32` (ulong only; any 920 other predicate, or a uint NAME, is error 28 on the holds line) makes every seal check high32 == 921 low32 at run time (LSR, CMP UXTW, B.NE trap 10), except when the constructor's body is exactly the 922 line `ret seal NAME or shl ulong x 32 ulong x`, x a uint parameter, then `end` (the check is erased, 923 rule `dup32`: uint values are held zero-extended). With `om2 diag` each seal compiled writes 924 `omc-check 1 kept|erased line=N rule=dup32|-` (N the seal line) with the omc-site records. 925 - **Unsized views.** A parameter `NAME view T *` / `NAME edit T *` takes an array of element type T of any 926 length (error 7 for another type): a sized array (E2, also on internal functions), an unsized one or a 927 text (view only). `len NAME` is its run-time count, a ulong value. Every index into it, a number too, 928 is checked at run time against the count (CMP, B.HS trap 3; no error 21, no elimination); `read`, 929 `write`, `pread`, `pwrite` and the host words keep their slice checks against the count. An unsized 930 array never goes to a sized parameter (error 7); view / edit rules, distinct names (19) and fresh (27) 931 are as for sized arrays. `new` stays sized; `fresh` needs a length (error 16). 932 - **Parameter slots.** Parameters take x0..x5 in order, in both modes: an unsized view or edit two slots 933 (pointer, then count), every other parameter one (a scalar, a sized array, a layout or a struct by its 934 pointer). A parameter that needs a seventh slot is error 9 on the fn line. 935 - **Part.** `part A o k` (o, k ulong; another type is error 7), only as an argument for an unsized 936 parameter of a call (a sized parameter is error 7; anywhere else, `read`/`write` included, error 9), is 937 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 938 array error 27). o is read, then k, then the checks run in this order: o <= len A, then k <= len A - o 939 (CMP, B.HI trap 3; the wrapped o + k is never formed). The callee gets A + o * size and count k. A part 940 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 941 (to an edit parameter error 20). For distinct names a part is its base A: A and a part of it, or two 942 parts of A, in one call are error 19 whatever the ranges. 943 - **Out.** A parameter `NAME out T N` (N a length; `*` or `fresh` is error 16) is written by the unit; 944 the bridge owns the buffer and copies it out after status 0 (spec 6, E1). Inside the unit it is an edit 945 of T N in one slot (its pointer): `get`, `put`, passing it on as an edit; a view or an array of another 946 length passed to it is error 20 / 7. 947 - **Export.** `export fn NAME ...` at top level (error 16 elsewhere, and when `fn` does not follow) marks a 948 function-mode entry (with `fn main` error 9; a 33rd export error 14). With any export, words 0 .. E-1 949 are `B` to the exports in source order and the code starts at word E; the other functions are private. 950 Without export the OM-1 rule holds (one function: its bare words; more: word 0 is `B` to the last). The 951 entry rules of the abstract types apply to each export (to the last function when there is none). 952 953 #### 9.13.1 Secret hygiene: `dit` and `scrub` (program mode) 954 955 Two value words for code that handles secrets. Both are OM-2 only (reserved as above), program mode only 956 (error 9 in function mode), AArch64 only (error 25 under `target x86linux`), and give a long. They are 957 value-only words: they stand where an expression is read (`k = scrub 16`, an argument, an operand); a bare 958 statement `scrub 16` or `dit 1` reads the word as a statement name and is error 16 (keyword used as a 959 name). IR mode never reaches them: `ir` together with `om2` is already error 16 in either header order, 960 so omc's IR-mode error 9 test for these words is a defensive check that no source exercises. The emitted 961 words are fixed, so the output is byte-for-byte deterministic. Fixtures: `seed/omc/om2/s5/` (`s5.cases`, 962 `s5-mutants.cases`, both standing gates in `seed/host/check.sh`); `s5-scrub-emit` pins the sha256 of the 963 whole output of `scrub-emit.om`, so the exact register-zeroing sequence below is checked, and the 964 mutants `m-zpool`, `m-zvec` and `m-movz16` (zeroing words retargeted to X16 or V0) are detected by it. 965 `s5-scrub-femit` pins the same for a unit with a live float local, so which V registers are spared is 966 checked (`m-twinall`, sparing the dead twins of live slots too), and `s5-scrub-flive` reads live float 967 locals, a held float operand and a float call argument back after scrub (`m-twinnone`, zeroing V0-V31). 968 `s5-scrub-pin` reads a pinned global base and a pinned length back after scrub (`m-pinlo`, the pins not set 969 back: trap 3), and `s5-scrub-lateglob` reads a global declared after a scrubbing function (`m-pinshut`, 970 that global pinned anyway: its register is cleared and not restored, trap 3). `s5-scrub-chain` reaches 971 the scrub through two calls compiled before a long global (pinned anyway: trap 3), `s5-scrub-latebase` 972 writes and reads a short global (a base pin only) declared after the scrubbing function (pinned anyway: a 973 store through base 0, SIGSEGV), and `s5-scrub-inl` reads a global declared after an inline scrubbing 974 function. `pinshut` is set when the body pass begins any `fn`, an inline one too, so that global takes no 975 pin and the case checks the MOVZ/MOVK path; without `pinshut` the inline body, compiled at its call site 976 after the global, restored the pin. 977 978 - **`dit v`** (v int, else error 7) sets PSTATE.DIT (Arm ARM C5.2.4, FEAT_DIT; bit 24 of the DIT 979 special-purpose register) and gives the previous bit as 0 or 1. v outside {0, 1} (a negative int too) 980 is trap 3 before the write. Words: `CMP Xv, #1` (SUBS, C6.2.464), `B.HI` trap 3, `LSL X16, Xv, #24` 981 (UBFM, C6.2.487), `MRS Xd, DIT` (C6.2.287, `d53b42a0`|d), `MSR DIT, X16` (C6.2.289, `d51b42b0`), 982 `UBFX Xd, Xd, #24, #1`. Writes to PSTATE take effect in program order with no barrier (C5.1). A core 983 without FEAT_DIT raises SIGILL; the Spark's GB10 lists `dit` in /proc/cpuinfo. Linux starts a process 984 with DIT 0 and keeps it across context switches; `dit` does not restore it at function exit. 985 - **`scrub n`** (n ulong, else error 7) zeroes the dead stack and the dead registers and gives 0. n must 986 be a multiple of 16 and at most `1048576` (1 MiB), else trap 3; when SP - n is below the stack-pool floor 987 X28 it is trap 6, before any store. Then the n bytes `[SP - n, SP)` are zeroed with `STP XZR, XZR, 988 [X16], #16` (C6.2.414) from SP - n upward: the frames of returned callees, their spilled registers and 989 local arrays. Then `MOVZ Xr, #0` for every register that holds no live value: the pool registers at 990 index npar + temporaries-in-use and above (the free temporaries and caller-saved registers), X16, and 991 X7, X18-X26, X29 (no program-mode code keeps a value there except the OM-2 pinned global registers 992 below); and `MOVI Vd.2D, #0` (C7.2.247), which also clears 993 the upper SVE Z bits, for V0-V15 and for every dead twin. In an OM-2 AArch64 program the pinned global 994 registers among X18-X26 (each global array declared before the first `fn`, in order, gets one for its 995 base address and one more for its length when that is above 4095, until the nine are taken) are then set 996 back to those public constants with `MOVZ`/`MOVK`, since later element accesses read them; OM-1 and x86 997 units have no pinned registers. Since #853 an f32/f64 local name and a held 998 float value live in the twin V16+j of their pool register (omc.om, "floats in v registers"); the twin 999 is live when slot j is below the free index and its value lives there, and only such twins are 1000 spared. The twin of a free slot, or of a slot whose value is in its x register (a float parameter, an 1001 integer), is zeroed; V0-V15 carry a float only inside one operation. Not zeroed: SP; X27 (the Linux 1002 initial stack when the unit reads its arguments or environment); X28 (the floor); X30 (the return 1003 address); the pool registers below the free index (parameters, locals, the held operands of the 1004 expression and of an enclosing call) and their live twins; NZCV, FPCR, FPSR, the SVE P registers and 1005 FFR; memory above SP, the live frames. The result register is set 1006 to 0 last. 1007 1008 ### 9.15 Run-time pools (omc only, `seed/omc/gate-pools.sh`; design `docs/RUNTIME-POOLS.md`) 1009 1010 Decision 3 of 2026-11-11 (omega-mv #793 RM4, #795 RM6): a region whose length is known at run time, 1011 obtained from the host as zero pages, bounds-checked like every array, with no `free` and no general 1012 allocator. Program mode on AArch64 Linux and, since 2026-11-23, `target x86linux`. 1013 1014 - `global NAME T *`: a run-time pool of element type T (as for `global`; `bool` is error 9). Its length 1015 is 0 when the program starts. Function mode and IR mode refuse it (error 9), `target x86efi` and 1016 `target a64efi` refuse it (error 25). Like every global it is never passed as an argument and never 1017 sliced with `part` (error 19), and a struct argument is never a pool (error 7). 1018 - `r = enlarge NAME n`: n a ulong and r a long (error 7 otherwise; r is an existing long local or a new 1019 one), allowed only as the whole of an assignment (error 9 inside a value, a `put` or a condition; a bare 1020 `enlarge P n` line is error 16, as for every value word written as a statement), in any function and 1021 any block. `enlarge` on a name that is not a run-time pool is error 7. 1022 Results: n at or below `len NAME`: 0, nothing changes (`enlarge` never shrinks). n above it: NAME has 1023 n elements, the first `len NAME` keep their values, the rest are 0, the result is 0. n times the 1024 element size at or past 2^63: -22 and NAME is unchanged. The host refuses (mmap or mremap fails, for 1025 example under RLIMIT_AS or `vm.overcommit_memory=2`): the host's negative errno, -12 (ENOMEM), and 1026 NAME is unchanged. A refusal is a result the program handles; it is never a trap. Under a cgroup 1027 memory limit (`memory.max`) the mapping is not refused: pages are charged when first touched, and 1028 past the limit the kernel's OOM killer ends the process, as it would for a touched `.bss` page. 1029 - `len NAME` is the current length, a run-time ulong, never folded: a contract on it (`requires eq len P 1030 0`, `invariant le i len P`) is checked when the program runs. 1031 - `get NAME i`, `put NAME i v`, `read fd NAME off n` and `write fd NAME off n` (a uchar pool) behave as for 1032 any array and are checked against the current length: an index at or past it traps 3, a number index 1033 included (it is checked at run time, never error 21). Every other word that takes an array (the device 1034 and mapping words such as `mapread` and `mapwrite`, the path and buffer words) refuses a pool with 1035 error 7. 1036 - Memory is held until the process ends: no word gives it back (decision 24). A long-running program 1037 sizes a pool to its high-water mark and reuses it, keeping its own used length, rather than enlarging 1038 for every request; `gate-pools.sh` has such a server-shaped case with resident memory checked flat. 1039 - Lowering: each pool has a 16-byte slot in the global pool area (base, length in elements; never held in 1040 a pinned register X18..X26). Every access loads the slot after all its operands have been read (LDP, 1041 CMP, B.HS trap 3), because an `enlarge` inside an operand may move the pool. `enlarge` calls one helper 1042 per unit, emitted at the unit's first `enlarge`: lengths are rounded up to whole 4096-byte pages, a 1043 growth inside the pages already mapped only stores the length, the first growth is mmap (syscall 222, 1044 MAP_PRIVATE|MAP_ANONYMOUS) and a later one mremap (216, MREMAP_MAYMOVE), which moves page tables and 1045 never copies the data or touches the untouched pages. A unit that uses no pool compiles to the same 1046 bytes as before (gate-pools.sh compares every tracked unit). Under `target x86linux` the same rules 1047 hold: the slot is read after the operands (LEA, MOV, CMP, JAE trap 3), and `enlarge` is emitted inline 1048 at each site with the x86-64 Linux syscalls mmap (9) and mremap (25); gate-pools.sh section X runs every 1049 pool case on x86-64 (EMULATED under qemu-x86_64) with two x86 mutants. 1050 - What verification keeps and loses: every access stays bounds-checked (trap 3 exactly as for a sized 1051 array) and `enlarge` cannot overrun or shrink; what is lost is the compile-time knowledge of the 1052 length, so a number index into a pool is no longer error 21 at compile time, no pool check is 1053 eliminated under unrolling or inlining, and a contract on `len` is a run-time check (om2 diag 1054 `kept rule=runtime`), never proved constant. checker2, the C path and IR mode do not see pools. 1055 - om4 knows the subset `seed/omc/omc.om` uses (landing 2): `global NAME T *`, `get`, `put` and `len` on a 1056 pool, and `r = enlarge P n`, for which it emits the same words as omc in an OM-1 unit (gate5 builds omc 1057 from omc.om with both; gate4 runs `seed/rung4/tests/t_pool*.om` and, under `prlimit 1058 --as=`268435456``, `h_poolhost.om`). om4 refuses `read` and `write` on a pool with error 9 (omc only). 1059 `enlarge` is keyword id 244 in omc (code 85 in om4's table), a C1 language addition. It changes no 1060 manifest-c2 row, so there is no delta file; `gate-pools.sh` scans the corpus: no tracked unit uses it as 1061 a name, and the units that use the word outside `seed/omc/tests/pools` (omc.om and om4's pool cases) are 1062 listed there by name. 1063 1064 ### 9.14 Compiler error codes (omc, registry `seed/omc/error-codes.reg`) 1065 1066 A refusal prints one line, `omc: line L: error C`, on stderr, writes no program and exits with C. 1067 The single source of the codes is `seed/omc/error-codes.reg` (issue #797): one row per code with its 1068 status (emitted, io or unused), the `seed/omc/gate15.sh` case that must refuse with it, and the 1069 meaning below. `seed/omc/codereg.om` (run by gate15) fails when a `fail`, `nfail`, `unkfail`, 1070 `lenval` or `exit int` site in `omc.om` has no row, when an emitted row has no site, when a row of 1071 this table differs from the registry, or when a registry case did not refuse with its code at its 1072 expected line. Codes 1 and 2 are I/O errors on the compiler's own stdin/stdout (line 0 when the input 1073 cannot be read). In IR mode (section 11) the same codes apply; a contract line (`requires`, 1074 `ensures`, `invariant` not followed by `=`) is error 30 there. irwasm exit codes are a separate namespace (section 11.1). 1075 1076 | Code | Meaning | 1077 |---|---| 1078 | omc 1 | the compiler's standard input could not be read | 1079 | omc 2 | the compiler's standard output could not be written | 1080 | omc 3 | unknown name or field, or a word this mode does not provide | 1081 | omc 4 | the line ends where a word or value is needed | 1082 | omc 5 | extra words after a complete statement | 1083 | omc 6 | malformed number or token | 1084 | omc 7 | type mismatch | 1085 | omc 8 | number out of range for its type or place | 1086 | omc 9 | word or declaration in a place that does not allow it | 1087 | omc 10 | duplicate name | 1088 | omc 11 | bare number without a type from its context | 1089 | omc 12 | register pool exhausted | 1090 | omc 13 | name too long (63 bytes; 8 for an abstract, a layout, a layout field, or any name in IR mode) | 1091 | omc 14 | capacity exceeded (the host refused to grow the compiler's arena or its memory ceiling OMC_MEMORY_MAX was reached, value nesting past omc's own stack, the program image, or an OM-2 expansion bound) | 1092 | omc 15 | missing end | 1093 | omc 16 | syntax: unknown or misplaced word | 1094 | omc 17 | line after ret, break, continue, trap or exit in the same block | 1095 | omc 18 | a function with a result can reach its end | 1096 | omc 19 | global passed as an argument, or one array twice in a call | 1097 | omc 20 | write to a view or a text | 1098 | omc 21 | constant index outside the array | 1099 | omc 22 | malformed text literal | 1100 | omc 23 | size capacity | 1101 | omc 24 | AArch64 branch displacement out of range | 1102 | omc 25 | unknown target, an AArch64-only path on another target, or an x86efi refusal (bare unit, Linux host word, efi OP literal outside 0..14) | 1103 | omc 26 | the compiler's environment entry OMC_MEMORY_MAX is not empty, 0 or 1 to 19 decimal digits below 2^63, or an entry is too long to read whole | 1104 | omc 27 | fresh element read before it is definitely written, or fresh array passed on | 1105 | omc 28 | abstract type: seal outside its constructor, or an unsupported holds | 1106 | omc 29 | external layout out of bounds or misplaced | 1107 | omc 30 | contract syntax misplaced or not supported here (IR mode included) | 1108 1109 ## 10. Native host extension (2026-10-23) 1110 1111 Implemented by the Omega-written compiler in `seed/omc/omc.om`. The original 1112 om4 parent builds this extended compiler; the extended compiler reproduces 1113 itself byte for byte. The original subset retains its machine code. The new 1114 words are reserved and require program mode (error 9 in function mode), with one 1115 exception: an OM-2 function unit (first line `om2`, no `fn main`) may use the file 1116 and identity subset `fopen`, `fclose`, `fstat`, `stat`, `lstat`, `getuid`, 1117 `geteuid`, `getgid` and `getegid`, the clocks `monons`, `realns` and `sleepns`, and 1118 the device subset `devctl`, `mapnew`, `mapdrop`, `mapread`, `mapwrite`, `devcall`, 1119 `uvmctl`, `mapaddr`, `mapget`, `mapset`, `maphold` and `mapbind` (`seed/host/MAPPING.md`) on the AArch64 1120 target. Each of these is an inline `svc` with its arguments saved and restored around 1121 it; none reads argv, the x28 stack floor or a global, and none writes x7 or x19-x28, 1122 so a unit called through the omega-bridge native ABI keeps its frame. In function 1123 mode entry31 points at a32-byte header followed by1..4098 owned32-byte mapping 1124 slots. The header supplies capacity and nonwrapping generation limits; handles 1125 have13 low slot bits. The bridge selects an explicit context and serializes 1126 its calls. Fixed bind replaces only an entire live PROT_NONE reservation in 1127 that table. Failed bind retires its token on successful cleanup; a cleanup 1128 failure traps3 and leaves an inaccessible, un-rebindable owner for mapdrop only 1129 (mapaddr may inspect it). The bridge refuses destroy while it is live. 1130 Program mode retains its raw128 1131 slots and eight slot bits. Every other host word, every OM-1 function unit and 1132 other targets stay error9. This context-format contract is a draft requiring 1133 Drake approval before merge (PROPOSED `spec/omegese-om3.md` section1, gate 1134 `seed/omc/om2/fnhost/fnhost.cases`). 1135 1136 All results below have type `long`. Successful kernel results are nonnegative; 1137 failures return minus the Linux error number. Programs must check errors. 1138 These operations do not form a sandbox: they operate with the process's 1139 existing permissions. They expose no pointer values and no arbitrary syscall. 1140 1141 In signatures, `fd`, `flags`, `mode`, `pid`, `signal`, `events`, `domain`, 1142 `kind`, `protocol`, `backlog`, `target`, `options`, `level`, `option`, `whence` and `op` are `int`. 1143 Offsets, byte counts, capacities and argument indices are `ulong`. File offsets 1144 and time intervals are `long`. `A` is a `uchar` array. Every slice checks 1145 `n <= len A` and `off <= len A - n` before kernel access, otherwise trap 3 1146 (program exit 103). Writable operations reject `view` and `text` (error 20). 1147 Non-byte arrays and mismatched scalar types are error 7. 1148 1149 | Expression | Meaning | 1150 | --- | --- | 1151 | `fopen A off n flags mode` | Open a length-delimited path relative to the current directory. Return descriptor. `flags` are Linux asm-generic `O_` values on every target; under `target x86linux` the compiler renumbers O_DIRECTORY, O_NOFOLLOW, O_DIRECT and O_LARGEFILE to x86-64's values. | 1152 | `fclose fd` | Close descriptor. | 1153 | `fsync fd` | Sync file data and metadata. | 1154 | `fdsync fd` | Sync file data only (`fdatasync`). | 1155 | `memfd A off n flags` | Create an anonymous in-memory file and return its descriptor (`memfd_create`). | 1156 | `fchmod fd mode` | Set permissions on an open descriptor. | 1157 | `chmod A off n mode` | Set permissions on a checked path (`fchmodat`, flags 0). | 1158 | `chown A off n uid gid` | Set ownership on a checked path (`fchownat`, flags 0). | 1159 | `faccess A off n mode` | Check access to a checked path (`faccessat`, flags 0): mode 0/1/2/4. | 1160 | `getuid` / `geteuid` / `getgid` / `getegid` | Process identity (syscalls 174-177). | 1161 | `fchdir fd` | Change the working directory to an open directory descriptor. | 1162 | `getppid` | Parent process id. | 1163 | `setsid` | Create a session and become its leader. | 1164 | `getpgid pid` | Process group id of `pid` (0 = self). | 1165 | `getsid pid` | Session id of `pid` (0 = self). | 1166 | `syncfs fd` | Sync the filesystem containing an open descriptor. | 1167 | `shutdown fd how` | Shut down part of a connected socket. | 1168 | `flock fd op` | Advisory whole-file lock (Linux `flock`, ARM64 syscall 32; keyword id 197). `op` is passed unchanged: 1 `LOCK_SH`, 2 `LOCK_EX`, 8 `LOCK_UN`, plus 4 `LOCK_NB` for no wait. Returns 0 or -errno: -11 when a `LOCK_NB` request is held by another open file, -22 for any other op, -9 for a closed fd. The lock belongs to the open file, so it is released when the last descriptor sharing that open file is closed. Fixture `seed/host/tests/flock.om`. | 1169 | `setpgid pid pgid` | Set a process's group (0 = self/own pid). | 1170 | `umask mask` | Set the file-mode mask; return the previous mask. | 1171 | `fseek fd offset whence` | Seek and return the resulting signed file offset. | 1172 | `ftrunc fd length` | Set an open descriptor's length (Linux `ftruncate`). | 1173 | `truncate A off n length` | Set a checked path's length (Linux `truncate`). | 1174 | `unlink A off n` | Remove the named file. | 1175 | `makedir A off n mode` | Create a directory. | 1176 | `rmdir A off n` | Remove an empty directory. | 1177 | `cwd A off capacity` | Write the current directory into writable bytes. Return the kernel byte count including the trailing zero byte. A short buffer returns a negative error. | 1178 | `chdir A off n` | Change the working directory to a checked, nonempty path. Return 0 or -errno. | 1179 | `readlnk PATH off n OUT off capacity` | Read a symbolic link through a checked, nonempty path into writable output bytes. Return the byte count without a terminator. A result equal to capacity may be truncated. | 1180 | `getdnts fd A off n` | Write raw Linux `getdents64` records; return bytes written. | 1181 | `fstat fd A off n` | Write the 128-byte Linux ARM64 stat structure; requires capacity at least 128. | 1182 | `stat A off n B off capacity` | Metadata for a checked path via `newfstatat`; writes the same 128-byte ARM64 structure; a short output traps 3. | 1183 | `lstat A off n B off capacity` | As `stat`, but does not follow a final symbolic link (`AT_SYMLINK_NOFOLLOW`). | 1184 | `renames A off n flags` | Rename the two paths in a packed list using `renameat2`; flag 1 refuses replacement. | 1185 | `link A off n` | Create a hard link from a packed two-path list (old, new). | 1186 | `symlnk A off n` | Create a symbolic link from a packed two-path list (target text, link path). | 1187 | `monons` | Monotonic nanoseconds, suitable for elapsed-time measurement. | 1188 | `realns` | Realtime nanoseconds since the Unix epoch, suitable for timestamps. | 1189 | `sleepns interval` | Sleep for nonnegative nanoseconds. Negative intervals trap 3. Interruptions return the kernel error. | 1190 | `socknew domain kind protocol` | Create a socket. | 1191 | `bind fd A off n` | Bind the socket to the address bytes in the slice. | 1192 | `connect fd A off n` | Connect using the address bytes in the slice. | 1193 | `listen fd backlog` | Listen for connections. | 1194 | `accept fd flags` | Accept a connection with `accept4`; return descriptor, without peer-address output. | 1195 | `sockname fd A off n` | Write socket address bytes; return the full address length, which may exceed capacity when truncated. | 1196 | `peername fd A off n` | Query the connected peer of an existing descriptor into a writable byte slice; return full peer-address length, or negative errno. A result greater than `n` truthfully indicates truncation. | 1197 | `sockopt fd level option A off n` | Set one allowlisted scalar transport option from a readonly four-byte slice; see the allowlist below. | 1198 | `recv fd A off n flags` | Receive into a writable slice. | 1199 | `send fd A off n flags` | Send a slice with `MSG_NOSIGNAL` added, so a closed peer returns an error. | 1200 | `waitio fd events interval` | Poll one descriptor. Return readiness bits, zero on timeout, or negative errno. Interval is nanoseconds; negative means infinite. Events outside 0..65535 trap 3. | 1201 | `peercred fd A off capacity` | Read Linux `SO_PEERCRED` into a writable slice of at least 12 bytes: little-endian 32-bit PID, UID, GID; return zero or negative errno. | 1202 | `pollfds A off n interval` | Poll a writable slice of packed eight-byte Linux `pollfd` records. `n` is bytes, a multiple of eight, at most 8192. Return ready-entry count, zero on timeout, or negative errno. Interval is nanoseconds; negative means infinite. | 1203 | `sendmsg fd A off n flags` | Send one checked payload using a private `msghdr` and single `iovec`, without ancillary data or destination-address override. Adds `MSG_NOSIGNAL`; returns a possibly partial byte count or negative errno. | 1204 | `fork` | Copy the current process: zero in the child, child PID in the parent, negative errno on failure. | 1205 | `getpid` | Return the current process ID. | 1206 | `killpid pid signal` | Send a signal; zero signal checks existence/permission. | 1207 | `waitpid pid A off n options` | Wait with `wait4`; write a four-byte status, return PID or zero for an unfinished nonblocking wait. Capacity at least four. | 1208 | `pipefds A off n flags` | Create a pipe with `pipe2`; write two little-endian 32-bit descriptors. Capacity at least eight. | 1209 | `dupfd fd target flags` | Duplicate onto a chosen descriptor using `dup3`. | 1210 | `execprog A off n` | Replace the process using a packed argument list. Only returns on failure. | 1211 | `execpure A off n` | Keyword id 198, AArch64 only (x86 emission refuses with error 25). As `execprog`, then pin the executable as descriptor 3 and apply the fixed strict stdio profile below before `execveat(AT_EMPTY_PATH)`. Only returns on failure, with the first failing step's negative errno. | 1212 | `execenv A off n B off m` | Keyword id 233, AArch64 and x86linux. As `execprog A off n`, but the child's environment is exactly packet B (u16 count 1..64, nonempty u16-length records, 2..4096 bytes, no embedded zero, no trailing bytes) instead of an empty one. Both packets are checked (trap 3) before descriptors above 2 close. Only returns on failure, with a negative errno; refused in function mode (error 9) and in contracts (error 30). Gate: `seed/host/execenv/`. | 1213 | `prlimit pid res A off n` | Keyword id 235, AArch64 and x86linux: Linux `prlimit64` (syscall 261 / 302). `pid` and `res` are int (0 = this process), A a writable byte array, `off` and `n` ulong. `n` 16 reads: the old `{rlim_cur, rlim_max}` is written to `A[off..off+16)` as two little-endian u64. `n` 32 sets: the new pair is read from `A[off..off+16)` and the old pair is written to `A[off+16..off+32)`. Any other `n` returns -22 without a kernel call; with `n` 32 the kernel also returns -22 (EINVAL) when the new soft value is above the new hard value, which does not mean a bad `n`. The slice `A[off..off+n)` is checked first (trap 3). Returns 0 or a negative errno. Limits are inherited across `fork` and kept across `execprog` (the gate checks RLIMIT_AS in an exec'd child). Refused in function mode (error 9), in contracts (error 30) and under `target x86efi` (error 25). Gate: `seed/host/prlimit/`. | 1214 | `cpuset pid A off n` | id 236: Linux sched_setaffinity (AArch64 122, x86linux 203). int pid (0 calling thread), checked byte mask slice, returns long 0 or minus errno; an empty permitted mask is -22. | 1215 | `cpuget pid A off n` | id 237: sched_getaffinity (123 / 204), same operands but writable bytes; long count of bytes copied or minus errno. | 1216 | `cpunow` | id 238: getcpu (168 / 309), no operands; long CPU number snapshot or minus errno. | 1217 | `setprio which who priority` | id 239: setpriority (140 / 141), three int operands; long 0 or minus errno. which 0, who 0 selects this thread. Linux privilege checks remain. | 1218 | `getprio which who` | id 240: getpriority (141 / 140), two int operands; long raw kernel result 20 minus nice, or minus errno. All five scheduler words are program-only; function mode error 9, contracts 30, x86efi 25. Draft: spec/omegese-cpu-workers.md. | 1219 | `argcnt` | Return argument count, including the executable name. | 1220 | `argread index A off capacity` | Copy argument bytes without a terminator; return byte length. An invalid index traps 3. Insufficient capacity returns -105 without changing the slice. | 1221 | `envcnt` | Return the number of entries in the process environment (the `envp` the kernel supplied). | 1222 | `envread index A off capacity` | Copy one environment entry without its terminator; return its byte length. An index at or past `envcnt` traps 3; insufficient capacity returns -105 without changing the slice. | 1223 | `random A off n flags` | Fill a writable byte slice from Linux `getrandom`. Return the bytes written or -errno. `flags` is `int`: 0 blocks until the pool is ready, 1 `GRND_NONBLOCK`, 2 `GRND_RANDOM`, 4 `GRND_INSECURE`; other flags return -EINVAL. | 1224 1225 ### Path and process boundaries 1226 1227 Paths are at most 4095 bytes. Embedded zero bytes and longer paths trap 3 1228 before a kernel operation. The compiler privately copies and terminates paths 1229 at the Linux boundary; Omega array lengths remain explicit. Private stack 1230 space is checked against the existing stack floor before writing. 1231 1232 `readlnk` additionally rejects an empty path with trap 3. Its path may be a 1233 readonly slice; its output must be writable. Both slices receive the ordinary 1234 array bounds and byte-type checks. The private path copy is complete before 1235 the kernel writes the output, so overlapping path and output slices are safe. 1236 `cwd` requires writable bytes. It preserves the kernel's count convention: 1237 the returned count includes its trailing zero byte. `readlnk` never appends a 1238 zero byte. These operations are Linux `getcwd` and `readlinkat(AT_FDCWD)`. 1239 `sockopt` is Linux `setsockopt`, restricted to `SOL_SOCKET` (level 1) 1240 `SO_REUSEADDR` (2), `SO_REUSEPORT` (15), `SO_KEEPALIVE` (9), `SO_SNDBUF` (7), 1241 `SO_RCVBUF` (8), and `IPPROTO_TCP` (level 6) `TCP_NODELAY` (1). 1242 Each value is exactly four little-endian bytes. An unlisted level/option returns 1243 `-92` (`ENOPROTOOPT`) without invoking the kernel; an allowed option with a 1244 different length returns `-22` (`EINVAL`). Kernel errors for listed operations 1245 are preserved, including `-9` (`EBADF`) and `-95` (`EOPNOTSUPP`) when a socket 1246 family does not support a listed option. No pointer-bearing option is exposed. 1247 1248 `peername` uses Linux AArch64 `getpeername` (syscall 205), not `getsockname` 1249 (204); under `target x86linux` it uses x86-64 `getpeername` (52), not 1250 `getsockname` (51). It shares `sockname`'s checked writable slice and private 32-bit 1251 length convention. Zero capacity is allowed, including at the array end; 1252 success still returns the full address length without writing address bytes. 1253 The checked array capacity fits the kernel's signed 32-bit length. No descriptor 1254 is created or connected. The descriptor is an existing process descriptor; 1255 callers must control its lifetime, including close/reuse races. 1256 Consume output only after success and after checking length and address family. 1257 The native Linux sockaddr describes the transport endpoint, not an authenticated 1258 user or an original client behind a proxy. Forwarding headers gain no authority. 1259 Existing trusted-proxy policy remains a separate caller responsibility. 1260 1261 `peercred` is kernel-attested local peer identity, not application authorization. 1262 Use it only on a connected Unix socket and compare the returned identity with 1263 the service's explicit policy. Unavailable or unexpected credentials must fail 1264 closed. Capacity below 12 traps 3 before the syscall; extra capacity is untouched. 1265 1266 Each `pollfds` record is `fd:int32`, `events:uint16`, `revents:uint16`, in 1267 little-endian byte order. The kernel updates `revents` in place. Misaligned byte 1268 lengths and lengths above 8192 trap 3. A zero-length slice is a timed sleep. 1269 Applications must inspect error/hangup bits and every syscall result. 1270 1271 Networking errors use the existing stable Linux-arm64 negative-errno contract: 1272 `-4` interrupted, `-11` would block, `-32` broken pipe, `-110` timeout, 1273 `-111` refused, and `-115` connect in progress. `read`, `write`, `send`, `recv`, 1274 and `sendmsg` may complete partially. The library must advance by the actual 1275 count, distinguish EOF from errors, retry interruptions within a monotonic 1276 deadline, and wait for readiness on nonblocking sockets rather than spin. 1277 Never retry `fclose` after an error: the descriptor may already be released. 1278 1279 A packed list is a little-endian `u16` count followed by that many records, 1280 each a little-endian `u16` byte length and those bytes. There is no padding or 1281 terminator in the public format. An exec argument packet (`execprog`, `execpure` 1282 and the first packet of `execenv`) is at most 65536 bytes with count 1..1024; 1283 every other packed list (`renames`, `link`, `symlnk`, the `execenv` environment) 1284 is at most 4096 bytes with count 1..64. Embedded zero bytes, truncated records, extra trailing 1285 bytes and out-of-range counts trap 3. `execprog` uses the first record as both 1286 the executable path and argument zero; it must be nonempty. Other arguments 1287 may be empty. `renames` requires exactly two nonempty path records. 1288 1289 The compiler constructs private, bounded pointer lists for the kernel. They 1290 are never exposed as language values. `execprog` supplies an empty environment, 1291 preserves the working directory and standard streams (descriptors 0, 1 and 2), and does 1292 not search PATH or invoke a shell. Before execution it closes every descriptor 1293 at or above 3 using Linux `close_range(3, UINT_MAX, CLOSE_RANGE_UNSHARE)` 1294 (AArch64 and x86-64 emission alike). 1295 If that kernel operation fails or is unavailable, execution is refused with 1296 the kernel's negative error result; no descriptor-loop fallback is used. 1297 After a successful close, an executable-path failure still leaves those descriptors 1298 closed. Malformed packets trap before descriptor closure. Callers must explicitly 1299 bind intended streams before invoking `execprog`; higher-numbered descriptor 1300 inheritance is unsupported. This prevents accidental descriptor inheritance; 1301 it does not restrict filesystem paths, network creation, current-directory access, 1302 subprocesses or arbitrary native code. Existing authority/launcher integration is 1303 still required for those effects. Forked children are independent 1304 processes and must be reaped; this extension does not add shared-memory threads. 1305 1306 `execpure` (word 198) decodes and closes descriptors exactly as `execprog`, then applies a fixed 1307 strict stdio profile before entering the program: it opens the executable path `O_PATH|O_CLOEXEC` 1308 as descriptor 3; creates a Landlock ruleset that handles every ABI-3 filesystem right and allows 1309 only execute and read-file beneath that inode; sets `PR_SET_NO_NEW_PRIVS`; restricts itself to the 1310 ruleset; sets seven `prlimit64` ceilings (CPU 1/2 s, file size 1 MiB, stack 8 MiB, core 0, processes 1311 0, descriptors 4, address space 128 MiB); installs a seccomp filter that kills the process on a 1312 non-AArch64 audit architecture and allows only `read` on descriptor 0, `write` on descriptors 1 and 1313 2, `exit`, `exit_group` and `execveat` on descriptor 3 with flags `AT_EMPTY_PATH`, returning EPERM for 1314 everything else; and finally calls `execveat(3, "", argv, empty envp, AT_EMPTY_PATH)`. The first step that returns a 1315 negative value restores the private stack and returns that negative errno without executing. 1316 There is no weaker fallback. This is a fixed profile, not a general sandbox; output and wall-clock 1317 budgets still need a trusted supervisor. Qualification is `seed/qualification/security673/gate669.om` 1318 (`pure-*.om` fixtures). The x86-64 emitter has no strict-profile lowering and refuses the word with 1319 error 25. 1320 1321 Clock results require nonnegative seconds and a signed nanosecond total; 1322 values outside that range trap 1. `argread` bounds 1323 its internal string scan at 1 MiB; reaching that bound traps 3. Linux ARM64 is 1324 the only qualified host. OS flags, address layouts and metadata layouts are 1325 host-specific; portable library contracts remain separate work. 1326 1327 Qualification is `sh seed/host/check.sh`; see `seed/host/README.md`. The seed 1328 loader and shell test coordinator do not implement these operations. No 1329 foreign-language compiler or runtime is on the new implementation path. 1330 1331 The proposed device/memory extension adds checked `devctl`, `mapnew`, 1332 `mapdrop`, `mapread` and `mapwrite` to this same compiler, plus the VFIO words 1333 `vfioctl` (literal allowlisted request, exact size, `argsz` forced; IOMMU_MAP_DMA takes an 1334 owned mapping handle, never an address), 1335 `eventfd` (uint initial value, CLOEXEC|NONBLOCK, existing read/write/poll/close), 1336 `vfioirq` (acquired-device/eventfd kinds, exact argsz, bounded IRQ forms), 1337 `vfiomap` (read-only shared map of exactly one reported VFIO region) and `vfiomapw` 1338 (the same map read/write, for device registers). Its exact type, 1339 ownership, range and refusal contract is [seed/host/MAPPING.md](../../seed/host/MAPPING.md). 1340 The VFIO/event words use keywords228..232 respectively as `vfioctl`, 1341 `vfiomap`, `vfiomapw`, `eventfd`, `vfioirq`. They are AArch64 1342 program-mode words; function mode refuses them, and hosted x86 VFIO 1343 is not implemented. Descriptor-kind tracking remains program-local: 1344 existing OM-2 unit `fclose`/`dupfd` emission does not access that 1345 standalone-program table. 1346 The draft `devctl` boundary also admits five exact aien-gpu ABI1 request 1347 numbers, not arbitrary type-A ioctls; changing their direction or encoded 1348 payload size is refused. See the pinned UAPI and Wolfram-derived matrix there. 1349 Drake must approve this trust-surface extension before merge. 1350 It adds process-local mapped resources while the compiler's own storage remains 1351 fixed pools. GPU launch and model execution are separate, still-unqualified gates. 1352 1353 #### `devcall` (keyword 171) 1354 1355 `devcall fd request H hoff 32 P poff n` returns `long`, the ioctl result or 1356 negative Linux errno. `fd` is `int`, `request` a literal `uint` RM_ALLOC or 1357 RM_CONTROL request, `H` and `P` writable `uchar` arrays, and `hoff`, `poff` 1358 and `n` are `ulong`. The header span must be exactly 32 bytes and the 1359 parameter span at most `1048576` bytes (inclusive, the RM default copy-in cap). 1360 Both slices must fit their arrays, must not overlap, and the header's caller 1361 pointer bytes must be zero; violations trap 3 (exit 103). 1362 The checked parameter span is bound directly, not copied onto the stack; 1363 only a private 32-byte header is stack-backed. See 1364 [`MAPPING.md`](../../seed/host/MAPPING.md) for the ABI and upstream cap source. 1365 `seed/host/tests/devcall.om` checks harmless memfd ioctls at 16384, 55888 1366 and `1048576` bytes, and refusal at `1048577` bytes. `devctl` retains its 1367 request-encoded size limit. 1368 1369 #### KFD device words 1370 1371 Program-mode Linux only: native AArch64 and `target x86linux`. Function mode, 1372 including OM-2 functions, refuses these words with error 9; firmware targets 1373 refuse them with error 25. Results are `long`: a handle or syscall result on 1374 success, negative Linux errno otherwise. No device is opened implicitly. 1375 1376 - `kfdres n` reserves a nonzero, 4096-byte-multiple `ulong` length with 1377 `PROT_NONE`, at a kernel-chosen address aligned to 2 MiB. It over-reserves 1378 anonymously and unmaps its own alignment prefix/suffix. Misaligned lengths 1379 and addition overflow trap 3. The old `maphold` address and length limits 1380 do not apply. No physical backing is committed by a reservation. 1381 - `kfdmap fd offset n` maps `n` bytes read/write and shared, without choosing 1382 an address. `fd` is `int`; offset and length are `ulong`; zero length traps 1383 3. Use the DRM render fd for buffer offsets and `/dev/kfd` for doorbells, 1384 according to the kernel's returned offsets. Before mmap, fstat must identify 1385 a character device: DRM major 226 with render minor at least 128, or the same 1386 device number as stat(`/dev/kfd`). Invalid fds, ordinary files and other 1387 character devices trap 3. The span is nonzero and uses the full `ulong` length; 1388 the kernel enforces mapping-offset, page, address-space and device boundaries. 1389 No 32-bit truncation or arbitrary 64 GiB KFD mapping cap is applied. 1390 - `kfdctl fd request H off n ...` uses a writable `uchar` header span. 1391 `request` is a literal `uint` from the KFD 1.14 allowlist; an unknown or 1392 nonliteral request is error 9. A literal header length unequal to the request's 1393 ABI size is error 9; a computed unequal length traps 3 before the ioctl. 1394 Normal array-span bounds checks also apply. 1395 1396 The allowlist covers GET_VERSION, ACQUIRE_VM, GET_PROCESS_APERTURES_NEW, 1397 CREATE_QUEUE, DESTROY_QUEUE, ALLOC_MEMORY_OF_GPU, FREE_MEMORY_OF_GPU, 1398 MAP_MEMORY_TO_GPU, UNMAP_MEMORY_FROM_GPU, CREATE_EVENT, DESTROY_EVENT and 1399 WAIT_EVENTS. It also covers SET_SCRATCH_BACKING_VA: 1400 Linux `kfd_ioctl.h` defines its record at lines 355–359 and its ioctl macro at 1401 1516–1517 in the installed header used by `tests/kfd/check.py`. That test compiles 1402 every AMDKFD_IOC request macro as an independent C UAPI oracle, compares emitted 1403 immediates for admitted requests and requires compile error 9 for every sibling, 1404 including RUNTIME_ENABLE, DBG_TRAP and SET_TRAP_HANDLER. The compiler includes no C. 1405 1406 The suffix depends on the request: 1407 1408 | Request | Suffix and binding | 1409 |---|---| 1410 | GET_PROCESS_APERTURES_NEW | `P poff pn`: writable byte array span or live writable owned mapping handle; offset + length must not wrap and must fit the mapping, and count × 56 must fit `pn`; count zero and `pn` zero are legal | 1411 | MAP_MEMORY_TO_GPU, UNMAP_MEMORY_FROM_GPU | `P poff pn`: device IDs, count × 4 must fit | 1412 | WAIT_EVENTS | `P poff pn`: event records, count × 48 must fit; every extension pointer must be zero | 1413 | ALLOC_MEMORY_OF_GPU | `R`: live reservation handle; requested size must fit; USERPTR flag refused | 1414 | SET_SCRATCH_BACKING_VA | `R`: live reservation handle | 1415 | CREATE_QUEUE | `ring wptr rptr eop ctx`: live read/write handles; ring size at least 1024 and a power of two, ring/eop/context declared sizes fit; distinct `wptr` and `rptr` handles each hold at least 8 bytes and bind at their base; the same handle in both positions selects the AMD queue object (queue type 2, at least 2304 bytes, write pointer at base+56, read pointer at base+128); zero eop/context handles require zero declared sizes | 1416 | Other requests | No suffix; ACQUIRE_VM verifies its `drm_fd` with fstat as a DRM render character descriptor (major 226, minor at least 128) | 1417 1418 **Address-binding rule:** every caller-supplied address field must be zero. 1419 The compiler copies the header privately, validates each handle's generation, 1420 liveness, access kind and size (or each span's bounds), then writes only checked 1421 addresses into the private ioctl record. Header and payload spans must not 1422 overlap. Copy-out excludes address fields, so those bytes remain zero even 1423 when the kernel returns an error. Invalid handles, kinds, sizes, addresses, 1424 overlapping spans, USERPTR and event extensions trap 3 (exit 103). 1425 Opaque kernel allocation handles and mmap offsets are values, not pointers. 1426 For the aperture mapping form, the private pointer is the checked mapping base plus `poff`; the header's `num_of_nodes` is copied back, including on a zero-count query, while its address bytes remain zero. 1427 1428 **AMD queue object.** Naming one handle as both `wptr` and `rptr` selects the 1429 AMD queue layout. The positions come from the compiler, never from caller 1430 bytes: write_dispatch_id at base+56 and read_dispatch_id at base+128. The 1431 request must have queue type 2 (COMPUTE_AQL), and the whole 2304-byte 1432 `amd_queue_v2_t` must lie inside the writable mapping, so every field the 1433 firmware may read or write is inside checked memory. Any other queue type with 1434 a shared handle traps 3. Distinct handles keep base-only binding with 8 bytes 1435 each. Ring, EOP and context addresses are always the handle's base. 1436 The numbers come from ROCm's `amd_hsa_queue.h` (64-byte aligned; both 1437 versions place write_dispatch_id after the 40-byte `hsa_queue_t`, caps and 1438 three reserved words, and read_dispatch_id after reserved2). The v1 1439 `amd_queue_t` is 256 bytes; CP firmware reads the v2 fields past it when the 1440 caps word, which is caller data and can change after the ioctl, carries 1441 AMD_QUEUE_CAPS_SW_ASYNC_RECLAIM. Requiring the v2 extent (256 bytes plus 1442 `scratch_last_used_index[MAX_NUM_XCC]`, MAX_NUM_XCC 128, 16 bytes each; 1443 measured with a C build of that header: sizeof 2304) keeps the firmware inside 1444 the mapping whatever the caps word holds. 1445 1446 Use one reservation per GPU allocation. After ALLOC, existing 1447 `mapbind R renderfd mmap_offset 3` replaces the entire owned reservation 1448 with a shared mapping at exactly the same address, keeping `R` usable as a 1449 read/write handle; failure retires it. `mapaddr R` gives the checked base 1450 as a `ulong` for AQL/kernarg data, never as an unchecked ioctl address. 1451 `mapget`, `mapset`, `mapdrop` and `cpufence` retain their existing contracts. 1452 The existing program mapping table's handle capacity is unchanged. 1453 GPU VM mappings require 4096-byte alignment: upstream 1454 [`amdgpu_gart.h`](https://github.com/torvalds/linux/blob/master/drivers/gpu/drm/amd/amdgpu/amdgpu_gart.h) 1455 defines `AMDGPU_GPU_PAGE_SIZE`, and 1456 [`amdgpu_vm.c`](https://github.com/torvalds/linux/blob/master/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c) 1457 rejects a start, offset or size with bits in `AMDGPU_GPU_PAGE_MASK`. 1458 The 2 MiB reservation alignment is a stronger compiler guarantee for large 1459 pages, not a claim that every KFD allocation requires 2 MiB. Actual mapping 1460 offsets and sizes remain subject to the target kernel. No raw virtual address 1461 operand exists, so an unaligned caller address cannot reach ALLOC or SCRATCH. 1462 1463 CPU acceptance: `python3 tests/kfd/check.py`. `/dev/kfd` absence is `fopen` 1464 errno -2. Native invalid-fd ioctl calls return -9; QEMU-user currently returns 1465 -25 for its unsupported KFD ioctl translation before looking up that fd. 1466 Both are checked separately. CPU/emulator acceptance is not AMD device 1467 qualification; all device rows remain NOT_RUN until an authorized device run. 1468 The native AArch64 ptrace oracle observes every bound address at the syscall 1469 boundary and poisons private output pointer fields after a real EBADF; caller 1470 pointer bytes must remain zero. Independently compiled compiler mutants 1471 remove request, literal/dynamic size, address, kind, fd-class or function-mode refusals and must be 1472 detected. `--record-history` appends measured compiler facts to the existing 1473 size ledger only after the CPU gate passes; it never rewrites historical rows. 1474 1475 ### Host CPU ordering words (#939) 1476 1477 | Statement | Meaning | 1478 |---|---| 1479 | `cpufence` | Publication barrier (keyword id 199). Every load and store before it completes before any load or store after it. AArch64: `DSB SY` (``d5033f9f``), the barrier `mapget`/`mapset` already bracket their access with. x86-64 (`target x86linux`): `MFENCE` (`0f ae f0`), the fence the x86 `mapget`/`mapset` use. | 1480 | `cpurelax` | Spin-wait hint, no ordering (keyword id 200). AArch64: `YIELD` (``d503203f``). x86-64: `PAUSE` (`f3 90`). Use it inside a bounded poll loop and pair it with `cpufence` when order matters. | 1481 1482 Both are statements with no operands and no value. Unlike the other host words 1483 they are accepted in function mode as well as program mode, because they make no 1484 system call. An operand is error 5, use as a value or outside a function is 1485 error 16, use as the name on the left of `=` is error 5, and a statement after 1486 `ret` is error 17. IR mode (`ir` first line) refuses them with error 16. 1487 `seed/host/cpufence.sh` (run by `seed/host/check.sh`) checks each refusal 1488 except the IR one, plus a function-mode unit, on the host. The fixture 1489 `seed/host/tests/cpufence.om` exits 42 natively on AArch64 and under 1490 qemu-x86_64. GNU objdump, used only as a referee, finds exactly one added 1491 `dsb sy`/`mfence` per `cpufence` and one `yield`/`pause` per `cpurelax`, 1492 compared with the same program with the words deleted. The script also checks 1493 the refusals above and builds a compiler whose `cpufence` emits NOPs. That 1494 compiler still runs the fixture to exit 42, and the instruction count catches 1495 it. These are host results only. Ordering against a GPU is not qualified here. 1496 1497 ## 11. OSC IR output (omc only, experimental checkpoint) 1498 1499 A leading line `ir`, before any other line, puts omc in IR mode: it writes OSC IR version 1 1500 (`spec/one-layer-format.md`) for a unit of up to 32 functions instead of AArch64 machine words, and 1501 the AArch64 path is not taken. Every function is encoded in source order. A function may call an 1502 **earlier** function (self and forward calls are error 3) with at most six arguments; a 1503 value-returning call composes as a value, a void call is a statement, and using one where the other 1504 is needed is error 7. Argument types are checked at compile time (error 7). `break` lowers to a 1505 `BR` to the innermost loop's exit and marks the path dead; `continue` is still refused (error 3). 1506 A `TYPE value` cast reads its operand at the operand's own type and converts it, exactly as the 1507 AArch64 path does: `ret ulong sub c 48` with `c` a `uchar` lowers to a `sub` then a `cast`. A bare 1508 number in the cast is range-checked against the cast's type (error 8), a bare number inside the 1509 operand against the operand's type (error 8), and a bool converts to or from a number only by 1510 comparison (error 9). A same-type cast of a constant is the constant itself; any other same-type 1511 value is a `mov`. 1512 1513 The producer validates complete statement lines rather than discarding 1514 trailing words (error 5); missing operands are error 4 and untyped bare 1515 expressions error 11. Locals and loop counters obey block scope, including 1516 the `else` boundary; redeclaring an in-scope name is error 10, and reading 1517 an out-of-scope name is error 3. Locals and parameters retain the native 1518 eight-byte name limit (13), while function names retain full matching up 1519 to 63 bytes. A reachable non-void function end is error 18; a void end 1520 emits an implicit return. Missing function `end` is error 15. Unsupported 1521 float parameter/result types are refused with error 9 before serialization. 1522 Typed literals are range-checked (8). Parentheses remain unsupported in 1523 this scalar IR checkpoint, rather than being silently discarded. 1524 1525 `seed/omc/gate-ir.sh` compares 10 dev programs, nine hand-written multi-function call units and 30 1526 randomized two-function call units byte-for-byte with the C-built `omegese` + `omega_emit` oracle, requires `checker2` to ACCEPT every unit, requires 1527 a mul-to-add mutant to differ, and pins refusal cases. Its validation regressions 1528 cover trailing/missing words, scopes, scalar types, literal bounds and name 1529 limits; positive controls include implicit void returns, sequential `for` 1530 counters, scope reuse and functions sharing a name prefix. Those C tools 1531 are referees only; they never write omc's bytes. 1532 1533 Boolean `and`, `or` and `xor` lower to the IR bitwise sub-operations, just as on the 1534 native path. `gate-ir.sh` checks all three against the C encoder and checker2. 1535 Arithmetic (`add` through `rem`) and shifts of booleans remain error 7. 1536 1537 Limits, said plainly: scalar values, calls to earlier functions, at most 32 functions and 6 1538 parameters. IR mode refuses a `struct`, `global` or `text` declaration with error 9 and refuses a 1539 float word, a host word, `continue`, `sizeof` or `offsetof` with error 3, and a contract line 1540 (`requires`, `ensures`, `invariant`; section 12 is native only) with error 30 on that line (#791); it 1541 never skips a declaration it cannot lower or reads a contract clause as a local. A contract word followed 1542 by `=` (`ensures = ulong 1`) assigns a local of that name, as the C oracle and native mode do. `note` lines are 1543 skipped. Struct IR remains open. The gate needs the 1544 C-built oracles, so `seed/host/check.sh` runs it only when `build/omegese/omegese`, 1545 `build/omega_emit/omega_emit` and `build/checker2/checker2` exist, and says `SKIP` otherwise. 1546 1547 ### 11.1 WebAssembly MVP from seeded Omega 1548 1549 `seed/wasm/irwasm.om` reads OSC IR v1 from stdin and emits a deterministic, 1550 import-free WebAssembly MVP module to stdout. The implementation and binary writer 1551 are seeded Omega; neither C nor Node participates in generation: 1552 1553 ```sh 1554 seed/out/omc < seed/wasm/irwasm.om > irwasm 1555 chmod +x irwasm 1556 { printf 'ir\n'; cat functions.om; } | seed/out/omc > functions.ir 1557 ./irwasm < functions.ir > functions.wasm 1558 nice -n 19 sh seed/wasm/gate-irwasm.sh 1559 ``` 1560 1561 The path is a backend for the existing OSC scalar wire format, not a universal 1562 source converter. Every IR function is exported under its original, unique 1563 ASCII name. For a v1 unit no memory, table, start function, imports, WASI or 1564 JavaScript runtime is required, and the sections are type, function, export 1565 and code, in that order (v7 additions below). 1566 Fixed-width five-byte unsigned LEB section/body lengths are valid MVP encodings; 1567 all other LEB fields use minimal encodings. 1568 1569 | IR scalar tag | Wasm parameter/result | Internal representation and operations | 1570 |---|---|---| 1571 | 0 void | no result | no value register may have tag 0 | 1572 | 1 bool | i32 | canonical 0/1 in an i64 local; logical not and bitwise AND/OR/XOR | 1573 | 2 u8, 3 u16, 4 u32 | i32 | zero-extended i64; unsigned operations, mask after wrapping arithmetic | 1574 | 5 u64 | i64 | all bits preserved; unsigned compare/div/rem/right shift | 1575 | 6 i8, 7 i16, 8 i32 | i32 | sign-extended i64; signed compare/div/rem/right shift, checked arithmetic | 1576 | 9 i64 | i64 | signed compare/div/rem/right shift; checked arithmetic | 1577 1578 CONST/MOV preserve canonical bits. BIN subcodes 1..10 map to 1579 add/sub/mul/div/rem/and/or/xor/shl/shr; UN 1..3 map to negation, 1580 bitwise not and logical not; CMP 1..6 map to eq/ne/lt/le/gt/ge with the 1581 operand's signedness. Signed add/sub/mul/neg/left-shift overflow traps rather 1582 than wrapping; unsigned results wrap at their declared width. Shift counts 1583 are checked before wasm can mask them. Division by zero traps; signed 1584 MIN/-1 division traps, while MIN%-1 is zero. CAST checks the destination range 1585 before changing width/signedness. CALLs name earlier functions and preserve 1586 each declared ABI type, including void. RET converts the internal local to 1587 the declared ABI. TRAP and every failed numeric check become wasm traps 1588 (`WebAssembly.RuntimeError`); MVP does not preserve the numeric Omega trap code. 1589 1590 BR/CBR lower through an i32 block-dispatch local inside `block`/`loop`, 1591 with per-block `if`, `br` and `br_if`. This handles loops, joins, nested 1592 conditionals and `break` without assuming reducible input. The original 1593 lowered loop-bound instructions remain in the stream. Arbitrary IR cycles 1594 are not independently proven bounded here: this is a backend, not checker2. 1595 1596 Limits are OSC v1 only: at most 32 functions, 6 parameters, 480 registers, 1597 512 blocks and 4096 instructions per function; names at most 63 ASCII bytes; 1598 contract texts at most 255 bytes; input at most 2,620,251 bytes, buffered 1599 output at most 8,388,608 bytes. Tags 10..12, versions 2..5, allocation, 1600 memory/arena/pool/slice operations and all unknown opcodes are refused. 1601 Blocks must partition instructions and end in BR/CBR/RET; scalar types, 1602 call signatures, constant canonicality and definite assignment are checked. 1603 Contract text is retained only as input metadata: its executable checks 1604 must already be present as IR instructions. 1605 1606 | Code | Named stderr refusal | 1607 |---|---| 1608 | irwasm 20 | MAGIC | 1609 | irwasm 21 | VERSION (anything except v1 and v7; v7 with no v7 feature) | 1610 | irwasm 22 | TRUNCATED | 1611 | irwasm 23 | CAPACITY | 1612 | irwasm 24 | UNSUPPORTED_OP | 1613 | irwasm 25 | UNSUPPORTED_TAG | 1614 | irwasm 26 | INVALID (typing, register, block, text, or definite assignment) | 1615 | irwasm 27 | TRAILING | 1616 | irwasm 28 | IO | 1617 1618 Every parse/type/capacity refusal writes no stdout: the module is buffered 1619 until the complete unit and code generation succeed. As with any stream 1620 writer, a later stdout I/O failure cannot retract bytes already written. 1621 The gate pins the compiler digest and compares every export on a fixed 1622 input table with full-width results from real AArch64 Omega drivers. Node 1623 v24.21.0 is solely the read-only validation/execution oracle and is not in 1624 the build path; it can be replaced by another conforming wasm validator. 1625 The gate also compares two translations byte-for-byte, substitutes an 1626 add-to-sub IR-byte mutant into the parity check (must fail), and pins 1627 named refusal exits with empty stdout. This is host evidence, not browser 1628 integration, hardware qualification or a deployment. 1629 1630 Numeric bounds were checked with WolframLanguageEvaluator: 1631 `Table[{w,2^w-1,-2^(w-1),2^(w-1)-1},{w,{1,8,16,32,64}}]`; 1632 the unsigned masks are 1, 255, 65535, `4294967295` and 1633 `18446744073709551615`. The definite-assignment iteration bound was checked 1634 with `512*480+1 -> 245761` (a monotone bit-removal fixed point). 1635 1636 **OSC IR v7 (spec section 10).** irwasm also accepts wire version 7: module, 1637 local and text regions, tags 13 f32 and 14 f64, and opcodes 30 RLOAD, 31 1638 RSTORE, 32 BITCAST and 33 RINIT. A v1 unit translates to exactly the bytes it 1639 did before (the gate checks every v1 fixture). A v7 module adds, in order: 1640 a memory section after the function section (limits flag 1, min = max = the 1641 exact page count, no growth); immutable i32 globals holding the byte offset 1642 of each module and text region; exports for the functions, then `memory`, 1643 then `region.NAME` for each module and text region; one active data segment 1644 per non-empty text region after the code section; and a final custom section 1645 `osc.v7.abi` (function count; per function its name, parameter tags and 1646 result tag; module-region count; per region its name, tag, class and count; 1647 all unsigned LEB) so a host can tell `u8` from `i32` behind an i32. No imports. 1648 1649 | v7 element | Lowering | 1650 |---|---| 1651 | 13 f32, 14 f64 | wasm f32/f64 at the ABI; inside, the bit pattern in an i64 local (wrap/reinterpret on use, so NaN payloads move exactly through CONST, MOV, regions and BITCAST) | 1652 | BIN add/sub/mul/div, UN neg, CMP 1..6 on floats | IEEE f32/f64 operations; CMP gives canonical 0/1 | 1653 | CAST int to float, f32 to f64, f64 to f32 | convert_s/u, promote, demote | 1654 | CAST float to int | saturating: NaN gives 0, values beyond the range give its nearest end, others truncate toward zero; written without the non-MVP trunc_sat opcodes | 1655 | BITCAST | same width class: no code beyond renormalizing integer signedness | 1656 | RLOAD/RSTORE | full-width index compared unsigned against the region count before any address arithmetic (a negative index is a huge unsigned value), trap if not below it; then i64 to i32 wrap, shift by the element width, static region offset in the memarg | 1657 | RINIT | a bounded loop storing the value into every element of the function's local region | 1658 1659 Every region, local ones included, gets static storage in table order, 1660 aligned to its element width. A text region's bytes come from its data 1661 segment and are read-only to Omega code (RSTORE and RINIT to text are 1662 refused), though not to a host holding `memory`. Local regions are owned by 1663 one function and only ever seen after that call's RINIT; the validator 1664 computes definite initialization of local regions on every path (unreachable 1665 blocks start with no region initialized), like registers. The memory is at 1666 most 2^31 bytes: `2^31 -> `2147483648`` bytes `= 32768` pages of 65536 1667 (WolframLanguageEvaluator); a larger layout is CAPACITY. At most 1024 1668 regions, `16777216` elements each; a v7 input may be up to 8,388,608 bytes 1669 (the v1 limit of 2,620,251 bytes stays for v1 headers). The region-bit 1670 fixed point is bounded by `512*1024+1 -> 524289` iterations. 1671 1672 Refusals keep the table above. v7 adds: a nonempty struct table is 1673 UNSUPPORTED_TAG (more than 16 structs CAPACITY); region class 3 and opcodes 1674 9/10 are UNSUPPORTED_OP; tags 13/14 or opcodes 30..33 in a v1 unit are 1675 UNSUPPORTED_TAG/UNSUPPORTED_OP; a v7 header on a unit that uses no v7 1676 feature is VERSION, reported after a complete parse; duplicate function 1677 names, duplicate or shadowing region names and an export collision with 1678 `memory` or `region.NAME` are INVALID. 1679 1680 The float-to-int boundaries were computed with WolframLanguageEvaluator as 1681 IEEE bit patterns: f32 2^63 ``5f000000`` (`1593835520`), -2^63 ``df000000``, 2^64 1682 ``5f800000`` (`1602224128`); f64 2^63 ``43e0000000000000`` (`4890909195324358656`), 1683 -2^63 ``c3e0000000000000``, 2^64 ``43f0000000000000`` (`4895412794951729152`). 1684 1685 The gate's v7 section takes its units from the independent hand writer 1686 `seed/wasm/v7/writer.js` plus `seed/wasm/v7cases.js`, and its verdicts and 1687 expected outputs from the independent oracle `seed/wasm/v7/oracle.js`. 1688 Every accepted unit must translate twice to identical, valid wasm; every 1689 refused unit must exit with the oracle's class and empty stdout. For each 1690 run case, `node seed/wasm/v7run.js MODULE SCRIPT` (a read-only executor that 1691 reads `osc.v7.abi`) must print exactly what `oracle.js run` prints. The RGBX 1692 case fills a 16x8 `uint` framebuffer whose byte lanes follow a `text "RGBX"` 1693 table; its sha256 must agree, and a one-channel mutant and a `BGRX` mutant 1694 must hash differently. The out-of-bounds case (index = count, count + 1, 1695 negative i8/i32/i64, u64 with an in-range low 32 bits, all-ones u64) must 1696 trap in both, and an irwasm compiled with its two bounds-check calls 1697 deleted must be caught. 1698 1699 ### Equivalence of scalar IR functions (seed/equiv, issue 826) 1700 1701 `seed/equiv/irequiv.om` is a seeded-Omega interpreter for the same OSC IR v1 units (its reader is 1702 irspirv's v1 reader byte for byte; irwasm's v7 reader is that reader plus the edits recorded in 1703 `seed/equiv/irwasm-v7.sed`). `irequiv check A B` runs both functions on every input of a signature of 1704 at most 24 bits (all 256 for one uchar, all 65536 for a ushort or two uchars) and prints 1705 `EQUIV PASS ... checked=N differing=0`, or `EQUIV FAIL ... differing=K first=` with both 1706 results; equal means the same bits or the same trap code. Wider signatures are only sampled 1707 (`irequiv sample`), printed as `NOT_A_PROOF` with exit 10. A PASS covers the IR both functions 1708 lowered to under `src/compiler/osc_interp.c` semantics, not native words. `seed/equiv/gate-irequiv.sh` 1709 runs the fixture pairs (repo functions js_hexv/hhexv, clamp_add, bitrev8, r8 against refactors and 1710 single-input mutants), then checks `irequiv eval` against native AArch64 programs on the 140 rows of 1711 `seed/wasm/cases.tsv`, `seed/spirv/regression.tsv` and `seed/spirv/demo.tsv` (same bits, same trap 1712 code); `seed/equiv/README.md` has the command line and exit codes. 1713 1714 ### 11.2 Memory profile contract (IR v7) 1715 1716 The backend half of this contract is implemented by `seed/wasm/irwasm.om` 1717 (section 11.1). The producer half (omc's IR mode writing version 7) is separate 1718 work: on this compiler IR mode still writes version 1 only, so the v7 units the 1719 gate translates come from the hand writer `seed/wasm/v7/writer.js`. The authoritative wire 1720 allocation and validation rules are in `spec/one-layer-format.md` section 10. 1721 The milestone name does not repurpose OSC wire version 2. 1722 1723 The source spelling reuses native arrays: 1724 1725 ``` 1726 global pixels uint 4096 1727 text palette "RGBX" 1728 fn frame phase uint to uint 1729 scratch = new uint 4 phase 1730 put pixels 0 get scratch 0 1731 ret get pixels 0 1732 end 1733 ``` 1734 1735 `global` creates mutable per-instance storage; `text` creates a read-only 1736 byte table; `new` creates a function-local fixed-size array whose initializer 1737 is evaluated once at its declaration and copied to every element on each 1738 invocation. `len` is a compile-time element count. A one-element global is 1739 the scalar-state spelling. Mutable globals start at zero and persist 1740 between exported calls. Local storage never exposes a previous call. 1741 1742 `get` and `put` retain exact element typing and bounds behavior: a constant 1743 out-of-range index is error 21, a dynamic negative or high index is trap 3, 1744 and writing text is error 20. All accesses are checked before address 1745 arithmetic; there is no unchecked form. Integer indices do not become valid 1746 by wrapping to a wasm32 address. Elements are naturally aligned and packed 1747 at their scalar width; struct-cell layout is a separate contract. 1748 Type/context/capacity refusals remain errors 7/9/14/23 respectively. 1749 1750 The first memory profile names globals directly from functions. It does not 1751 add array parameters, raw pointers, dynamic allocation or GPU synchronization. 1752 Function/Workgroup storage distinctions are wire contracts, not permission 1753 to lower persistent state to per-work-item temporary storage. 1754 The wasm ABI exports `memory`, original scalar function names, and immutable 1755 `region.NAME` offset globals for module regions. JavaScript can form a typed 1756 framebuffer view and invoke `frame` explicitly; Omega does not install a 1757 browser loop or import JavaScript services. A read-only source table is not 1758 protected from a JavaScript caller that holds the exported memory. 1759 1760 ## 12. Executable native contracts, version 1 (OM-2 extension) 1761 1762 This section extends the seeded native compiler, not the OSC v1 metadata in 1763 section 11.1. `om2` and `om2 debug` check contracts. `om2 release` erases their 1764 runtime evaluation after the same syntax, scope, type and purity checks. 1765 `om2 diag debug` and `om2 diag release` combine the policy with diagnostic 1766 records. `om2 fmt` keeps its existing canonical profile and checks contracts. 1767 OM-1 does not reserve any new words. No environment variable selects policy. 1768 1769 ``` 1770 om2 1771 fn step x uint to uint 1772 requires lt x 10 1773 ensures eq result add x 1 1774 ret add x 1 1775 end 1776 fn main to int 1777 i = uint 0 1778 while lt i 3 1779 invariant le i 3 1780 i = step i 1781 end 1782 ret int sub i 3 1783 end 1784 ``` 1785 1786 ### Declaration and observation points 1787 1788 `requires BOOL` and `ensures BOOL` form a function's prefix, before its first 1789 executable statement. Blanks and `note` lines may separate clauses. A function 1790 has at most 64 prefix clauses. Preconditions execute in declaration order on 1791 entry, after parameter binding, including inline calls. 1792 1793 Postconditions execute in declaration order on **every normal return**: 1794 explicit value/void `ret`, implicit void fallthrough, and inline returns. 1795 They do not execute on `exit`, a trap or abnormal process termination. The 1796 return expression is evaluated exactly once and preserved while checks run. 1797 The read-only name `result` is available only in value postconditions. It has 1798 the declared return type. The caller receives that same value after the checks. 1799 1800 Function predicates bind globals and parameters visible at their declaration, 1801 not names introduced later in the body. A parameter in a postcondition means 1802 its **current value at return**; array reads likewise observe current contents. 1803 There is no implicit entry snapshot and no `old` operator. Reads of `fresh` 1804 output arrays are checked for definite initialization at every return. 1805 1806 `invariant BOOL` forms the prefix of a `while` or `for` body, before any body 1807 statement. There are at most 64 clauses per loop. It sees loop-entry names and, 1808 for `for`, its counter. Clauses run at the **loop head**, before the condition: 1809 on entry even for zero trips, on every backedge, and before the final false 1810 condition. `continue` reaches that head; `for` increments first. `break` 1811 bypasses the next check and makes no promise about the break-exit state. A 1812 return from inside a loop runs function postconditions, not an extra invariant. 1813 Unrolled loops preserve these observation points, including their final 1814 counter value. Their diagnostic `iter` can therefore equal the loop limit. 1815 1816 ### Purity, proofs and failure 1817 1818 Predicates have type `bool`. Their bounded, recursive expression grammar 1819 permits integer/bool literals and names, integer/bool operations and checked 1820 conversions, grouping, `len`, and ordinary checked array/struct/layout reads. 1821 It excludes user calls (including inline calls), floats and abstract values, 1822 host operations, mapped-device operations, allocation, writes and ownership 1823 operations. The exclusion is recursive, including in release and under a 1824 constant expression. `and` and `or` remain eager, never short-circuit bounds 1825 guards. 1826 1827 The checker proves literal `true` and safely folded constant predicates using 1828 the existing checked integer folder. A proof erases evaluation only when the 1829 whole predicate is known to return true without trapping. It does not assume 1830 that arbitrary reflexive expressions are safe. Constant false remains a 1831 runtime failure in debug; release erases it by policy, not by proof. 1832 1833 False `requires` uses existing trap **9** (program exit **109**); false 1834 `ensures` or `invariant` uses existing trap **10** (exit **110**). 1835 Function-mode callers receive those same trap codes through `OscRt.trap`. 1836 An arithmetic, conversion or bounds failure while evaluating a predicate 1837 retains its original trap code. Compiler error **30** means misplaced 1838 contract syntax, unavailable `result`, or a forbidden predicate operation. 1839 Existing type, unknown-name, initialization and capacity errors retain their 1840 codes. Diagnostic trap sites name the predicate's source line. 1841 Error 30 has diagnostic obligation `contract`. Each emitted contract site also 1842 has an `omc-check 1 kept|erased line=N rule=RULE kind=KIND` record in diagnostic 1843 mode: `runtime` for kept checks, `constant-true` for a proof, or `release` for 1844 policy erasure; KIND is `requires`, `ensures` or `invariant`. Deferred 1845 postconditions are reported at their actual return sites, not during entry 1846 validation. 1847 1848 Release erasure removes predicate instructions, trap records and diagnostic 1849 sites, and restores temporary allocation and branch bookkeeping. It never 1850 uses the predicate as an optimizer assumption and never erases the body's 1851 arithmetic, bounds, initialization, stack or loop-fuel protection. Contract 1852 sources still must fit the compiler's validation capacities in release. 1853 1854 Fixtures and exact expected outcomes are in 1855 `seed/omc/contracts/contracts.cases`, using the existing pinned 1856 `seed/qualification/om2/gate.om` conductor. The example above is exercised by 1857 `seed/omc/contracts/ok.om`; release/erased and proved/plain pairs require 1858 byte-identical output, not just equal exit statuses. 1859 1860 ## Native object output (experimental, outside frozen OM-2) 1861 1862 A first line `object`, followed by `om2` or `om2 release`, requests an 1863 AArch64 function-mode object instead of an executable or bare callable unit. 1864 The payload uses the existing function ABI and preserves its trap behavior. 1865 `extern fn NAME ... to TYPE` declares a typed imported function without a body. 1866 Imports must be resolved by the native module linker before execution. 1867 Exports use `export fn`; the existing profiles retain their own behavior. 1868 1869 Objects carry compiler-generated symbols, typed interfaces, call relocations and 1870 stack-cost records. The object format and separate source-digest/compiler-pin 1871 identity checks are specified in `spec/omegese-modules.md`. 1872 This first format accepts scalar and array interfaces. It refuses nominal and 1873 struct/layout interfaces, inline imports, imported fresh scratch contracts, 1874 globals and text literals. Function-mode call cycles still refuse. 1875 1876 Host effects (DRA-542): an object takes `read`, `write`, `exit` and the OM-2 1877 function-mode host subset that needs no program image: `fopen`, `fclose`, 1878 `fstat`, `stat`, `lstat`, `getuid`, `geteuid`, `getgid`, `getegid`, `monons`, 1879 `realns` and `sleepns`. Each compiles to the same code as in function mode, so 1880 a program linked from modules reads, writes, opens files and exits. The device 1881 words 166..177 stay error 9 in an object (their table lives in a runtime context 1882 the module linker does not set up), as do program-only host words (error 9, 1883 function-mode subset). A host word's transient stack (its save area and, for a 1884 path, a private 4096-byte buffer) is charged to the function's stack record: 1885 the record is stkbytes (the whole frame) plus the largest transient push, an 1886 upper bound on the deepest SP the function's own code reaches below its entry 1887 (callees excluded; equal to it when no transient push precedes a frame 1888 allocation, as in the gate's one-statement bodies), and a call's record is the 1889 frame plus everything pushed at that call. omc counts every SP push and pop it 1890 emits; an object function whose count would go below zero or does not return to 1891 zero at its end is refused (error 9, site 628) instead of being under-reported. 1892 Checked by `seed/omc/gate-objhost.sh`. 1893 A function named `main` has no special meaning inside an object. 1894 1895 The object is not an executable. Its linker must validate identities, interfaces, 1896 relocations, whole-program cycles and stack demand before publishing a final 1897 image. Compiler parse refusals leave stdout empty. A failed output write can 1898 leave a partial object, which consumers must reject. Existing OM-1/OM-2 output 1899 does not change unless the explicit object line is present.