interplane.Get Omega
Read in your language

sovereign-intelligence

Front door to Drake Stapleton's sovereign stack.

Brought by drakestapleton

branch main Branches Tags History

sovereign-intelligence / harness / skills / writing-omega / SKILL.md

418 lines · 29663 bytes Raw Blame History Rendered
1---
2name: writing-omega
3description: Portable guide to writing Omega (.om) programs that the seeded omc compiler accepts and runs correctly: program shape, types, words, traps, compiler errors 1..30, common mistakes with the exact refusal, and tested examples. Use before writing or reviewing any .om program on any machine.
4---
5
6# Writing Omega programs
7
8This guide is for any agent or person writing `.om` on any machine. It needs only a clone of
9[aien-dev/omega-mv](https://github.com/aien-dev/omega-mv) and of this repository. Every rule
10below was observed with a program at the pin in the table; the programs are in
11[`examples/`](../../examples/) and [`examples/gate.sh`](../../examples/gate.sh) reruns all of them.
12For compiler internals, register rules, wire formats and the reasons behind each rule, read
13[`skills/omega-encoding/SKILL.md`](../omega-encoding/SKILL.md).
14
15| Pin | Value |
16|---|---|
17| omega-mv commit | `f4df82394e35893dcf1354dda69a2fe028d94bc1` |
18| compiler `seed/out/omc` | sha256 `3ad9f10f64309e7acf8a725082b28e23a2a4aeb07e98322fb4dc0fcd8fc93194` |
19| language reference | `docs/one_layer/OMEGESE.md` at that commit |
20| host | Linux AArch64 only; omc writes a static AArch64 Linux ELF |
21
22The language reference is normative. Where this guide and OMEGESE disagree, the compiler at the pin
23decides; this guide records the known disagreements.
24
25## 1. Compile and run
26
27```sh
28git clone rad://z6do9WDBhuSnvopDkgFdFr1yWA62 omega-mv && cd omega-mv
29git checkout f4df82394e35893dcf1354dda69a2fe028d94bc1
30sha256sum seed/out/omc # must print the pinned hash
31sh seed/omega-from-seed.sh # optional: rebuild omc from the 408-byte loader
32seed/out/omc < prog.om > prog; echo "compile $?"
33chmod +x prog && ./prog; echo "exit $?"
34```
35
36- omc reads the unit on stdin and writes the executable on stdout. Exit 0 means accepted. Any other
37 exit is the error number, and stderr has one line `omc: line N: error K`.
38- **Never run the output of a refused compile**: stdout may still hold bytes.
39- A unit with `fn main` is program mode (an executable). A unit without it is function mode (raw
40 machine words for a host to call); never execute function-mode output directly.
41- Check behavior, not compile success: compare stdout bytes and the exit status with what you
42 expected, and run one deliberately wrong variant to see the check fail.
43- To check a whole set the way this repository does:
44 `examples/gate.sh path/to/seed/out/omc` prints `PASS name` or `FAIL name: reason` per program and
45 ends `GATE PASS examples=N ...` or `GATE FAIL ...` (exit 1); a different compiler hash exits 2.
46
47## 2. Program shape
48
49```
50note hello: the smallest complete program
51text msg "hello, world\n"
52fn main to int
53k = write 1 msg 0 len msg
54if ne k long len msg
55ret 1
56end
57ret 0
58end
59```
60
61([`examples/hello.om`](../../examples/hello.om)). The rules it shows:
62
63- **One statement per line.** No semicolons, no braces. Blocks (`fn`, `if`, `else`, `while`, `for`,
64 `struct`) close with `end`. Indentation is optional.
65- **Prefix words only.** Every operation is a word followed by its values: `add x 1`,
66 `mul add a b c`, `lt i n`. Each word has a fixed number of values. Parentheses may group a value
67 and add nothing: `(add a b)`.
68- **Comments are `note` lines.** `//` and `#` are refused (error 16).
69- **`fn NAME p1 T1 p2 T2 ... to R`**, result `R` a type or `void`. Parameters fill **6 slots**: an
70 OM-2 unsized `view T *` / `edit T *` takes 2 (pointer and count), every other parameter 1 (a
71 scalar, a sized array, a struct). Two unsized views plus three scalars is error 9
72 ([`examples/om2_param_slots.om`](../../examples/om2_param_slots.om),
73 `mistake_om2_param_slots.om`). `fn main to int` takes no parameters and its `ret` value is the exit
74 status (0..255).
75- **Assignment is `name = value`.** The first assignment creates the name with the value's type. The
76 `=` is optional, which is a trap: `return x` is accepted as "assign x to a new name `return`".
77- A function may call a function defined later in the unit, and program-mode functions may recurse.
78- Top-level lines are `note`, `fn`, `text`, `global`, `const`, `struct`, and in OM-2 units
79 `layout`, `abstract`, `holds` and `export fn`. `struct` and `layout` lines come before the first
80 `fn` (error 9 after it). A `const` is visible only after its line.
81
82Every declaration and statement form at the pin (OMEGESE sections 9 to 12 are the full rules):
83
84| Form | Where | Notes |
85|---|---|---|
86| `note ANY TEXT` | any line | a comment line |
87| `om2`, `om2 debug`, `om2 release`, `om2 diag`, `om2 diag debug`, `om2 diag release` | first line that is not blank or `note` | opts the unit into OM-2 (section 9); `release` erases contract checks, `diag` adds a machine-readable stderr record |
88| `om2 fmt` | the first line, at byte 0 | prints the canonical text of the rest of the input instead of compiling it |
89| `text NAME "bytes"` | top level | a read-only `uchar` array |
90| `global NAME T N` | top level, program mode | zero-filled array, never an argument |
91| `const NAME T LITERAL` | top level | an integer or float value, visible after its line |
92| `struct S f1 T1 f2 T2 ... end` | top level, before the first `fn` | one line; a field `f T N` is an array of 1..64 |
93| `layout NAME SIZE`, `field F T [COUNT] at OFF little`/`big` lines, `end` | OM-2, top level, before the first `fn` | an external byte layout of SIZE 1..4096 bytes |
94| `abstract NAME T [ops W ...]`, `holds NAME dup32` | OM-2, top level, before the first `fn` | T `uint` or `ulong`; W from `rotr rotl and or xor` |
95| `fn NAME p1 T1 ... to R` ... `end` | top level | `inline` after R in OM-2; `export fn` marks an OM-2 function-mode entry |
96| parameter `p T` | `fn` line | a scalar |
97| parameter `a view T N` / `a edit T N` | `fn` line | a sized array, read-only or writable |
98| parameter `a view T *` / `a edit T *` | `fn` line, OM-2 | an array of any length |
99| parameter `s edit T N fresh` | `fn` line, OM-2 | scratch: every element written before it is read |
100| parameter `p view S` / `p edit S` | `fn` line | a struct, or an OM-2 layout |
101| parameter `o out T N` | `fn` line, OM-2 | written by the unit; the calling host copies it out after status 0 |
102| `name = value` | function body | the first assignment creates the name |
103| `put A i v`, `put p f v` | function body | store into an array element or a field |
104| `f v1 v2 ...` | function body | a call to a `void` function |
105| `if C` ... `else` ... `end` | function body | `else` is optional; no `else if` |
106| `while C bound N` ... `end` | function body | N 1..9223372036854775807 (IR mode 1..1000000) |
107| `for i T K` ... `end` | function body | `unroll` after K in OM-2, K 1..64 |
108| `break`, `continue` | inside a loop | |
109| `ret`, `ret v` | function body | `ret v` in a function with a result |
110| `exit N`, `trap N` | function body | exit status N; trap N 1..14 exits 100+N |
111| `requires C`, `ensures C` | OM-2, the first lines of a function | `result` names the returned value |
112| `invariant C` | OM-2, the first line of a loop body | |
113
114## 3. Types and values
115
116| Type | Meaning |
117|---|---|
118| `bool` | `true` / `false`, the result of comparisons |
119| `uchar`, `ushort`, `uint`, `ulong` | unsigned 8, 16, 32, 64 bit (also spelled `u8 u16 u32 u64`) |
120| `byte`, `short`, `int`, `long` | signed 8, 16, 32, 64 bit (also spelled `i8 i16 i32 i64`); `byte` is **signed**, and `char` is not a type (error 3) |
121| `f32`, `f64` | IEEE binary32, binary64 |
122| `void` | no result (function result only) |
123
124- **No implicit conversion.** Both values of an operation have one type (error 7). Convert with the
125 type word: `long x`, `uint b`, `f64 n`.
126- **A bare number takes its type from context**: the other value of its operation, the parameter it
127 is passed to, the result type at `ret`. With no context it is error 11: write `x = uint 5`, never
128 `x = 5` for a new name.
129- Integer literals are decimal with an optional leading `-`. A literal that does not fit its type
130 is error 8. No character literals: write `uchar 65`, not `'A'` (error 3).
131- Float literals need digits on both sides of the dot: `2.0f64`, `1.0e30f64`, `0.5f32`. The suffix is
132 optional where context gives the type.
133- **Hex only in OM-2** (section 9): lowercase `0x` and lowercase digits, value must fit
134 (`int 0xffffffff` is error 8; write `int -1`).
135- `sizeof T`, `sizeof S` and `offsetof S f` are compile-time `ulong` constants.
136
137## 4. Words
138
139| Kind | Words |
140|---|---|
141| arithmetic | `add sub mul div rem neg` |
142| bits | `and or xor not shl shr` (`rotr rotl` in OM-2) |
143| compare (give `bool`) | `eq ne lt le gt ge` |
144| float | `add sub mul div neg`, `fsqrt fabs fmin fmax` |
145| arrays | `new`, `get A i`, `put A i v`, `len A` |
146| structs | `new S v1 v2 ...`, `get p f`, `put p f v` |
147| control | `if` / `else` / `end`, `while COND bound N`, `for i T K`, `break`, `continue`, `ret`, `exit`, `trap N` |
148| conversion | the type words, `bitcast T v` |
149| I/O | `read fd A off n`, `write fd A off n`, `pread` / `pwrite fd A off n pos`, and the 67 host words of section 10 |
150
151- `and`, `or`, `xor` on integers of any width are bitwise, not logical: `and ulong 12 ulong 10` is 8
152 ([`examples/int_bits_and.om`](../../examples/int_bits_and.om)). Compare first when you want a bool.
153- `and` / `or` on bools evaluate **both** sides; there is no short circuit
154 ([`examples/mistake_short_circuit.om`](../../examples/mistake_short_circuit.om) traps 3 on the
155 index the C reader would expect to be skipped). Test the index in an outer `if`.
156- Comparisons follow the type: on `ulong`, `lt x y` with x = 2^64-1 and y = 1 is false.
157- `div` and `rem` on signed values round toward zero; `rem` takes the dividend's sign;
158 `shr` on a signed value keeps the sign.
159- A function with a result is a value, not a statement: write `v = f 1`, never a bare `f 1`
160 (error 7). A `void` function is called as a statement.
161- A call is the name then its values with no brackets or commas: `ret f 1 2`.
162
163## 5. Traps: what stops a running program
164
165A trap ends the process with exit status 100 + N. Output already written stays written.
166
167| Cause | Trap | Exit | Example |
168|---|---|---|---|
169| signed overflow in `add sub mul neg` | 1 | 101 | `examples/trap1_overflow.om` |
170| `div` or `rem` by zero, and signed minimum divided by -1 | 2 | 102 | `trap2_divzero.om` |
171| array index or I/O slice out of bounds | 3 | 103 | `trap3_bounds.om` |
172| a loop past its bound | 4 | 104 | `trap4_loop.om` |
173| an integer conversion whose value does not fit | 5 | 105 | `trap5_conv.om` |
174| stack exhausted (8 MiB) by calls or local arrays | 6 | 106 | `trap6_stack.om` |
175| shift or rotate amount outside 0..width-1 | 7 | 107 | `trap7_shift.om` |
176| a contract check that fails (OM-2) | 9, 10 | 109, 110 | `contract_requires.om`, `contract_ensures.om` |
177| `trap N`, N 1..14 | N | 100+N | `trap_code.om` (`trap 14`, exit 114) |
178
179- Unsigned arithmetic wraps modulo 2^width and never traps
180 ([`examples/unsigned_wrap.om`](../../examples/unsigned_wrap.om)).
181- Integer conversions are checked: `uchar x` with x = 300 traps 5. Keep the low bits on purpose with
182 a mask: `uchar and x 255`.
183- Float to integer truncates toward zero and saturates at the type's limits; NaN gives 0; it never
184 traps ([`examples/float_to_int.om`](../../examples/float_to_int.om)). No float operation traps:
185 1/0 is infinity, 0/0 is NaN, and NaN compares false except with `ne`.
186- `exit N` ends the process with status N directly, without the trap convention.
187
188## 6. Loops and bounds
189
190- `while COND bound N` runs the body at most N times, N 1..9223372036854775807 (error 8 outside;
191 IR mode 1..1000000). Without `bound` the limit is 1000000. One more pass traps 4. Choose N from
192 an argument you can write down in a `note`, for example "every pass consumes at least one byte of
193 a 65536-byte input".
194- `for i T K` runs i from 0 to K-1. A number K is unguarded. Any other K (a name or value) with no
195 `bound` traps 4 (exit 104) after 1000000 passes, as a `while` with no bound. `for i T K bound N`
196 takes the same N as `while`, caps every count and traps 4 when K exceeds N (`for_bound.om`,
197 `trap4_for_bound.om`). The MCP pin (`f4df8239`, omc `3ad9f10f…`, since omega-mcp #6) accepts
198 `for ... bound`; the previous MCP pin `e5b32567` (omc `2c824805…`) refused it with error 5.
199- `break` and `continue` work in both loops. There is no `else if`: nest an `if` inside `else`.
200- No loop runs forever and recursion is bounded by the stack.
201
202## 7. Arrays, texts, globals, structs
203
204- **Local array:** `a = new T N v`, N elements each v, only in a function's outermost block (error 9
205 inside a block). N is a literal or an integer `const`; a variable N is error 16. There is no heap
206 and no `free` (error 9).
207- **Global array:** `global NAME T N` at top level, zero-filled, program mode only. **A global is
208 never an argument** (error 19); a function uses it by naming it.
209- **Text:** `text NAME "bytes"` is a read-only `uchar` array. Escapes are only `\n \t \\ \"`
210 (error 22 for others).
211- **Array parameters** state type and exact length: `a view uchar 64` (read-only) or
212 `a edit uchar 64` (writable). Another length is error 7. In OM-2, `a view T *` / `a edit T *` take
213 any length. Writing to a view or text is error 20.
214- `get A i` / `put A i v`: a literal index outside the array is error 21; every other index is checked
215 at run time (trap 3). There are no pointers and no address arithmetic.
216- **Structs:** `struct Pair a uint b long end`, before the first `fn`. Every field is an 8-byte cell,
217 so a struct is never a wire or file layout. `p = new Pair 5 -12`, pass as `p edit Pair` or
218 `p view Pair` ([`examples/structs.om`](../../examples/structs.om)).
219- **Bytes on the wire:** build them with shifts and masks into a `uchar` array
220 ([`examples/wire_le.om`](../../examples/wire_le.om)); OM-2 also has `layout`.
221
222## 8. Names and limits
223
224- Variable, parameter, global, text, const, struct and field names: at most 8 characters (error 13).
225 Function names: at most 63, but see section 13 for names that start with an 8-letter keyword.
226- A new name may not repeat a visible name, a function or a struct (error 10). A name first assigned
227 inside a block ends at that block's `end`; assign it before the block to keep it.
228- Reserved words cannot be names, including `len read write text new free view edit global note
229 exit const bound` and every host word (`stat`, `link`, `send`, `random`, `fork`, ...). `len` as a
230 name is error 16, `free` is error 9.
231- 16 registers per function hold parameters, live names, loop counters and the temporaries of the
232 current statement. The 17th is error 12 (`examples/err12_registers.om`). The fix is structural:
233 move part of the work into a helper function that takes a few scalars and returns one value, end
234 the life of names you no longer need by computing them inside a block, and split a long nested
235 expression into several assignments of one or two words each.
236- Size limits: an array up to 16777216 elements, 4 MiB of local arrays per function, 1 GiB of
237 globals (error 23).
238
239## 9. OM-2 units
240
241A unit whose first line that is not blank or `note` is exactly `om2` is an OM-2 unit. OM-1 code keeps
242its meaning inside it. OM-2 adds:
243
244- lowercase hex literals; `rotr x n`, `rotl x n` on unsigned types (trap 7 for an amount outside
245 0..width-1);
246- unsized parameters `a view T *` / `a edit T *` with `len a` the run-time count;
247- `part A off n`, only as an argument to an unsized parameter: the n elements of A from off,
248 checked at run time (trap 3). A part of a global is error 19; as a value of its own it is error 9;
249 to a sized parameter it is error 7;
250- `for i T K unroll`, `fn ... inline`, `layout` (external byte layouts), `fresh` scratch arrays
251 (error 27), `abstract` types with `seal` / `open` (error 28), `export fn` (at most 32, error 14);
252- executable contracts: `requires` and `ensures` lines at the start of a function, `invariant` as the
253 first line of a loop body. A failing `requires` traps 9 (exit 109), a failing `ensures` or
254 `invariant` traps 10 (exit 110). A clause may not call a function, use floats or host words
255 (error 30). The first line `om2 release` erases the checks
256 ([`examples/contract_release.om`](../../examples/contract_release.om)).
257
258Examples: [`om2_tour.om`](../../examples/om2_tour.om), [`om2_views.om`](../../examples/om2_views.om),
259[`om2_hex_rotr.om`](../../examples/om2_hex_rotr.om), [`contracts_ok.om`](../../examples/contracts_ok.om).
260
261## 10. Host I/O
262
263- Every host word returns a `long`: a count, or minus the Linux errno. `read` may return fewer bytes
264 than asked, 0 at end of input, or a negative error; `write` may write fewer. Loop until done and
265 handle `k < 0` and `k == 0` separately
266 ([`examples/stdin_count.om`](../../examples/stdin_count.om)).
267- Descriptors, flags and modes are `int`; offsets, counts and capacities `ulong`; buffers `uchar`
268 arrays. Slices are checked before the kernel call (trap 3).
269- `main` takes no parameters: read arguments with `argcnt` and `argread`
270 ([`examples/echo_args.om`](../../examples/echo_args.om)) and the environment with `envcnt` and
271 `envread` ([`examples/env_read.om`](../../examples/env_read.om)). Short capacity returns -105.
272- Host words carry the process's own permissions; they are not a sandbox.
273
274The 67 host words at the pin, with their values (OMEGESE section 10 has each one's exact contract).
275`A` and `B` are `uchar` arrays, `off`, `n` and `capacity` are `ulong`, and descriptors, flags, modes
276and ids are `int`. A path is the slice `A off n`; a packed list is a `u16` count, then `u16`-length
277records. Each word is reserved: using it as a name is error 16 at the pin, while an unreserved name
278in the same program compiles.
279
280| Area | Words |
281|---|---|
282| files | `fopen A off n flags mode`, `fclose fd`, `fsync fd`, `fdsync fd`, `syncfs fd`, `memfd A off n flags`, `fseek fd offset whence`, `ftrunc fd length`, `flock fd op`, `fstat fd A off n`, `getdnts fd A off n` |
283| paths | `chmod A off n mode`, `fchmod fd mode`, `chown A off n uid gid`, `faccess A off n mode`, `truncate A off n length`, `unlink A off n`, `makedir A off n mode`, `rmdir A off n`, `cwd A off capacity`, `chdir A off n`, `fchdir fd`, `readlnk A off n B off capacity`, `stat A off n B off capacity`, `lstat A off n B off capacity`, `renames A off n flags`, `link A off n`, `symlnk A off n`, `umask mask` |
284| processes | `getpid`, `getppid`, `getuid`, `geteuid`, `getgid`, `getegid`, `setsid`, `getpgid pid`, `getsid pid`, `setpgid pid pgid`, `fork`, `killpid pid signal`, `waitpid pid A off n options`, `pipefds A off n flags`, `dupfd fd target flags`, `execprog A off n` |
285| arguments, environment, randomness | `argcnt`, `argread index A off capacity`, `envcnt`, `envread index A off capacity`, `random A off n flags` |
286| time | `monons`, `realns`, `sleepns interval` |
287| sockets | `socknew domain kind protocol`, `bind fd A off n`, `connect fd A off n`, `listen fd backlog`, `accept fd flags`, `sockname fd A off n`, `sockopt fd level option A off n`, `recv fd A off n flags`, `send fd A off n flags`, `sendmsg fd A off n flags`, `shutdown fd how`, `waitio fd events interval`, `pollfds A off n interval`, `peercred fd A off capacity` |
288
289## 11. Compiler errors
290
291Exit status = error number. The only message is the one stderr line `omc: line N: error K`, where N
292is the line being read (0 when no line was read). One refusal per code is in `examples/errNN_*.om`
293with its exact stderr line in the matching `.expect`, except 24, which needs a generated program.
294
295| Code | Meaning | Example | Fix |
296|---|---|---|---|
297| 1 | omc could not read its input | `err01_input` (stdin is a directory) | give omc a readable file on stdin |
298| 2 | omc could not write its output | `err02_output` (stdout is `/dev/full`) | send stdout to a writable file with space |
299| 3 | unknown name, field or function | `err03_unknown_name` | assign the name before use; check the spelling |
300| 4 | the line ends before the statement is complete | `err04_line_ends` | give every word all of its values |
301| 5 | words left after a complete statement | `err05_extra_words` | count each word's values; there is no infix |
302| 6 | malformed number | `err06_bad_number` | decimal digits; hex only in OM-2, lowercase |
303| 7 | type mismatch | `err07_type_mismatch` | convert with a type word: `add int 1 int u` |
304| 8 | number out of range | `err08_out_of_range` | a literal that fits its type; a bound 1..9223372036854775807 (IR mode 1..1000000); a trap code 1..14 |
305| 9 | a word in a place where it is not allowed | `err09_disallowed` | move it: `new` only in a function's outermost block, `struct` before the first `fn` |
306| 10 | duplicate name | `err10_duplicate` | choose a name that is not visible, not a function, not a struct |
307| 11 | a number with nothing to give it a type | `err11_ambiguous` | `x = uint 5` |
308| 12 | register pool exhausted (16 per function) | `err12_registers` | fewer live names, a helper function, shorter expressions (section 8) |
309| 13 | name too long | `err13_long_name` | at most 8 characters (function names 63) |
310| 14 | compiler capacity: names, functions, exports, expansion | `err14_capacity` | split the function or the unit |
311| 15 | the input ends inside an open block | `err15_missing_end` | close every block with `end` |
312| 16 | syntax: unknown word or misplaced form | `err16_syntax` | start each line with a statement word; comments are `note` lines |
313| 17 | a line after `ret`, `break`, `continue`, `trap` or `exit` in the same block | `err17_after_path` | delete the line or move it above |
314| 18 | a function with a result whose `end` is reachable | `err18_missing_ret` | end every path with `ret v` |
315| 19 | a global as an argument, or one array twice in a call | `err19_global_arg` | name the global inside the function; pass distinct arrays |
316| 20 | writing to a text or a view | `err20_readonly` | an `edit` parameter, or a local copy |
317| 21 | a literal index outside the array | `err21_const_index` | an index 0..N-1 |
318| 22 | a text escape other than `\n \t \\ \"` | `err22_text_escape` | build other bytes with `put` |
319| 23 | array or pool size limit | `err23_size` | smaller arrays (section 8 limits) |
320| 24 | a conditional branch farther than 1 MiB of code | generated, below | move long bodies into functions |
321| 25 | unknown `target` name, an AArch64-only path on another target, or (with omega-mv#1015) an x86efi refusal | `err25_target` | omit `target` for AArch64, or name a target the unit fits (`target x86linux` and `target x86efi` with `fn main` compile). omega-mv#1015 (head `19ee7e99`, merged as `d3d1b1bc`, the pin, omc `b4f45121…`) adds the x86efi backend; its error 25 is a bare unit (no `fn main`), a Linux host word, or an `efi` OP literal outside 0..13 (0..14 with omega-mv#1022, open); a non-literal OP is error 16 and `efi` under `target x86linux` is error 3. See `omega-encoding` |
322| 26 | never emitted at the pin | none | none |
323| 27 | OM-2 `fresh` element read before it is written | `err27_fresh` | `put` every element before the `get` |
324| 28 | OM-2 `seal` outside the constructor | `err28_seal` | `seal` only as the whole body of `fn NAMEmk ... to NAME` |
325| 29 | OM-2 `layout` field past the size or overlapping | `err29_layout` | keep every field inside SIZE and apart |
326| 30 | OM-2 contract clause not allowed | `err30_contract` | integer words on parameters only (and `result` in `ensures`); no calls, floats or host words |
327
328How the emitted set was established at the pin: in `seed/omc/omc.om`, `fn fail` (line 324) writes
329the stderr line and exits with the code (`exit int code`, line 356). The only other exits are
330`exit int 0` and `exit 0`, so every refusal goes through `fail`. Its callers pass the literals 1..25
331and 27..30, or forward a literal 3, 4, 6, 8, 13 or 16 through `lenval`, `nfail` and `unkfail`. No
332caller passes 26, so that code is never emitted (the registry `seed/omc/error-codes.reg` lists it as
333"no emitting site"). Code 25 comes from the target checks (`fail 25` in `fn emit` and six other
334sites). A trap inside omc itself would exit
335100 + N, which is not an error code.
336
337Error 24 needs more than 1 MiB of code inside one loop. This program, with 270000 copies of the
338line `x = add x 1` (4 bytes of code each), was refused with `omc: line 270006: error 24`, the line
339of the loop's `end`; with 140000 copies it compiled:
340
341```sh
342{ printf 'fn main to int\nx = ulong 0\nc = true\nwhile c bound 1\n'
343 yes 'x = add x 1' | head -n 270000
344 printf 'c = false\nend\nret int and x 1\nend\n'; } > e24.om
345seed/out/omc < e24.om > e24; echo "compile $?" # compile 24
346```
347
348## 12. Common mistakes
349
350Each row is a program in `examples/` with its observed refusal.
351
352| Mistake | Write instead | Refusal | Example |
353|---|---|---|---|
354| `y = x + 1` | `y = add x 1` | error 5 | `mistake_infix.om` |
355| `f(1, 2)` | `f 1 2` | error 6 | `mistake_c_call.om` |
356| `if x > 0` | `if gt x 0` | error 7 | `mistake_compare_operator.om` |
357| `'A'` | `uchar 65` | error 3 | `mistake_char_literal.om` |
358| `// comment` | `note comment` | error 16 | `mistake_slash_comment.om` |
359| `x = 1;` | `x = uint 1` | error 6 | `mistake_semicolon.om` |
360| `return x` | `ret x` | error 18 (silent assignment) | `mistake_return.om` |
361| `else if c` | `else`, then a nested `if c` | error 5 | `mistake_else_if.om` |
362| `fn main argc int to int` | `argcnt`, `argread` | error 9 | `mistake_main_args.om` |
363| `while c bound 9223372036854775808` (or `bound 0`) | a bound 1..9223372036854775807 | error 8 | `mistake_bound_range.om` |
364| `ir` unit with `while c bound 1000001` | an IR bound 1..1000000 | error 8 | `mistake_ir_bound.om` |
365| `a = new uchar n 0` | a literal or `const` length | error 16 | `mistake_new_var_len.om` |
366| `free a` | nothing: no heap | error 9 | `mistake_free.om` |
367| `len = ...` | another name | error 16 | `mistake_reserved_name.om` |
368| `neg = ...` or `text neg "a"` | another name: `neg` is the negation word | error 16 | `mistake_neg_name.om` |
369| a bare call `f 1` with a result | `v = f 1` | error 7 | `mistake_value_stmt.om` |
370| a 7th parameter | a struct or an array | error 9 | `mistake_seven_params.om` |
371| 2 `view T *` plus 3 scalars (7 slots) | a sized view, a struct, or fewer scalars | error 9 | `mistake_om2_param_slots.om` |
372| `emit buf` with `buf` a global | name the global inside the function | error 19 | `err19_global_arg.om` |
373| `a view uchar 8` given a 16-element array | the exact length, or OM-2 `view uchar *` | error 7 | `mistake_param_length.om` |
374| `trap 15` | `trap 1` .. `trap 14` | error 8 | `mistake_trap_range.om` |
375| `struct` after a `fn` | every `struct` before the first `fn` | error 9 | `mistake_struct_after_fn.om` |
376| `rotr` or hex without `om2` | an `om2` first line | error 3 | `mistake_om1_rotr.om` |
377| `0X10` or `0xFF` | `0x10`, `0xff` | error 6 | `mistake_om2_upper_hex.om` |
378| `int 0xffffffff` | `int -1` | error 8 | `mistake_om2_int_hex.om` |
379| `part` of a global | `part` of a local | error 19 | `mistake_om2_part_global.om` |
380| `part` to a sized parameter | an unsized `view T *` parameter | error 7 | `mistake_om2_part_sized.om` |
381| `s = part a 0 2` | `part` only as an argument | error 9 | `mistake_om2_part_statement.om` |
382| `if and lt i n eq get a i 0` (C short circuit) | an outer `if lt i n` | trap 3, exit 103 | `mistake_short_circuit.om` |
383
384## 13. Known compiler defects at the pin
385
386- **`bitcast` across signedness below 64 bits:** at this pin, `uint 4294967295` to `int` compares
387 equal to -1 and adding 2 returns 1, and `int -1` to `uint` compares equal to 4294967295. Those
388 two cases were wrong at omc `2c824805` (not equal; adding 2 trapped 1). `ushort`/`short`,
389 `uchar`/`byte` and `f32` to `int` were not retested on 2026-10-29. Do not assume they are fixed.
390 Decode signed values arithmetically when you have not measured the pair
391 ([`examples/wire_le.om`](../../examples/wire_le.om)).
392- **Empty text through `view uchar *`** (omega-mv issue #775): reproduced on 2026-11-04 with omc
393 `2c824805`: `om2`, `text e ""`, `fn n a view uchar * to ulong` / `ret len a`, `ret int n e` exits
394 28 (60 with one more 32-byte text). Pass `part e 0 0`
395 ([`examples/empty_text_part.om`](../../examples/empty_text_part.om)).
396- **`and`/`or` are eager:** `if and gt n 0 eq get a sub n 1 13` traps 3 when `n` is 0. Guard an
397 index with a nested `if`.
398- **Function names:** a name of 9..63 bytes is not a keyword by its first 8 bytes. `continue_x`
399 compiles and returns 7 ([`examples/defect_keyword_prefix.om`](../../examples/defect_keyword_prefix.om)).
400 An exact keyword (`fn continue`) is still error 16. At omc `2c824805`, `continue_x` was error 16.
401- OMEGESE 9.9 lists `+ - * /` for floats; the compiler refuses them. Write `add sub mul div`.
402
403## 14. Example index
404
405All in [`examples/`](../../examples/); each `NAME.om` has `NAME.expect` (compile status, exit status
406or stderr line) and, when it prints, `NAME.stdout` with the exact bytes. Wolfram checks of the
407arithmetic expectations are in [`examples/WOLFRAM.md`](../../examples/WOLFRAM.md).
408
409- Start here: `hello`, `exit_status`, `print_decimal`, `functions`, `loops`, `arrays`, `text`.
410- Arithmetic: `int_arith`, `int_bits_and`, `unsigned_wrap`, `checked_conv`, `float_arith`,
411 `float_to_int`, `consts`.
412- Data: `globals`, `structs`, `wire_le`.
413- I/O: `stdin_count`, `echo_args`, `env_read`, `tmp_files`.
414- Traps: `trap1_overflow` .. `trap7_shift`, `trap_code`.
415- OM-2 and contracts: `om2_tour`, `om2_views`, `om2_hex_rotr`, `om2_part_trap`, `om2_param_slots`,
416 `contracts_ok`, `contract_requires`, `contract_ensures`, `contract_invariant`, `contract_release`.
417- Regression guards: `empty_text_part`, `defect_keyword_prefix`.
418- Refusals: `err01_input` .. `err30_contract`, `mistake_*`.