diff --git a/AGENTS.md b/AGENTS.md index b7bb020..2c1c61c 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -8,19 +8,24 @@ Agent skills for working in Omega and the AIEN repositories: the checks that cat repeat, written as guidance an agent loads before acting. It is documentation and procedure, not a compiler, a runtime, a gate, or evidence that any claim is true. -Six skills live under `skills//SKILL.md` in the Agent Skills layout (frontmatter `name` and +Seven skills live under `skills//SKILL.md` in the Agent Skills layout (frontmatter `name` and `description`, then the body): | Path | Covers | |---|---| | `skills/omega-harness/SKILL.md` | The workflow: orient, implement in `.om`, compile, run, challenge, effects, repeated errors, guide upkeep | +| `skills/writing-omega/SKILL.md` | Portable guide for writing a correct `.om` program on any machine: shape, types, words, traps, errors 1..30, common mistakes with their refusals, known pin defects | | `skills/omega-encoding/SKILL.md` | The language the seeded compiler accepts at a pinned commit: words, types, traps, bounds, registers, host I/O, byte layouts, error codes | | `skills/omega-communication/SKILL.md` | Claim ladder, report shape, agent handoffs, semantic and wire data, corrections | | `skills/aien-repositories/SKILL.md` | Mission, plan authority, task to repository routing, status discipline, known source drift | | `skills/crumb-protocol/SKILL.md` | Directory coordination: crumbs, locks, committed-crumb freshness, `CRUMB-VERIFY` and `crumb-doctor` | | `skills/wolfram-math/SKILL.md` | Mandatory Wolfram for every computation, its MCP setup, verification calls and failure handling | -`skills/omega-encoding/examples/` holds two runnable `.om` programs. `LICENSE` is Apache 2.0. +`examples/` holds the tested programs: each `NAME.om` with `NAME.expect` (and `NAME.stdout` when it +prints), one per trap and error code plus the common mistakes. `examples/gate.sh OMC` checks the +pinned compiler hash and reruns every program in `examples/` and `skills/*/examples/`; run it after +any change to an example or a language rule. `skills/omega-encoding/examples/` holds two more +runnable programs. `LICENSE` is Apache 2.0. ## Before you edit a skill diff --git a/README.md b/README.md index efc7c5d..f7b044a 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,7 @@ Skills can't make agents flawless. What these do is turn the mistakes agents kee | Skill | Use it for | |---|---| | [`omega-harness`](skills/omega-harness/SKILL.md) | The overall workflow: orient, implement in `.om`, compile, run, challenge, handle effects, learn from repeated errors | +| [`writing-omega`](skills/writing-omega/SKILL.md) | A portable guide for writing a correct `.om` program on any machine: shape, types, words, traps, errors 1..30, common mistakes with their exact refusals, known compiler defects and workarounds | | [`omega-encoding`](skills/omega-encoding/SKILL.md) | The language the seeded compiler accepts: prefix words, types, traps, bounds, registers, host I/O, byte layouts, error codes, plus two runnable examples | | [`omega-communication`](skills/omega-communication/SKILL.md) | Status labels, reports, PR text, agent handoffs, receipts, wire formats, corrections | | [`aien-repositories`](skills/aien-repositories/SKILL.md) | What AIEN builds, who decides what, and which repository owns a task | @@ -77,26 +78,23 @@ QUALIFIED or deployed. ## Check the examples yourself -The examples run on Linux AArch64 hosts only: +The examples run on Linux AArch64 hosts only. [`examples/`](examples/) holds 97 programs, each +`NAME.om` with `NAME.expect` (and `NAME.stdout` when it prints): every trap, one refusal per error +code, the common mistakes and the known defects. `examples/gate.sh` refuses any compiler but the +pinned one, then compiles and runs every program here and in `skills/*/examples/`: ```sh git clone https://github.com/aien-dev/omega-mv.git omega-src +git -C omega-src checkout 91c83438daec0bdb88bf5c077cae10f3d15d365d sha256sum omega-src/seed/out/omc # 2aec185d4ed6d7a6a5779ed656b4e56904742bde5551b02893fb5f73916ad8d5 at main 91c83438 (2026-10-31); 734f0a39... at the 2026-10-25 pin 55f9b0af -omega-src/seed/out/omc < skills/omega-encoding/examples/fnv1a32.om > fnv 2> fnv.err -compile_rc=$? -printf 'compile rc=%s\n' "$compile_rc" -cat fnv.err -if [ "$compile_rc" -eq 0 ]; then - chmod +x fnv - printf abc > fnv.in - ./fnv < fnv.in > fnv.out - run_rc=$? - printf 'run rc=%s\n' "$run_rc" - if [ "$run_rc" -eq 0 ]; then od -An -tx1 fnv.out; fi # 0b e9 47 1a -fi +examples/gate.sh omega-src/seed/out/omc ``` -The `omega-encoding` skill (section 13) records the full set of observed results and the negative controls. +It prints `PASS name` or `FAIL name: reason` per program and ends with +`GATE PASS examples=99 pass=99 fail=0 omc=2aec185d...` (exit 0), `GATE FAIL ...` (exit 1), or a hash +refusal (exit 2). The `omega-encoding` skill (section 0 and section 13) records the observed results +and the negative controls; [`examples/WOLFRAM.md`](examples/WOLFRAM.md) records the Wolfram checks of +the arithmetic expectations. ## Keeping it current diff --git a/examples/WOLFRAM.md b/examples/WOLFRAM.md new file mode 100644 index 0000000..ed9b378 --- /dev/null +++ b/examples/WOLFRAM.md @@ -0,0 +1,70 @@ +# Wolfram checks for the example expectations + +Every arithmetic value in an `examples/*.stdout` file and the FNV-1a bytes of +`skills/omega-encoding/examples/fnv1a32.stdout` were checked with one WolframLanguageEvaluator call +on 2026-10-27. The `.stdout` files hold what the pinned compiler's programs printed +(omega-mv `e5b32567`, omc sha256 `2c824805…029f`); this call is the independent check that those +outputs are the right numbers. Byte counts, exit statuses and the `before` lines are bookkeeping and +are not listed. +The same stdout bytes were printed again on 2026-10-29 by omc `62775d2a…712b` (omega-mv `bf54b19f`); the gate compared them. Wolfram was not rerun that day. + +Query (verbatim): + +```wolfram +toBits[x_] := FromDigits[Flatten[{RealDigits[x, 2, 1, 0]}], 2]; u64[x_?NumericQ] := Module[{b = ExportString[{x}, "Real64", ByteOrdering -> -1]}, FromDigits[Reverse[ToCharacterCode[b]], 256]]; +<| +"print_decimal" -> {2^64 - 1, 2^63 - 1, -2^63}, +"int_arith" -> {Quotient[-7, 2] + If[Mod[-7, 2] != 0 && -7 < 0, 1, 0], -7 - 2*IntegerPart[-7/2], IntegerPart[7/-2], 7 - (-2)*IntegerPart[7/-2], 123456789*987654321, Floor[-16/2^2], 0 - (-7)}, +"unsigned_wrap" -> {Mod[2^32 - 1 + 1, 2^32], Mod[0 - 1, 2^32], Mod[65536*65536, 2^32], Mod[-1, 2^32], BitNot[0] + 2^32, 2^31, Mod[2^64 - 1 + 1, 2^64]}, +"exit_status" -> Mod[300, 256], +"float_arith" -> {IntegerPart[Sqrt[2.`30]*10^9], u64[0.1 + 0.2], u64[1.0], IntegerPart[-2.5], IntegerPart[Abs[-7.9]]}, +"float_to_int" -> {2^63 - 1, -2^63, IntegerPart[-5.75]}, +"checked_conv" -> {BitAnd[300, 255], 2^31 - 1, 2^16 - 1}, +"arrays" -> {Sum[k^2, {k, 1, 8}], 8^2}, +"globals" -> {DigitCount[1234567890, 10, 9] + DigitCount[9999, 10, 9], DigitCount[1234567890, 10, 0] + 1, DigitCount[1234567890, 10, 5]}, +"loops" -> {Length[NestWhileList[If[EvenQ[#], #/2, 3 # + 1] &, 27, # != 1 &]] - 1, Total[Select[Range[0, 50], Mod[#, 3] != 0 &]]}, +"functions" -> {20!, GCD[1071, 462], 1 + 6 + 2*(5 - 4)}, +"text" -> {StringLength["tab\there \"q\" back\\slash\n"], ToCharacterCode["t"]}, +"structs" -> {5 + (-12), 8*2}, +"stdin_count" -> {StringLength["alpha\nbeta\ngamma delta\n\nend"], StringCount["alpha\nbeta\ngamma delta\n\nend", "\n"], Total[ToCharacterCode["alpha\nbeta\ngamma delta\n\nend"]]}, +"wire_le" -> {IntegerDigits[16^^12345678, 256], FromDigits[Reverse[{120, 86, 52, 255}], 256] - 2^32}, +"om2_hex_rotr" -> {16^^deadbeef, BitOr[BitShiftRight[16^^deadbeef, 8], BitAnd[BitShiftLeft[16^^deadbeef, 24], 2^32 - 1]], 2^64 - 1, BitAnd[16^^deadbeef, 255]}, +"om2_views" -> {Total[Range[6]], 2 + 3 + 4, 6}, +"om2_tour" -> {7*3, 7*2^32 + 7 == 16^^0000000700000007}, +"contract_release" -> Quotient[7, 2], +"tmp_files" -> {BitOr[1, 64, 128], FromDigits["600", 8], FromDigits["700", 8], StringLength["omega\n"]}, +"env_read" -> {StringLength["LONG=" <> StringRepeat["v", 70]]}, +"echo_args" -> {1 + 4, StringLength[StringRepeat["x", 40]]}, +"trap_bounds" -> {2^31 - 1 + 1 > 2^31 - 1, 2^63 - 1}, +"fnv1a32_abc" -> IntegerDigits[Fold[Mod[BitXor[#1, #2]*16777619, 2^32] &, 2166136261, ToCharacterCode["abc"]], 256, 4] // Reverse +|> +``` + +Result (verbatim): + +``` +<|"print_decimal" -> {18446744073709551615, 9223372036854775807, -9223372036854775808}, "int_arith" -> {-3, -1, -3, 1, 121932631112635269, -4, 7}, "unsigned_wrap" -> {0, 4294967295, 0, 4294967295, 4294967295, 2147483648, 0}, "exit_status" -> 44, "float_arith" -> {1414213562, 4599075939470750516, 4607182418800017408, -2, 7}, "float_to_int" -> {9223372036854775807, -9223372036854775808, -5}, "checked_conv" -> {44, 2147483647, 65535}, "arrays" -> {204, 64}, "globals" -> {5, 2, 1}, "loops" -> {111, 867}, "functions" -> {2432902008176640000, 21, 9}, "text" -> {24, {116}}, "structs" -> {-7, 16}, "stdin_count" -> {27, 4, 2350}, "wire_le" -> {{18, 52, 86, 120}, -13347208}, "om2_hex_rotr" -> {3735928559, 4024348094, 18446744073709551615, 239}, "om2_views" -> {21, 9, 6}, "om2_tour" -> {21, True}, "contract_release" -> 3, "tmp_files" -> {193, 384, 448, 6}, "env_read" -> {75}, "echo_args" -> {5, 40}, "trap_bounds" -> {True, 9223372036854775807}, {26, 71, 233, 11} -> "fnv1a32_abc"|> +``` + +Reading notes: + +- `int_arith`: Omega `div` and `rem` truncate toward zero, so the program prints `-3 -1 -3 1` for + `-7/2`, `-7 rem 2`, `7/-2`, `7 rem -2`; `shr long -16 2` is an arithmetic shift, `-4`. +- `float_arith`: `IntegerPart` matches Omega's float-to-integer truncation toward zero. +- `wire_le`: Wolfram lists the bytes of `0x12345678` most significant first (`18 52 86 120`); the + program stores them least significant first and prints `120 86 52 18`. +- `fnv1a32_abc`: the trailing `// Reverse` applied to the rule, so the result shows as + `{26, 71, 233, 11} -> "fnv1a32_abc"`: hash `0x1a47e90b`, written little-endian as the bytes + `0b e9 47 1a` in `fnv1a32.stdout`. +- `env_read`: the `LONG=` entry is 75 bytes, over the 63-byte capacity, so `envread` returns -105 and + the program prints an empty line for it. + +Second call, for `int_bits_and` (exit status 8 is the value checked), query and result verbatim: + +```wolfram +BitAnd[12, 10] +``` + +``` +8 +``` diff --git a/examples/arrays.expect b/examples/arrays.expect new file mode 100644 index 0000000..420e65e --- /dev/null +++ b/examples/arrays.expect @@ -0,0 +1,2 @@ +compile 0 +exit 0 diff --git a/examples/arrays.om b/examples/arrays.om new file mode 100644 index 0000000..17106d3 --- /dev/null +++ b/examples/arrays.om @@ -0,0 +1,55 @@ +note arrays: a local array is new T N v in the outermost block; N is a literal or an integer const +note ---- output helpers: a function works on a global by naming it (a global is never an argument) +global ob uchar 32 +note outb: write ob[off .. off+n) to stdout; a short write continues, 0 or an error exits 90 +note bound: every pass writes at least one byte and n <= 32, so at most 32 passes +fn outb off ulong n ulong to void +e = add off n +p = off +while lt p e bound 32 +k = write 1 ob p sub e p +if le k 0 +exit 90 +end +p = add p ulong k +end +end +note putu: v in decimal, then a newline. A ulong has at most 20 digits, so 20 passes +fn putu v ulong to void +i = ulong 31 +put ob 31 10 +n = v +while true bound 20 +i = sub i 1 +put ob i uchar add rem n 10 48 +n = div n 10 +if eq n 0 +break +end +end +outb i sub 32 i +end +note putl: a signed value; -(v+1)+1 avoids negating the minimum, which would trap 1 +fn putl v long to void +if lt v 0 +put ob 0 45 +outb 0 1 +putu add ulong neg add v 1 1 +ret +end +putu ulong v +end +fn main to int +a = new uint 8 0 +for i ulong 8 +put a i uint mul add i 1 add i 1 +end +s = ulong 0 +for i ulong len a +s = add s ulong get a i +end +putu s +putu len a +putu ulong get a 7 +ret 0 +end diff --git a/examples/arrays.stdout b/examples/arrays.stdout new file mode 100644 index 0000000..09fb95c --- /dev/null +++ b/examples/arrays.stdout @@ -0,0 +1,3 @@ +204 +8 +64 diff --git a/examples/checked_conv.expect b/examples/checked_conv.expect new file mode 100644 index 0000000..420e65e --- /dev/null +++ b/examples/checked_conv.expect @@ -0,0 +1,2 @@ +compile 0 +exit 0 diff --git a/examples/checked_conv.om b/examples/checked_conv.om new file mode 100644 index 0000000..2654e6b --- /dev/null +++ b/examples/checked_conv.om @@ -0,0 +1,51 @@ +note checked_conv: integer conversions check the value; mask first to keep low bits +note ---- output helpers: a function works on a global by naming it (a global is never an argument) +global ob uchar 32 +note outb: write ob[off .. off+n) to stdout; a short write continues, 0 or an error exits 90 +note bound: every pass writes at least one byte and n <= 32, so at most 32 passes +fn outb off ulong n ulong to void +e = add off n +p = off +while lt p e bound 32 +k = write 1 ob p sub e p +if le k 0 +exit 90 +end +p = add p ulong k +end +end +note putu: v in decimal, then a newline. A ulong has at most 20 digits, so 20 passes +fn putu v ulong to void +i = ulong 31 +put ob 31 10 +n = v +while true bound 20 +i = sub i 1 +put ob i uchar add rem n 10 48 +n = div n 10 +if eq n 0 +break +end +end +outb i sub 32 i +end +note putl: a signed value; -(v+1)+1 avoids negating the minimum, which would trap 1 +fn putl v long to void +if lt v 0 +put ob 0 45 +outb 0 1 +putu add ulong neg add v 1 1 +ret +end +putu ulong v +end +fn main to int +x = uint 300 +putu ulong uchar and x 255 +y = long 2147483647 +putl long int y +w = int -1 +putl long w +putu ulong ushort 65535 +ret 0 +end diff --git a/examples/checked_conv.stdout b/examples/checked_conv.stdout new file mode 100644 index 0000000..41e85a2 --- /dev/null +++ b/examples/checked_conv.stdout @@ -0,0 +1,4 @@ +44 +2147483647 +-1 +65535 diff --git a/examples/consts.expect b/examples/consts.expect new file mode 100644 index 0000000..420e65e --- /dev/null +++ b/examples/consts.expect @@ -0,0 +1,2 @@ +compile 0 +exit 0 diff --git a/examples/consts.om b/examples/consts.om new file mode 100644 index 0000000..4d1ba60 --- /dev/null +++ b/examples/consts.om @@ -0,0 +1,58 @@ +note consts: a top-level const is visible after its line and may size an array, bound a loop or name a trap +note ---- output helpers: a function works on a global by naming it (a global is never an argument) +global ob uchar 32 +note outb: write ob[off .. off+n) to stdout; a short write continues, 0 or an error exits 90 +note bound: every pass writes at least one byte and n <= 32, so at most 32 passes +fn outb off ulong n ulong to void +e = add off n +p = off +while lt p e bound 32 +k = write 1 ob p sub e p +if le k 0 +exit 90 +end +p = add p ulong k +end +end +note putu: v in decimal, then a newline. A ulong has at most 20 digits, so 20 passes +fn putu v ulong to void +i = ulong 31 +put ob 31 10 +n = v +while true bound 20 +i = sub i 1 +put ob i uchar add rem n 10 48 +n = div n 10 +if eq n 0 +break +end +end +outb i sub 32 i +end +note putl: a signed value; -(v+1)+1 avoids negating the minimum, which would trap 1 +fn putl v long to void +if lt v 0 +put ob 0 45 +outb 0 1 +putu add ulong neg add v 1 1 +ret +end +putu ulong v +end +const N ulong 16 +const PASSES ulong 16 +const BAD ulong 12 +fn main to int +a = new uchar N 1 +s = ulong 0 +i = ulong 0 +while lt i len a bound PASSES +s = add s ulong get a i +i = add i 1 +end +putu s +if ne s N +trap BAD +end +ret 0 +end diff --git a/examples/consts.stdout b/examples/consts.stdout new file mode 100644 index 0000000..b6a7d89 --- /dev/null +++ b/examples/consts.stdout @@ -0,0 +1 @@ +16 diff --git a/examples/contract_ensures.expect b/examples/contract_ensures.expect new file mode 100644 index 0000000..cbabdc3 --- /dev/null +++ b/examples/contract_ensures.expect @@ -0,0 +1,2 @@ +compile 0 +exit 110 diff --git a/examples/contract_ensures.om b/examples/contract_ensures.om new file mode 100644 index 0000000..dcde4ae --- /dev/null +++ b/examples/contract_ensures.om @@ -0,0 +1,13 @@ +note contract_ensures: a false postcondition traps 10, exit 110; the bug here is the + 2 +om2 +text before "before\n" +fn inc x uint to uint +requires lt x 100 +ensures eq result add x 1 +ret add x 2 +end +fn main to int +k = write 1 before 0 len before +h = inc 5 +ret 0 +end diff --git a/examples/contract_ensures.stdout b/examples/contract_ensures.stdout new file mode 100644 index 0000000..90be1f3 --- /dev/null +++ b/examples/contract_ensures.stdout @@ -0,0 +1 @@ +before diff --git a/examples/contract_invariant.expect b/examples/contract_invariant.expect new file mode 100644 index 0000000..cbabdc3 --- /dev/null +++ b/examples/contract_invariant.expect @@ -0,0 +1,2 @@ +compile 0 +exit 110 diff --git a/examples/contract_invariant.om b/examples/contract_invariant.om new file mode 100644 index 0000000..9bf338d --- /dev/null +++ b/examples/contract_invariant.om @@ -0,0 +1,12 @@ +note contract_invariant: a false loop invariant traps 10, exit 110, at the top of the failing pass +om2 +text before "before\n" +fn main to int +k = write 1 before 0 len before +i = uint 0 +while lt i 10 +invariant lt i 5 +i = add i 1 +end +ret 0 +end diff --git a/examples/contract_invariant.stdout b/examples/contract_invariant.stdout new file mode 100644 index 0000000..90be1f3 --- /dev/null +++ b/examples/contract_invariant.stdout @@ -0,0 +1 @@ +before diff --git a/examples/contract_release.expect b/examples/contract_release.expect new file mode 100644 index 0000000..210c9cd --- /dev/null +++ b/examples/contract_release.expect @@ -0,0 +1,2 @@ +compile 0 +exit 3 diff --git a/examples/contract_release.om b/examples/contract_release.om new file mode 100644 index 0000000..9e583c6 --- /dev/null +++ b/examples/contract_release.om @@ -0,0 +1,9 @@ +note contract_release: om2 release erases contracts; the false precondition no longer traps +om2 release +fn half x uint to uint +requires eq rem x 2 0 +ret div x 2 +end +fn main to int +ret int half 7 +end diff --git a/examples/contract_release.stdout b/examples/contract_release.stdout new file mode 100644 index 0000000..e69de29 diff --git a/examples/contract_requires.expect b/examples/contract_requires.expect new file mode 100644 index 0000000..220e337 --- /dev/null +++ b/examples/contract_requires.expect @@ -0,0 +1,2 @@ +compile 0 +exit 109 diff --git a/examples/contract_requires.om b/examples/contract_requires.om new file mode 100644 index 0000000..d8d7d37 --- /dev/null +++ b/examples/contract_requires.om @@ -0,0 +1,12 @@ +note contract_requires: a false precondition traps 9, exit 109, before the body runs +om2 +text before "before\n" +fn half x uint to uint +requires eq rem x 2 0 +ret div x 2 +end +fn main to int +k = write 1 before 0 len before +h = half 7 +ret 0 +end diff --git a/examples/contract_requires.stdout b/examples/contract_requires.stdout new file mode 100644 index 0000000..90be1f3 --- /dev/null +++ b/examples/contract_requires.stdout @@ -0,0 +1 @@ +before diff --git a/examples/contracts_ok.expect b/examples/contracts_ok.expect new file mode 100644 index 0000000..420e65e --- /dev/null +++ b/examples/contracts_ok.expect @@ -0,0 +1,2 @@ +compile 0 +exit 0 diff --git a/examples/contracts_ok.om b/examples/contracts_ok.om new file mode 100644 index 0000000..76cf9cd --- /dev/null +++ b/examples/contracts_ok.om @@ -0,0 +1,15 @@ +note contracts_ok: requires and ensures form a function's prefix; invariant opens a loop body +om2 +fn step x uint to uint +requires lt x 10 +ensures eq result add x 1 +ret add x 1 +end +fn main to int +i = uint 0 +while lt i 3 +invariant le i 3 +i = step i +end +ret int sub i 3 +end diff --git a/examples/contracts_ok.stdout b/examples/contracts_ok.stdout new file mode 100644 index 0000000..e69de29 diff --git a/examples/defect_keyword_prefix.expect b/examples/defect_keyword_prefix.expect new file mode 100644 index 0000000..b5549ae --- /dev/null +++ b/examples/defect_keyword_prefix.expect @@ -0,0 +1,2 @@ +compile 0 +exit 7 diff --git a/examples/defect_keyword_prefix.om b/examples/defect_keyword_prefix.om new file mode 100644 index 0000000..c37f12a --- /dev/null +++ b/examples/defect_keyword_prefix.om @@ -0,0 +1,9 @@ +note keyword_prefix: regression guard at omc 62775d2a. A name of 9..63 bytes is never a +note keyword by its first 8 bytes, so continue_x compiles and returns 7. An exact keyword +note name is still error 16. Older pin 2c824805 refused this file with error 16 on line 4. +fn continue_x to int +ret 7 +end +fn main to int +ret continue_x +end diff --git a/examples/echo_args.args b/examples/echo_args.args new file mode 100644 index 0000000..6b715a7 --- /dev/null +++ b/examples/echo_args.args @@ -0,0 +1,4 @@ +one +two words + +xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx diff --git a/examples/echo_args.expect b/examples/echo_args.expect new file mode 100644 index 0000000..420e65e --- /dev/null +++ b/examples/echo_args.expect @@ -0,0 +1,2 @@ +compile 0 +exit 0 diff --git a/examples/echo_args.om b/examples/echo_args.om new file mode 100644 index 0000000..ac1dbe1 --- /dev/null +++ b/examples/echo_args.om @@ -0,0 +1,72 @@ +note echo_args: argcnt includes the program name; argread copies one argument without a terminator +note ---- output helpers: a function works on a global by naming it (a global is never an argument) +global ob uchar 32 +note outb: write ob[off .. off+n) to stdout; a short write continues, 0 or an error exits 90 +note bound: every pass writes at least one byte and n <= 32, so at most 32 passes +fn outb off ulong n ulong to void +e = add off n +p = off +while lt p e bound 32 +k = write 1 ob p sub e p +if le k 0 +exit 90 +end +p = add p ulong k +end +end +note putu: v in decimal, then a newline. A ulong has at most 20 digits, so 20 passes +fn putu v ulong to void +i = ulong 31 +put ob 31 10 +n = v +while true bound 20 +i = sub i 1 +put ob i uchar add rem n 10 48 +n = div n 10 +if eq n 0 +break +end +end +outb i sub 32 i +end +note putl: a signed value; -(v+1)+1 avoids negating the minimum, which would trap 1 +fn putl v long to void +if lt v 0 +put ob 0 45 +outb 0 1 +putu add ulong neg add v 1 1 +ret +end +putu ulong v +end +global ab uchar 32 +text toolong "(longer than 31 bytes)\n" +fn main to int +n = argcnt +putl n +i = ulong 1 +while lt long i n bound 64 +k = argread i ab 0 31 +if eq k -105 +w = write 1 toolong 0 len toolong +else +m = ulong k +put ab m 10 +outbuf m +end +i = add i 1 +end +ret 0 +end +note outbuf: write ab[0 .. m] (the argument and its newline); exit 90 on an error +fn outbuf m ulong to void +e = add m 1 +p = ulong 0 +while lt p e bound 32 +k = write 1 ab p sub e p +if le k 0 +exit 90 +end +p = add p ulong k +end +end diff --git a/examples/echo_args.stdout b/examples/echo_args.stdout new file mode 100644 index 0000000..dede895 --- /dev/null +++ b/examples/echo_args.stdout @@ -0,0 +1,5 @@ +5 +one +two words + +(longer than 31 bytes) diff --git a/examples/empty_text_part.expect b/examples/empty_text_part.expect new file mode 100644 index 0000000..420e65e --- /dev/null +++ b/examples/empty_text_part.expect @@ -0,0 +1,2 @@ +compile 0 +exit 0 diff --git a/examples/empty_text_part.om b/examples/empty_text_part.om new file mode 100644 index 0000000..ad1181e --- /dev/null +++ b/examples/empty_text_part.om @@ -0,0 +1,19 @@ +note empty_text_part: known defect at the pin (omega-mv #775): an empty text passed to an unsized view +note does not arrive with len 0. Workaround, shown here: pass part e 0 0, which arrives with len 0 +om2 +text e "" +text f "0123456789abcdef0123456789abcdef" +fn n a view uchar * to ulong +ret len a +end +fn main to int +k = n part e 0 0 +if ne k 0 +ret 1 +end +m = n f +if ne m 32 +ret 2 +end +ret 0 +end diff --git a/examples/env_read.env b/examples/env_read.env new file mode 100644 index 0000000..0fc85b2 --- /dev/null +++ b/examples/env_read.env @@ -0,0 +1,4 @@ +LANG=C +OMEGA_HOME=/opt/omega +EMPTY= +LONG=vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv diff --git a/examples/env_read.expect b/examples/env_read.expect new file mode 100644 index 0000000..420e65e --- /dev/null +++ b/examples/env_read.expect @@ -0,0 +1,2 @@ +compile 0 +exit 0 diff --git a/examples/env_read.om b/examples/env_read.om new file mode 100644 index 0000000..a58f967 --- /dev/null +++ b/examples/env_read.om @@ -0,0 +1,67 @@ +note env_read: envcnt counts the environment entries; envread copies one KEY=VALUE without a terminator +note ---- output helpers: a function works on a global by naming it (a global is never an argument) +global ob uchar 32 +note outb: write ob[off .. off+n) to stdout; a short write continues, 0 or an error exits 90 +note bound: every pass writes at least one byte and n <= 32, so at most 32 passes +fn outb off ulong n ulong to void +e = add off n +p = off +while lt p e bound 32 +k = write 1 ob p sub e p +if le k 0 +exit 90 +end +p = add p ulong k +end +end +note putu: v in decimal, then a newline. A ulong has at most 20 digits, so 20 passes +fn putu v ulong to void +i = ulong 31 +put ob 31 10 +n = v +while true bound 20 +i = sub i 1 +put ob i uchar add rem n 10 48 +n = div n 10 +if eq n 0 +break +end +end +outb i sub 32 i +end +note putl: a signed value; -(v+1)+1 avoids negating the minimum, which would trap 1 +fn putl v long to void +if lt v 0 +put ob 0 45 +outb 0 1 +putu add ulong neg add v 1 1 +ret +end +putu ulong v +end +global eb uchar 64 +fn main to int +n = envcnt +putl n +i = ulong 0 +while lt long i n bound 64 +k = envread i eb 0 63 +if lt k 0 +note -105: the entry is longer than the capacity; the buffer is unchanged +k = long 0 +end +m = ulong k +put eb m 10 +e = add m 1 +p = ulong 0 +while lt p e bound 64 +w = write 1 eb p sub e p +if le w 0 +exit 90 +end +p = add p ulong w +end +i = add i 1 +end +ret 0 +end diff --git a/examples/env_read.stdout b/examples/env_read.stdout new file mode 100644 index 0000000..9307c33 --- /dev/null +++ b/examples/env_read.stdout @@ -0,0 +1,5 @@ +4 +LANG=C +OMEGA_HOME=/opt/omega +EMPTY= + diff --git a/examples/err01_input.expect b/examples/err01_input.expect new file mode 100644 index 0000000..b249c0c --- /dev/null +++ b/examples/err01_input.expect @@ -0,0 +1,3 @@ +input dir +compile 1 +stderr omc: line 0: error 1 diff --git a/examples/err01_input.om b/examples/err01_input.om new file mode 100644 index 0000000..f97e469 --- /dev/null +++ b/examples/err01_input.om @@ -0,0 +1,4 @@ +note err01_input: error 1, the compiler could not read its input. The gate feeds a directory as stdin; this file is a placeholder valid program +fn main to int +ret 0 +end diff --git a/examples/err02_output.expect b/examples/err02_output.expect new file mode 100644 index 0000000..00907b1 --- /dev/null +++ b/examples/err02_output.expect @@ -0,0 +1,3 @@ +output full +compile 2 +stderr omc: line 5: error 2 diff --git a/examples/err02_output.om b/examples/err02_output.om new file mode 100644 index 0000000..04b1dab --- /dev/null +++ b/examples/err02_output.om @@ -0,0 +1,4 @@ +note err02_output: error 2, the compiler could not write its output. The gate sends stdout to /dev/full; the program itself is valid +fn main to int +ret 0 +end diff --git a/examples/err03_unknown_name.expect b/examples/err03_unknown_name.expect new file mode 100644 index 0000000..01cfbcb --- /dev/null +++ b/examples/err03_unknown_name.expect @@ -0,0 +1,2 @@ +compile 3 +stderr omc: line 3: error 3 diff --git a/examples/err03_unknown_name.om b/examples/err03_unknown_name.om new file mode 100644 index 0000000..8988c5c --- /dev/null +++ b/examples/err03_unknown_name.om @@ -0,0 +1,4 @@ +note err03_unknown_name: a name that was never assigned, or an unknown field. Fix: assign it first, check spelling +fn main to int +ret q +end diff --git a/examples/err04_line_ends.expect b/examples/err04_line_ends.expect new file mode 100644 index 0000000..961a805 --- /dev/null +++ b/examples/err04_line_ends.expect @@ -0,0 +1,2 @@ +compile 4 +stderr omc: line 5: error 4 diff --git a/examples/err04_line_ends.om b/examples/err04_line_ends.om new file mode 100644 index 0000000..d5f64f3 --- /dev/null +++ b/examples/err04_line_ends.om @@ -0,0 +1,5 @@ +note err04_line_ends: the line ends before the statement is complete; here sub needs two values +fn main to int +x = int 5 +ret sub x +end diff --git a/examples/err05_extra_words.expect b/examples/err05_extra_words.expect new file mode 100644 index 0000000..8fccef0 --- /dev/null +++ b/examples/err05_extra_words.expect @@ -0,0 +1,2 @@ +compile 5 +stderr omc: line 4: error 5 diff --git a/examples/err05_extra_words.om b/examples/err05_extra_words.om new file mode 100644 index 0000000..c617512 --- /dev/null +++ b/examples/err05_extra_words.om @@ -0,0 +1,5 @@ +note err05_extra_words: words left over after a complete statement; prefix words have fixed arity +fn main to int +x = int 5 +ret x 1 +end diff --git a/examples/err06_bad_number.expect b/examples/err06_bad_number.expect new file mode 100644 index 0000000..9c38e39 --- /dev/null +++ b/examples/err06_bad_number.expect @@ -0,0 +1,2 @@ +compile 6 +stderr omc: line 3: error 6 diff --git a/examples/err06_bad_number.om b/examples/err06_bad_number.om new file mode 100644 index 0000000..a6fef9b --- /dev/null +++ b/examples/err06_bad_number.om @@ -0,0 +1,5 @@ +note err06_bad_number: a malformed number; outside OM-2 there are no hex literals +fn main to int +x = uint 0x10 +ret int x +end diff --git a/examples/err07_type_mismatch.expect b/examples/err07_type_mismatch.expect new file mode 100644 index 0000000..20a2f13 --- /dev/null +++ b/examples/err07_type_mismatch.expect @@ -0,0 +1,2 @@ +compile 7 +stderr omc: line 4: error 7 diff --git a/examples/err07_type_mismatch.om b/examples/err07_type_mismatch.om new file mode 100644 index 0000000..6f6c648 --- /dev/null +++ b/examples/err07_type_mismatch.om @@ -0,0 +1,6 @@ +note err07_type_mismatch: no implicit conversions; both values of an op have one type. Fix: add int 1 int u +fn main to int +u = uint 2 +x = add int 1 u +ret x +end diff --git a/examples/err08_out_of_range.expect b/examples/err08_out_of_range.expect new file mode 100644 index 0000000..30adc60 --- /dev/null +++ b/examples/err08_out_of_range.expect @@ -0,0 +1,2 @@ +compile 8 +stderr omc: line 3: error 8 diff --git a/examples/err08_out_of_range.om b/examples/err08_out_of_range.om new file mode 100644 index 0000000..259d1e1 --- /dev/null +++ b/examples/err08_out_of_range.om @@ -0,0 +1,5 @@ +note err08_out_of_range: a literal that does not fit its type; int is -2147483648 .. 2147483647 +fn main to int +x = int 2147483648 +ret 0 +end diff --git a/examples/err09_disallowed.expect b/examples/err09_disallowed.expect new file mode 100644 index 0000000..748158a --- /dev/null +++ b/examples/err09_disallowed.expect @@ -0,0 +1,2 @@ +compile 9 +stderr omc: line 4: error 9 diff --git a/examples/err09_disallowed.om b/examples/err09_disallowed.om new file mode 100644 index 0000000..7e2cdbe --- /dev/null +++ b/examples/err09_disallowed.om @@ -0,0 +1,7 @@ +note err09_disallowed: a word in a place it is not allowed; new is only in a function's outermost block +fn main to int +if true +a = new uchar 4 0 +end +ret 0 +end diff --git a/examples/err10_duplicate.expect b/examples/err10_duplicate.expect new file mode 100644 index 0000000..0f85edc --- /dev/null +++ b/examples/err10_duplicate.expect @@ -0,0 +1,2 @@ +compile 10 +stderr omc: line 2: error 10 diff --git a/examples/err10_duplicate.om b/examples/err10_duplicate.om new file mode 100644 index 0000000..d3c6e87 --- /dev/null +++ b/examples/err10_duplicate.om @@ -0,0 +1,7 @@ +note err10_duplicate: a new name may not repeat a visible name, a function or a struct +fn f x int x int to int +ret x +end +fn main to int +ret f 1 2 +end diff --git a/examples/err11_ambiguous.expect b/examples/err11_ambiguous.expect new file mode 100644 index 0000000..9f8a31e --- /dev/null +++ b/examples/err11_ambiguous.expect @@ -0,0 +1,2 @@ +compile 11 +stderr omc: line 3: error 11 diff --git a/examples/err11_ambiguous.om b/examples/err11_ambiguous.om new file mode 100644 index 0000000..5d43045 --- /dev/null +++ b/examples/err11_ambiguous.om @@ -0,0 +1,5 @@ +note err11_ambiguous: a bare number with nothing to give it a type. Fix: x = uint 5 +fn main to int +x = 5 +ret 0 +end diff --git a/examples/err12_registers.expect b/examples/err12_registers.expect new file mode 100644 index 0000000..373862f --- /dev/null +++ b/examples/err12_registers.expect @@ -0,0 +1,2 @@ +compile 12 +stderr omc: line 19: error 12 diff --git a/examples/err12_registers.om b/examples/err12_registers.om new file mode 100644 index 0000000..c7d4f96 --- /dev/null +++ b/examples/err12_registers.om @@ -0,0 +1,21 @@ +note err12_registers: the 17th live name exhausts the 16-register pool. Fix: fewer live names, smaller functions +fn main to int +a1 = int 1 +a2 = int 2 +a3 = int 3 +a4 = int 4 +a5 = int 5 +a6 = int 6 +a7 = int 7 +a8 = int 8 +a9 = int 9 +a10 = int 10 +a11 = int 11 +a12 = int 12 +a13 = int 13 +a14 = int 14 +a15 = int 15 +a16 = int 16 +a17 = int 17 +ret add a1 add a2 add a3 add a4 add a5 add a6 add a7 add a8 add a9 add a10 add a11 add a12 add a13 add a14 add a15 add a16 a17 +end diff --git a/examples/err13_long_name.expect b/examples/err13_long_name.expect new file mode 100644 index 0000000..e95c893 --- /dev/null +++ b/examples/err13_long_name.expect @@ -0,0 +1,2 @@ +compile 13 +stderr omc: line 3: error 13 diff --git a/examples/err13_long_name.om b/examples/err13_long_name.om new file mode 100644 index 0000000..524c29b --- /dev/null +++ b/examples/err13_long_name.om @@ -0,0 +1,5 @@ +note err13_long_name: a variable, parameter, global, text, const, struct or field name has at most 8 characters +fn main to int +counter1x = int 1 +ret 0 +end diff --git a/examples/err14_capacity.expect b/examples/err14_capacity.expect new file mode 100644 index 0000000..00820ee --- /dev/null +++ b/examples/err14_capacity.expect @@ -0,0 +1,2 @@ +compile 14 +stderr omc: line 99: error 14 diff --git a/examples/err14_capacity.om b/examples/err14_capacity.om new file mode 100644 index 0000000..e8230b1 --- /dev/null +++ b/examples/err14_capacity.om @@ -0,0 +1,101 @@ +note err14_capacity: a compiler capacity; here the 33rd export in one OM-2 unit (limit 32). Exports are function mode, so no main +om2 +export fn e0 x uint to uint +ret x +end +export fn e1 x uint to uint +ret x +end +export fn e2 x uint to uint +ret x +end +export fn e3 x uint to uint +ret x +end +export fn e4 x uint to uint +ret x +end +export fn e5 x uint to uint +ret x +end +export fn e6 x uint to uint +ret x +end +export fn e7 x uint to uint +ret x +end +export fn e8 x uint to uint +ret x +end +export fn e9 x uint to uint +ret x +end +export fn e10 x uint to uint +ret x +end +export fn e11 x uint to uint +ret x +end +export fn e12 x uint to uint +ret x +end +export fn e13 x uint to uint +ret x +end +export fn e14 x uint to uint +ret x +end +export fn e15 x uint to uint +ret x +end +export fn e16 x uint to uint +ret x +end +export fn e17 x uint to uint +ret x +end +export fn e18 x uint to uint +ret x +end +export fn e19 x uint to uint +ret x +end +export fn e20 x uint to uint +ret x +end +export fn e21 x uint to uint +ret x +end +export fn e22 x uint to uint +ret x +end +export fn e23 x uint to uint +ret x +end +export fn e24 x uint to uint +ret x +end +export fn e25 x uint to uint +ret x +end +export fn e26 x uint to uint +ret x +end +export fn e27 x uint to uint +ret x +end +export fn e28 x uint to uint +ret x +end +export fn e29 x uint to uint +ret x +end +export fn e30 x uint to uint +ret x +end +export fn e31 x uint to uint +ret x +end +export fn e32 x uint to uint +ret x +end diff --git a/examples/err15_missing_end.expect b/examples/err15_missing_end.expect new file mode 100644 index 0000000..e896155 --- /dev/null +++ b/examples/err15_missing_end.expect @@ -0,0 +1,2 @@ +compile 15 +stderr omc: line 4: error 15 diff --git a/examples/err15_missing_end.om b/examples/err15_missing_end.om new file mode 100644 index 0000000..45af5f6 --- /dev/null +++ b/examples/err15_missing_end.om @@ -0,0 +1,3 @@ +note err15_missing_end: the input ends inside an open function or block +fn main to int +ret 0 diff --git a/examples/err16_syntax.expect b/examples/err16_syntax.expect new file mode 100644 index 0000000..520abe4 --- /dev/null +++ b/examples/err16_syntax.expect @@ -0,0 +1,2 @@ +compile 16 +stderr omc: line 2: error 16 diff --git a/examples/err16_syntax.om b/examples/err16_syntax.om new file mode 100644 index 0000000..7edb2bb --- /dev/null +++ b/examples/err16_syntax.om @@ -0,0 +1,4 @@ +note err16_syntax: a line that starts with no statement word; C-style declarations are not Omega +int main to int +ret 0 +end diff --git a/examples/err17_after_path.expect b/examples/err17_after_path.expect new file mode 100644 index 0000000..bde48f7 --- /dev/null +++ b/examples/err17_after_path.expect @@ -0,0 +1,2 @@ +compile 17 +stderr omc: line 4: error 17 diff --git a/examples/err17_after_path.om b/examples/err17_after_path.om new file mode 100644 index 0000000..fa3cb52 --- /dev/null +++ b/examples/err17_after_path.om @@ -0,0 +1,5 @@ +note err17_after_path: a line after ret, break, continue, trap or exit in the same block can never run +fn main to int +ret 0 +ret 1 +end diff --git a/examples/err18_missing_ret.expect b/examples/err18_missing_ret.expect new file mode 100644 index 0000000..2171436 --- /dev/null +++ b/examples/err18_missing_ret.expect @@ -0,0 +1,2 @@ +compile 18 +stderr omc: line 7: error 18 diff --git a/examples/err18_missing_ret.om b/examples/err18_missing_ret.om new file mode 100644 index 0000000..888bdbe --- /dev/null +++ b/examples/err18_missing_ret.om @@ -0,0 +1,9 @@ +note err18_missing_ret: a function with a result type whose end is reachable +fn f x int to int +if gt x 0 +ret 1 +end +end +fn main to int +ret f 1 +end diff --git a/examples/err19_global_arg.expect b/examples/err19_global_arg.expect new file mode 100644 index 0000000..43e0fb9 --- /dev/null +++ b/examples/err19_global_arg.expect @@ -0,0 +1,2 @@ +compile 19 +stderr omc: line 7: error 19 diff --git a/examples/err19_global_arg.om b/examples/err19_global_arg.om new file mode 100644 index 0000000..0615a6f --- /dev/null +++ b/examples/err19_global_arg.om @@ -0,0 +1,9 @@ +note err19_global_arg: a global is never an argument. Fix: name the global inside the function +global g uchar 4 +fn f a edit uchar 4 to void +put a 0 1 +end +fn main to int +f g +ret 0 +end diff --git a/examples/err20_readonly.expect b/examples/err20_readonly.expect new file mode 100644 index 0000000..fed7792 --- /dev/null +++ b/examples/err20_readonly.expect @@ -0,0 +1,2 @@ +compile 20 +stderr omc: line 4: error 20 diff --git a/examples/err20_readonly.om b/examples/err20_readonly.om new file mode 100644 index 0000000..891f0a7 --- /dev/null +++ b/examples/err20_readonly.om @@ -0,0 +1,6 @@ +note err20_readonly: a text or a view parameter is read-only +text t "abc" +fn main to int +put t 0 1 +ret 0 +end diff --git a/examples/err21_const_index.expect b/examples/err21_const_index.expect new file mode 100644 index 0000000..1d9001b --- /dev/null +++ b/examples/err21_const_index.expect @@ -0,0 +1,2 @@ +compile 21 +stderr omc: line 4: error 21 diff --git a/examples/err21_const_index.om b/examples/err21_const_index.om new file mode 100644 index 0000000..b22e1a3 --- /dev/null +++ b/examples/err21_const_index.om @@ -0,0 +1,6 @@ +note err21_const_index: a literal index outside the array is refused at compile time (a run-time index traps 3) +fn main to int +a = new uint 4 0 +put a 4 1 +ret 0 +end diff --git a/examples/err22_text_escape.expect b/examples/err22_text_escape.expect new file mode 100644 index 0000000..898ff62 --- /dev/null +++ b/examples/err22_text_escape.expect @@ -0,0 +1,2 @@ +compile 22 +stderr omc: line 2: error 22 diff --git a/examples/err22_text_escape.om b/examples/err22_text_escape.om new file mode 100644 index 0000000..25e451a --- /dev/null +++ b/examples/err22_text_escape.om @@ -0,0 +1,5 @@ +note err22_text_escape: a text escape other than backslash n, t, backslash or quote +text t "a\q" +fn main to int +ret 0 +end diff --git a/examples/err23_size.expect b/examples/err23_size.expect new file mode 100644 index 0000000..0eaa096 --- /dev/null +++ b/examples/err23_size.expect @@ -0,0 +1,2 @@ +compile 23 +stderr omc: line 3: error 23 diff --git a/examples/err23_size.om b/examples/err23_size.om new file mode 100644 index 0000000..ad677f6 --- /dev/null +++ b/examples/err23_size.om @@ -0,0 +1,5 @@ +note err23_size: an array over 16777216 elements, or over 4 MiB of local arrays, or 1 GiB of globals +fn main to int +a = new uchar 16777217 0 +ret 0 +end diff --git a/examples/err25_target.expect b/examples/err25_target.expect new file mode 100644 index 0000000..98fcd6d --- /dev/null +++ b/examples/err25_target.expect @@ -0,0 +1,2 @@ +compile 25 +stderr omc: line 1: error 25 diff --git a/examples/err25_target.om b/examples/err25_target.om new file mode 100644 index 0000000..8fcd9e9 --- /dev/null +++ b/examples/err25_target.om @@ -0,0 +1,5 @@ +target foo +note err25_target: an unknown target name (or an AArch64-only path on another target); target must be the first line +fn main to int +ret 0 +end diff --git a/examples/err27_fresh.expect b/examples/err27_fresh.expect new file mode 100644 index 0000000..2a72e5e --- /dev/null +++ b/examples/err27_fresh.expect @@ -0,0 +1,2 @@ +compile 27 +stderr omc: line 4: error 27 diff --git a/examples/err27_fresh.om b/examples/err27_fresh.om new file mode 100644 index 0000000..ebdc267 --- /dev/null +++ b/examples/err27_fresh.om @@ -0,0 +1,9 @@ +note err27_fresh: OM-2 fresh means every element is written before it is read +om2 +fn f s edit uint 4 fresh to uint +ret get s 0 +end +fn main to int +a = new uint 4 0 +ret int f a +end diff --git a/examples/err28_seal.expect b/examples/err28_seal.expect new file mode 100644 index 0000000..74344a9 --- /dev/null +++ b/examples/err28_seal.expect @@ -0,0 +1,2 @@ +compile 28 +stderr omc: line 6: error 28 diff --git a/examples/err28_seal.om b/examples/err28_seal.om new file mode 100644 index 0000000..1a63955 --- /dev/null +++ b/examples/err28_seal.om @@ -0,0 +1,8 @@ +note err28_seal: OM-2 seal is allowed only as the whole body of the abstract type's constructor +om2 +abstract v32 ulong +holds v32 dup32 +fn main to int +v = seal v32 ulong 0 +ret 0 +end diff --git a/examples/err29_layout.expect b/examples/err29_layout.expect new file mode 100644 index 0000000..c48967f --- /dev/null +++ b/examples/err29_layout.expect @@ -0,0 +1,2 @@ +compile 29 +stderr omc: line 4: error 29 diff --git a/examples/err29_layout.om b/examples/err29_layout.om new file mode 100644 index 0000000..549b681 --- /dev/null +++ b/examples/err29_layout.om @@ -0,0 +1,8 @@ +note err29_layout: an OM-2 layout field past the layout's size, or overlapping another field +om2 +layout blk 4 +field lo uint at 2 little +end +fn main to int +ret 0 +end diff --git a/examples/err30_contract.expect b/examples/err30_contract.expect new file mode 100644 index 0000000..d46080c --- /dev/null +++ b/examples/err30_contract.expect @@ -0,0 +1,2 @@ +compile 30 +stderr omc: line 7: error 30 diff --git a/examples/err30_contract.om b/examples/err30_contract.om new file mode 100644 index 0000000..2a5f503 --- /dev/null +++ b/examples/err30_contract.om @@ -0,0 +1,12 @@ +note err30_contract: a contract clause may not call a function, use floats or host words; result needs a value postcondition +om2 +fn g x uint to uint +ret x +end +fn f x uint to uint +requires lt g x 10 +ret x +end +fn main to int +ret int f 1 +end diff --git a/examples/exit_status.expect b/examples/exit_status.expect new file mode 100644 index 0000000..e5fc3bf --- /dev/null +++ b/examples/exit_status.expect @@ -0,0 +1,2 @@ +compile 0 +exit 44 diff --git a/examples/exit_status.om b/examples/exit_status.om new file mode 100644 index 0000000..9ee30a1 --- /dev/null +++ b/examples/exit_status.om @@ -0,0 +1,4 @@ +note exit_status: the exit status is main's value mod 256; 300 mod 256 = 44 +fn main to int +ret 300 +end diff --git a/examples/exit_status.stdout b/examples/exit_status.stdout new file mode 100644 index 0000000..e69de29 diff --git a/examples/float_arith.expect b/examples/float_arith.expect new file mode 100644 index 0000000..420e65e --- /dev/null +++ b/examples/float_arith.expect @@ -0,0 +1,2 @@ +compile 0 +exit 0 diff --git a/examples/float_arith.om b/examples/float_arith.om new file mode 100644 index 0000000..996234b --- /dev/null +++ b/examples/float_arith.om @@ -0,0 +1,63 @@ +note float_arith: IEEE binary64, round to nearest even, no float operation traps +note ---- output helpers: a function works on a global by naming it (a global is never an argument) +global ob uchar 32 +note outb: write ob[off .. off+n) to stdout; a short write continues, 0 or an error exits 90 +note bound: every pass writes at least one byte and n <= 32, so at most 32 passes +fn outb off ulong n ulong to void +e = add off n +p = off +while lt p e bound 32 +k = write 1 ob p sub e p +if le k 0 +exit 90 +end +p = add p ulong k +end +end +note putu: v in decimal, then a newline. A ulong has at most 20 digits, so 20 passes +fn putu v ulong to void +i = ulong 31 +put ob 31 10 +n = v +while true bound 20 +i = sub i 1 +put ob i uchar add rem n 10 48 +n = div n 10 +if eq n 0 +break +end +end +outb i sub 32 i +end +note putl: a signed value; -(v+1)+1 avoids negating the minimum, which would trap 1 +fn putl v long to void +if lt v 0 +put ob 0 45 +outb 0 1 +putu add ulong neg add v 1 1 +ret +end +putu ulong v +end +fn main to int +r = fsqrt 2.0f64 +putl long mul r 1000000000.0 +s = add 0.1f64 0.2 +putu bitcast ulong s +putu bitcast ulong 1.0f64 +z = f64 0.0 +n = div z z +if ne n n +putu 1 +end +if eq n n +putu 2 +end +i = div 1.0 z +if gt i 1.0e308 +putu 3 +end +putl long fmin -2.5f64 3.0f64 +putl long fabs -7.9f64 +ret 0 +end diff --git a/examples/float_arith.stdout b/examples/float_arith.stdout new file mode 100644 index 0000000..035b294 --- /dev/null +++ b/examples/float_arith.stdout @@ -0,0 +1,7 @@ +1414213562 +4599075939470750516 +4607182418800017408 +1 +3 +-2 +7 diff --git a/examples/float_to_int.expect b/examples/float_to_int.expect new file mode 100644 index 0000000..420e65e --- /dev/null +++ b/examples/float_to_int.expect @@ -0,0 +1,2 @@ +compile 0 +exit 0 diff --git a/examples/float_to_int.om b/examples/float_to_int.om new file mode 100644 index 0000000..1ae561f --- /dev/null +++ b/examples/float_to_int.om @@ -0,0 +1,51 @@ +note float_to_int: float to integer truncates toward zero and saturates; NaN becomes 0; no trap +note ---- output helpers: a function works on a global by naming it (a global is never an argument) +global ob uchar 32 +note outb: write ob[off .. off+n) to stdout; a short write continues, 0 or an error exits 90 +note bound: every pass writes at least one byte and n <= 32, so at most 32 passes +fn outb off ulong n ulong to void +e = add off n +p = off +while lt p e bound 32 +k = write 1 ob p sub e p +if le k 0 +exit 90 +end +p = add p ulong k +end +end +note putu: v in decimal, then a newline. A ulong has at most 20 digits, so 20 passes +fn putu v ulong to void +i = ulong 31 +put ob 31 10 +n = v +while true bound 20 +i = sub i 1 +put ob i uchar add rem n 10 48 +n = div n 10 +if eq n 0 +break +end +end +outb i sub 32 i +end +note putl: a signed value; -(v+1)+1 avoids negating the minimum, which would trap 1 +fn putl v long to void +if lt v 0 +put ob 0 45 +outb 0 1 +putu add ulong neg add v 1 1 +ret +end +putu ulong v +end +fn main to int +putl long 1.0e30f64 +putl long -1.0e30f64 +putl long -5.75f64 +putu ulong uint -5.5f64 +z = f64 0.0 +putl long div z z +putu ulong uchar 300.0f64 +ret 0 +end diff --git a/examples/float_to_int.stdout b/examples/float_to_int.stdout new file mode 100644 index 0000000..36e9bc7 --- /dev/null +++ b/examples/float_to_int.stdout @@ -0,0 +1,6 @@ +9223372036854775807 +-9223372036854775808 +-5 +0 +0 +255 diff --git a/examples/functions.expect b/examples/functions.expect new file mode 100644 index 0000000..420e65e --- /dev/null +++ b/examples/functions.expect @@ -0,0 +1,2 @@ +compile 0 +exit 0 diff --git a/examples/functions.om b/examples/functions.om new file mode 100644 index 0000000..52f6e9c --- /dev/null +++ b/examples/functions.om @@ -0,0 +1,66 @@ +note functions: at most 6 parameters; a call may name any function in the unit; recursion in program mode +note ---- output helpers: a function works on a global by naming it (a global is never an argument) +global ob uchar 32 +note outb: write ob[off .. off+n) to stdout; a short write continues, 0 or an error exits 90 +note bound: every pass writes at least one byte and n <= 32, so at most 32 passes +fn outb off ulong n ulong to void +e = add off n +p = off +while lt p e bound 32 +k = write 1 ob p sub e p +if le k 0 +exit 90 +end +p = add p ulong k +end +end +note putu: v in decimal, then a newline. A ulong has at most 20 digits, so 20 passes +fn putu v ulong to void +i = ulong 31 +put ob 31 10 +n = v +while true bound 20 +i = sub i 1 +put ob i uchar add rem n 10 48 +n = div n 10 +if eq n 0 +break +end +end +outb i sub 32 i +end +note putl: a signed value; -(v+1)+1 avoids negating the minimum, which would trap 1 +fn putl v long to void +if lt v 0 +put ob 0 45 +outb 0 1 +putu add ulong neg add v 1 1 +ret +end +putu ulong v +end +fn main to int +putu fact 20 +putu gcd 1071 462 +putu ulong pick 1 2 3 4 5 6 +ret 0 +end +fn fact n ulong to ulong +if le n 1 +ret 1 +end +ret mul n fact sub n 1 +end +fn gcd a ulong b ulong to ulong +x = a +y = b +while ne y 0 bound 200 +t = rem x y +x = y +y = t +end +ret x +end +fn pick a int b int c int d int e int f int to int +ret add add a f mul b sub e d +end diff --git a/examples/functions.stdout b/examples/functions.stdout new file mode 100644 index 0000000..01a15d5 --- /dev/null +++ b/examples/functions.stdout @@ -0,0 +1,3 @@ +2432902008176640000 +21 +9 diff --git a/examples/gate.sh b/examples/gate.sh new file mode 100755 index 0000000..f13faaf --- /dev/null +++ b/examples/gate.sh @@ -0,0 +1,154 @@ +#!/usr/bin/env bash +# gate.sh OMC: compile and run every worked example against its expected result. +# +# Covers examples/*.om and skills/*/examples/*.om. Each NAME.om needs NAME.expect: +# compile N required; the compiler's exit status +# stderr LINE required when N is not 0; the compiler's whole stderr is exactly LINE +# exit N required when N is 0; the program's exit status +# input dir optional; the compiler reads a directory instead of NAME.om (error 1) +# output full optional; the compiler writes to /dev/full (error 2) +# Optional fixtures: NAME.stdout (exact stdout bytes, absent means empty), NAME.stdin (piped in, +# so reads can be partial), NAME.args (one argument per line), NAME.env (one KEY=VALUE per line). +# Every program runs with `env -i` plus NAME.env, in an empty scratch directory, under a 20 s +# timeout, and must write nothing to stderr. A compile that is not expected to succeed is never run. +# +# The compiler must match the pinned sha256 below; a different binary is refused, not tolerated. +# Exit 0 only when every example passes; 1 on any failure; 2 on a usage or pin error. +set -u + +PIN_REV=91c83438daec0bdb88bf5c077cae10f3d15d365d +PIN_SHA=2aec185d4ed6d7a6a5779ed656b4e56904742bde5551b02893fb5f73916ad8d5 + +if [ "$#" -ne 1 ]; then + echo "usage: $0 /path/to/omc (omega-mv $PIN_REV seed/out/omc)" >&2 + exit 2 +fi +omc=$(cd "$(dirname "$1")" && pwd)/$(basename "$1") +if [ ! -x "$omc" ]; then + echo "GATE FAIL $1 is not an executable file" >&2 + exit 2 +fi +got=$(sha256sum "$omc" | cut -d' ' -f1) +if [ "$got" != "$PIN_SHA" ]; then + echo "GATE FAIL omc sha256 $got, pinned $PIN_SHA (omega-mv $PIN_REV)" >&2 + exit 2 +fi + +here=$(cd "$(dirname "$0")" && pwd) +root=$(dirname "$here") +work=$(mktemp -d) +trap 'rm -rf "$work"' EXIT + +pass=0 +fail=0 +total=0 + +bad() { + echo "FAIL $name: $*" + fail=$((fail + 1)) +} + +# Expected files without a program are a silent loss of coverage, so they fail too. +for f in "$root"/examples/*.expect "$root"/skills/*/examples/*.expect; do + [ -e "$f" ] || continue + if [ ! -e "${f%.expect}.om" ]; then + name=$(basename "${f%.expect}") + total=$((total + 1)) + bad "expect file without $name.om" + fi +done + +for src in "$root"/examples/*.om "$root"/skills/*/examples/*.om; do + [ -e "$src" ] || continue + base=${src%.om} + name=${base#"$root"/} + total=$((total + 1)) + if [ ! -f "$base.expect" ]; then + bad "no $name.expect" + continue + fi + want_compile= want_stderr= want_exit= input=file output=file + while IFS= read -r line || [ -n "$line" ]; do + case $line in + "compile "*) want_compile=${line#compile } ;; + "stderr "*) want_stderr=${line#stderr } ;; + "exit "*) want_exit=${line#exit } ;; + "input dir") input=dir ;; + "output full") output=full ;; + "") ;; + *) want_compile=invalid ;; + esac + done < "$base.expect" + case $want_compile in + ''|invalid|*[!0-9]*) bad "malformed $name.expect"; continue ;; + esac + if [ "$want_compile" != 0 ] && [ -z "$want_stderr" ]; then + bad "$name.expect has no stderr line"; continue + fi + if [ "$want_compile" = 0 ]; then + case $want_exit in + ''|*[!0-9]*) bad "$name.expect has no exit line"; continue ;; + esac + fi + + d=$work/$(echo "$name" | tr / _) + mkdir -p "$d/run" + in=$src + [ "$input" = dir ] && in=$d/run + out=$d/p + [ "$output" = full ] && out=/dev/full + "$omc" < "$in" > "$out" 2> "$d/cerr" + rc=$? + if [ "$rc" != "$want_compile" ]; then + bad "compile exit $rc, expected $want_compile: $(cat "$d/cerr")" + continue + fi + if [ "$want_compile" != 0 ]; then + if printf '%s\n' "$want_stderr" | cmp -s - "$d/cerr"; then + echo "PASS $name (compile $rc: $want_stderr)" + pass=$((pass + 1)) + else + bad "compiler stderr '$(cat "$d/cerr")', expected '$want_stderr'" + fi + continue + fi + if [ -s "$d/cerr" ]; then + bad "compiler stderr not empty: $(cat "$d/cerr")" + continue + fi + + chmod +x "$d/p" + args=() + envs=() + if [ -f "$base.args" ]; then mapfile -t args < "$base.args"; fi + if [ -f "$base.env" ]; then mapfile -t envs < "$base.env"; fi + if [ -f "$base.stdin" ]; then + (cd "$d/run" && cat "$base.stdin" | timeout 20 env -i "${envs[@]}" "$d/p" "${args[@]}" > "$d/out" 2> "$d/rerr") + else + (cd "$d/run" && timeout 20 env -i "${envs[@]}" "$d/p" "${args[@]}" < /dev/null > "$d/out" 2> "$d/rerr") + fi + rc=$? + want_out=/dev/null + [ -f "$base.stdout" ] && want_out=$base.stdout + if [ "$rc" != "$want_exit" ]; then + bad "exit $rc, expected $want_exit" + elif ! cmp -s "$want_out" "$d/out"; then + bad "stdout differs from $(basename "$want_out"): $(od -An -c "$d/out" | tr -s ' ' | tr -d '\n' | cut -c1-200)" + elif [ -s "$d/rerr" ]; then + bad "program stderr not empty: $(cat "$d/rerr")" + else + echo "PASS $name (exit $rc, $(wc -c < "$d/out" | tr -d ' ') stdout bytes)" + pass=$((pass + 1)) + fi +done + +if [ "$total" = 0 ]; then + echo "GATE FAIL no examples found under $root" + exit 1 +fi +if [ "$fail" = 0 ] && [ "$pass" = "$total" ]; then + echo "GATE PASS examples=$total pass=$pass fail=0 omc=$PIN_SHA" + exit 0 +fi +echo "GATE FAIL examples=$total pass=$pass fail=$fail omc=$got" +exit 1 diff --git a/examples/globals.expect b/examples/globals.expect new file mode 100644 index 0000000..420e65e --- /dev/null +++ b/examples/globals.expect @@ -0,0 +1,2 @@ +compile 0 +exit 0 diff --git a/examples/globals.om b/examples/globals.om new file mode 100644 index 0000000..a955bea --- /dev/null +++ b/examples/globals.om @@ -0,0 +1,63 @@ +note globals: zero-filled pools in the program image, visible in every function, named directly +note ---- output helpers: a function works on a global by naming it (a global is never an argument) +global ob uchar 32 +note outb: write ob[off .. off+n) to stdout; a short write continues, 0 or an error exits 90 +note bound: every pass writes at least one byte and n <= 32, so at most 32 passes +fn outb off ulong n ulong to void +e = add off n +p = off +while lt p e bound 32 +k = write 1 ob p sub e p +if le k 0 +exit 90 +end +p = add p ulong k +end +end +note putu: v in decimal, then a newline. A ulong has at most 20 digits, so 20 passes +fn putu v ulong to void +i = ulong 31 +put ob 31 10 +n = v +while true bound 20 +i = sub i 1 +put ob i uchar add rem n 10 48 +n = div n 10 +if eq n 0 +break +end +end +outb i sub 32 i +end +note putl: a signed value; -(v+1)+1 avoids negating the minimum, which would trap 1 +fn putl v long to void +if lt v 0 +put ob 0 45 +outb 0 1 +putu add ulong neg add v 1 1 +ret +end +putu ulong v +end +global hist ulong 10 +note tally: count the decimal digits of v into hist +fn tally v ulong to void +n = v +while true bound 20 +d = rem n 10 +put hist d add get hist d 1 +n = div n 10 +if eq n 0 +break +end +end +end +fn main to int +tally 1234567890 +tally 9999 +tally 0 +putu get hist 9 +putu get hist 0 +putu get hist 5 +ret 0 +end diff --git a/examples/globals.stdout b/examples/globals.stdout new file mode 100644 index 0000000..0e81b4b --- /dev/null +++ b/examples/globals.stdout @@ -0,0 +1,3 @@ +5 +2 +1 diff --git a/examples/hello.expect b/examples/hello.expect new file mode 100644 index 0000000..420e65e --- /dev/null +++ b/examples/hello.expect @@ -0,0 +1,2 @@ +compile 0 +exit 0 diff --git a/examples/hello.om b/examples/hello.om new file mode 100644 index 0000000..464ef15 --- /dev/null +++ b/examples/hello.om @@ -0,0 +1,9 @@ +note hello: the smallest complete program. A text is a read-only uchar array +text msg "hello, world\n" +fn main to int +k = write 1 msg 0 len msg +if ne k long len msg +ret 1 +end +ret 0 +end diff --git a/examples/hello.stdout b/examples/hello.stdout new file mode 100644 index 0000000..4b5fa63 --- /dev/null +++ b/examples/hello.stdout @@ -0,0 +1 @@ +hello, world diff --git a/examples/int_arith.expect b/examples/int_arith.expect new file mode 100644 index 0000000..420e65e --- /dev/null +++ b/examples/int_arith.expect @@ -0,0 +1,2 @@ +compile 0 +exit 0 diff --git a/examples/int_arith.om b/examples/int_arith.om new file mode 100644 index 0000000..0833e1d --- /dev/null +++ b/examples/int_arith.om @@ -0,0 +1,53 @@ +note int_arith: signed div rounds toward zero, rem takes the dividend's sign, shr keeps the sign +note ---- output helpers: a function works on a global by naming it (a global is never an argument) +global ob uchar 32 +note outb: write ob[off .. off+n) to stdout; a short write continues, 0 or an error exits 90 +note bound: every pass writes at least one byte and n <= 32, so at most 32 passes +fn outb off ulong n ulong to void +e = add off n +p = off +while lt p e bound 32 +k = write 1 ob p sub e p +if le k 0 +exit 90 +end +p = add p ulong k +end +end +note putu: v in decimal, then a newline. A ulong has at most 20 digits, so 20 passes +fn putu v ulong to void +i = ulong 31 +put ob 31 10 +n = v +while true bound 20 +i = sub i 1 +put ob i uchar add rem n 10 48 +n = div n 10 +if eq n 0 +break +end +end +outb i sub 32 i +end +note putl: a signed value; -(v+1)+1 avoids negating the minimum, which would trap 1 +fn putl v long to void +if lt v 0 +put ob 0 45 +outb 0 1 +putu add ulong neg add v 1 1 +ret +end +putu ulong v +end +fn main to int +a = long -7 +b = long 2 +putl div a b +putl rem a b +putl div 7 neg b +putl rem 7 neg b +putl mul 123456789 long 987654321 +putl shr long -16 2 +putl sub 0 a +ret 0 +end diff --git a/examples/int_arith.stdout b/examples/int_arith.stdout new file mode 100644 index 0000000..4896f8f --- /dev/null +++ b/examples/int_arith.stdout @@ -0,0 +1,7 @@ +-3 +-1 +-3 +1 +121932631112635269 +-4 +7 diff --git a/examples/int_bits_and.expect b/examples/int_bits_and.expect new file mode 100644 index 0000000..c78106d --- /dev/null +++ b/examples/int_bits_and.expect @@ -0,0 +1,2 @@ +compile 0 +exit 8 diff --git a/examples/int_bits_and.om b/examples/int_bits_and.om new file mode 100644 index 0000000..760f90f --- /dev/null +++ b/examples/int_bits_and.om @@ -0,0 +1,10 @@ +note int_bits_and: and, or, xor on integers are bitwise. 12 is 1100, 10 is 1010, so and gives 1000 = 8 +fn main to int +x = ulong 12 +y = and x ulong 10 +z = and int 12 int 10 +if ne int y z +ret 1 +end +ret z +end diff --git a/examples/loops.expect b/examples/loops.expect new file mode 100644 index 0000000..420e65e --- /dev/null +++ b/examples/loops.expect @@ -0,0 +1,2 @@ +compile 0 +exit 0 diff --git a/examples/loops.om b/examples/loops.om new file mode 100644 index 0000000..78d3c2a --- /dev/null +++ b/examples/loops.om @@ -0,0 +1,70 @@ +note loops: while COND bound N (1..999999), for i T K, break and continue +note ---- output helpers: a function works on a global by naming it (a global is never an argument) +global ob uchar 32 +note outb: write ob[off .. off+n) to stdout; a short write continues, 0 or an error exits 90 +note bound: every pass writes at least one byte and n <= 32, so at most 32 passes +fn outb off ulong n ulong to void +e = add off n +p = off +while lt p e bound 32 +k = write 1 ob p sub e p +if le k 0 +exit 90 +end +p = add p ulong k +end +end +note putu: v in decimal, then a newline. A ulong has at most 20 digits, so 20 passes +fn putu v ulong to void +i = ulong 31 +put ob 31 10 +n = v +while true bound 20 +i = sub i 1 +put ob i uchar add rem n 10 48 +n = div n 10 +if eq n 0 +break +end +end +outb i sub 32 i +end +note putl: a signed value; -(v+1)+1 avoids negating the minimum, which would trap 1 +fn putl v long to void +if lt v 0 +put ob 0 45 +outb 0 1 +putu add ulong neg add v 1 1 +ret +end +putu ulong v +end +note collatz: the step count to reach 1; the bound is a stated limit, not a proof, so exceeding it traps 4 +fn collatz n ulong to ulong +x = n +c = ulong 0 +while ne x 1 bound 1000 +c = add c 1 +if eq rem x 2 0 +x = div x 2 +continue +end +x = add mul x 3 1 +end +ret c +end +fn main to int +putu collatz 27 +s = ulong 0 +for i ulong 100 +if eq rem i 3 0 +continue +end +if gt i 50 +break +end +s = add s i +end +putu s +ret 0 +end diff --git a/examples/loops.stdout b/examples/loops.stdout new file mode 100644 index 0000000..3d4b5df --- /dev/null +++ b/examples/loops.stdout @@ -0,0 +1,2 @@ +111 +867 diff --git a/examples/mistake_bound_range.expect b/examples/mistake_bound_range.expect new file mode 100644 index 0000000..05803dc --- /dev/null +++ b/examples/mistake_bound_range.expect @@ -0,0 +1,2 @@ +compile 8 +stderr omc: line 4: error 8 diff --git a/examples/mistake_bound_range.om b/examples/mistake_bound_range.om new file mode 100644 index 0000000..d6e3054 --- /dev/null +++ b/examples/mistake_bound_range.om @@ -0,0 +1,8 @@ +note mistake_bound_range: a while bound is 1..999999; without bound the limit is 1000000 passes +fn main to int +i = ulong 0 +while lt i 3 bound 1000000 +i = add i 1 +end +ret 0 +end diff --git a/examples/mistake_c_call.expect b/examples/mistake_c_call.expect new file mode 100644 index 0000000..8845172 --- /dev/null +++ b/examples/mistake_c_call.expect @@ -0,0 +1,2 @@ +compile 6 +stderr omc: line 6: error 6 diff --git a/examples/mistake_c_call.om b/examples/mistake_c_call.om new file mode 100644 index 0000000..6f2af4c --- /dev/null +++ b/examples/mistake_c_call.om @@ -0,0 +1,7 @@ +note mistake_c_call: a call is the function name then its values, no brackets or commas. Fix: ret f 1 2 +fn f a int b int to int +ret add a b +end +fn main to int +ret f(1, 2) +end diff --git a/examples/mistake_char_literal.expect b/examples/mistake_char_literal.expect new file mode 100644 index 0000000..01cfbcb --- /dev/null +++ b/examples/mistake_char_literal.expect @@ -0,0 +1,2 @@ +compile 3 +stderr omc: line 3: error 3 diff --git a/examples/mistake_char_literal.om b/examples/mistake_char_literal.om new file mode 100644 index 0000000..91e5a2a --- /dev/null +++ b/examples/mistake_char_literal.om @@ -0,0 +1,5 @@ +note mistake_char_literal: there are no character literals; write the byte value. Fix: x = uchar 65 +fn main to int +x = uchar 'A' +ret 0 +end diff --git a/examples/mistake_compare_operator.expect b/examples/mistake_compare_operator.expect new file mode 100644 index 0000000..20a2f13 --- /dev/null +++ b/examples/mistake_compare_operator.expect @@ -0,0 +1,2 @@ +compile 7 +stderr omc: line 4: error 7 diff --git a/examples/mistake_compare_operator.om b/examples/mistake_compare_operator.om new file mode 100644 index 0000000..d731d01 --- /dev/null +++ b/examples/mistake_compare_operator.om @@ -0,0 +1,8 @@ +note mistake_compare_operator: conditions are bool values built with eq ne lt le gt ge; > is not a word. Fix: if gt x 0 +fn main to int +x = int 1 +if x > 0 +ret 1 +end +ret 0 +end diff --git a/examples/mistake_else_if.expect b/examples/mistake_else_if.expect new file mode 100644 index 0000000..39a9fc7 --- /dev/null +++ b/examples/mistake_else_if.expect @@ -0,0 +1,2 @@ +compile 5 +stderr omc: line 6: error 5 diff --git a/examples/mistake_else_if.om b/examples/mistake_else_if.om new file mode 100644 index 0000000..bced1f2 --- /dev/null +++ b/examples/mistake_else_if.om @@ -0,0 +1,10 @@ +note mistake_else_if: there is no else if on one line; nest an if inside the else block +fn main to int +x = int 1 +if eq x 0 +ret 1 +else if eq x 1 +ret 2 +end +ret 0 +end diff --git a/examples/mistake_for_bound.expect b/examples/mistake_for_bound.expect new file mode 100644 index 0000000..640c914 --- /dev/null +++ b/examples/mistake_for_bound.expect @@ -0,0 +1,2 @@ +compile 5 +stderr omc: line 5: error 5 diff --git a/examples/mistake_for_bound.om b/examples/mistake_for_bound.om new file mode 100644 index 0000000..cf0e210 --- /dev/null +++ b/examples/mistake_for_bound.om @@ -0,0 +1,9 @@ +note mistake_for_bound: for takes no bound; its count is the limit. Use while COND bound N for a bounded variable loop +fn main to int +n = ulong 5 +s = ulong 0 +for i ulong n bound 10 +s = add s i +end +ret int s +end diff --git a/examples/mistake_free.expect b/examples/mistake_free.expect new file mode 100644 index 0000000..8036a92 --- /dev/null +++ b/examples/mistake_free.expect @@ -0,0 +1,2 @@ +compile 9 +stderr omc: line 3: error 9 diff --git a/examples/mistake_free.om b/examples/mistake_free.om new file mode 100644 index 0000000..2ce42be --- /dev/null +++ b/examples/mistake_free.om @@ -0,0 +1,5 @@ +note mistake_free: there is no heap and no free; arrays are new in the outermost block or global +fn main to int +free = int 1 +ret 0 +end diff --git a/examples/mistake_infix.expect b/examples/mistake_infix.expect new file mode 100644 index 0000000..8fccef0 --- /dev/null +++ b/examples/mistake_infix.expect @@ -0,0 +1,2 @@ +compile 5 +stderr omc: line 4: error 5 diff --git a/examples/mistake_infix.om b/examples/mistake_infix.om new file mode 100644 index 0000000..9b093cc --- /dev/null +++ b/examples/mistake_infix.om @@ -0,0 +1,6 @@ +note mistake_infix: there are no infix operators; write the prefix word. Fix: y = add x 1 +fn main to int +x = int 1 +y = x + 1 +ret y +end diff --git a/examples/mistake_main_args.expect b/examples/mistake_main_args.expect new file mode 100644 index 0000000..0659d98 --- /dev/null +++ b/examples/mistake_main_args.expect @@ -0,0 +1,2 @@ +compile 9 +stderr omc: line 5: error 9 diff --git a/examples/mistake_main_args.om b/examples/mistake_main_args.om new file mode 100644 index 0000000..21c52e4 --- /dev/null +++ b/examples/mistake_main_args.om @@ -0,0 +1,4 @@ +note mistake_main_args: main takes no parameters; read arguments with argcnt and argread +fn main argc int to int +ret 0 +end diff --git a/examples/mistake_neg_name.expect b/examples/mistake_neg_name.expect new file mode 100644 index 0000000..12737e7 --- /dev/null +++ b/examples/mistake_neg_name.expect @@ -0,0 +1,2 @@ +compile 16 +stderr omc: line 3: error 16 diff --git a/examples/mistake_neg_name.om b/examples/mistake_neg_name.om new file mode 100644 index 0000000..2a0134c --- /dev/null +++ b/examples/mistake_neg_name.om @@ -0,0 +1,5 @@ +note mistake_neg_name: neg is the negation word, so it cannot name a value or a text. Fix: pick another name, for example negv +fn main to int +neg = int 1 +ret 0 +end diff --git a/examples/mistake_new_var_len.expect b/examples/mistake_new_var_len.expect new file mode 100644 index 0000000..b42a41a --- /dev/null +++ b/examples/mistake_new_var_len.expect @@ -0,0 +1,2 @@ +compile 16 +stderr omc: line 4: error 16 diff --git a/examples/mistake_new_var_len.om b/examples/mistake_new_var_len.om new file mode 100644 index 0000000..4e67cd4 --- /dev/null +++ b/examples/mistake_new_var_len.om @@ -0,0 +1,6 @@ +note mistake_new_var_len: a new length is a literal or an integer const, never a variable; there are no run-time-sized arrays +fn main to int +n = ulong 4 +a = new uchar n 0 +ret 0 +end diff --git a/examples/mistake_om1_rotr.expect b/examples/mistake_om1_rotr.expect new file mode 100644 index 0000000..b2e04dd --- /dev/null +++ b/examples/mistake_om1_rotr.expect @@ -0,0 +1,2 @@ +compile 3 +stderr omc: line 4: error 3 diff --git a/examples/mistake_om1_rotr.om b/examples/mistake_om1_rotr.om new file mode 100644 index 0000000..17b0b94 --- /dev/null +++ b/examples/mistake_om1_rotr.om @@ -0,0 +1,5 @@ +note mistake_om1_rotr: rotr and hex need the om2 line; without it rotr is an unknown name +fn main to int +x = uint 1 +ret int rotr x 1 +end diff --git a/examples/mistake_om2_int_hex.expect b/examples/mistake_om2_int_hex.expect new file mode 100644 index 0000000..05803dc --- /dev/null +++ b/examples/mistake_om2_int_hex.expect @@ -0,0 +1,2 @@ +compile 8 +stderr omc: line 4: error 8 diff --git a/examples/mistake_om2_int_hex.om b/examples/mistake_om2_int_hex.om new file mode 100644 index 0000000..1332bb5 --- /dev/null +++ b/examples/mistake_om2_int_hex.om @@ -0,0 +1,6 @@ +note mistake_om2_int_hex: a hex literal must fit its type as a value; 0xffffffff is not an int. Fix: int -1 +om2 +fn main to int +x = int 0xffffffff +ret 0 +end diff --git a/examples/mistake_om2_param_slots.expect b/examples/mistake_om2_param_slots.expect new file mode 100644 index 0000000..8036a92 --- /dev/null +++ b/examples/mistake_om2_param_slots.expect @@ -0,0 +1,2 @@ +compile 9 +stderr omc: line 3: error 9 diff --git a/examples/mistake_om2_param_slots.om b/examples/mistake_om2_param_slots.om new file mode 100644 index 0000000..6a1bf56 --- /dev/null +++ b/examples/mistake_om2_param_slots.om @@ -0,0 +1,9 @@ +note mistake_om2_param_slots: 2 unsized views plus 3 scalars need 7 slots; the limit is 6. Fix: a sized view, a struct, or fewer scalars +om2 +fn f a view uchar * b view uchar * x int y int z int to int +ret add add x y z +end +fn main to int +a = new uchar 4 0 +ret f a a 1 2 3 +end diff --git a/examples/mistake_om2_part_global.expect b/examples/mistake_om2_part_global.expect new file mode 100644 index 0000000..073894b --- /dev/null +++ b/examples/mistake_om2_part_global.expect @@ -0,0 +1,2 @@ +compile 19 +stderr omc: line 8: error 19 diff --git a/examples/mistake_om2_part_global.om b/examples/mistake_om2_part_global.om new file mode 100644 index 0000000..12d3d4f --- /dev/null +++ b/examples/mistake_om2_part_global.om @@ -0,0 +1,9 @@ +note mistake_om2_part_global: part of a global is refused like any global argument; slice a local array +om2 +global g uchar 8 +fn f a view uchar * to ulong +ret len a +end +fn main to int +ret int f part g 0 2 +end diff --git a/examples/mistake_om2_part_sized.expect b/examples/mistake_om2_part_sized.expect new file mode 100644 index 0000000..718e9ad --- /dev/null +++ b/examples/mistake_om2_part_sized.expect @@ -0,0 +1,2 @@ +compile 7 +stderr omc: line 8: error 7 diff --git a/examples/mistake_om2_part_sized.om b/examples/mistake_om2_part_sized.om new file mode 100644 index 0000000..0380acf --- /dev/null +++ b/examples/mistake_om2_part_sized.om @@ -0,0 +1,9 @@ +note mistake_om2_part_sized: part goes only to an unsized view T * parameter, not a sized one +om2 +fn f a view uchar 2 to ulong +ret len a +end +fn main to int +b = new uchar 8 0 +ret int f part b 0 2 +end diff --git a/examples/mistake_om2_part_statement.expect b/examples/mistake_om2_part_statement.expect new file mode 100644 index 0000000..0659d98 --- /dev/null +++ b/examples/mistake_om2_part_statement.expect @@ -0,0 +1,2 @@ +compile 9 +stderr omc: line 5: error 9 diff --git a/examples/mistake_om2_part_statement.om b/examples/mistake_om2_part_statement.om new file mode 100644 index 0000000..e37ab7b --- /dev/null +++ b/examples/mistake_om2_part_statement.om @@ -0,0 +1,7 @@ +note mistake_om2_part_statement: part A off n is only an argument to an unsized view parameter, never a value of its own +om2 +fn main to int +a = new uint 4 0 +p = part a 0 2 +ret 0 +end diff --git a/examples/mistake_om2_upper_hex.expect b/examples/mistake_om2_upper_hex.expect new file mode 100644 index 0000000..8f1f3f3 --- /dev/null +++ b/examples/mistake_om2_upper_hex.expect @@ -0,0 +1,2 @@ +compile 6 +stderr omc: line 4: error 6 diff --git a/examples/mistake_om2_upper_hex.om b/examples/mistake_om2_upper_hex.om new file mode 100644 index 0000000..341a86c --- /dev/null +++ b/examples/mistake_om2_upper_hex.om @@ -0,0 +1,6 @@ +note mistake_om2_upper_hex: OM-2 hex digits are lowercase after a lowercase 0x +om2 +fn main to int +x = uint 0X10 +ret 0 +end diff --git a/examples/mistake_param_length.expect b/examples/mistake_param_length.expect new file mode 100644 index 0000000..9287464 --- /dev/null +++ b/examples/mistake_param_length.expect @@ -0,0 +1,2 @@ +compile 7 +stderr omc: line 7: error 7 diff --git a/examples/mistake_param_length.om b/examples/mistake_param_length.om new file mode 100644 index 0000000..253a945 --- /dev/null +++ b/examples/mistake_param_length.om @@ -0,0 +1,8 @@ +note mistake_param_length: a sized array parameter takes exactly that length; use OM-2 view T * for any length +fn f a view uchar 4 to uchar +ret get a 0 +end +fn main to int +b = new uchar 8 0 +ret int f b +end diff --git a/examples/mistake_reserved_name.expect b/examples/mistake_reserved_name.expect new file mode 100644 index 0000000..12737e7 --- /dev/null +++ b/examples/mistake_reserved_name.expect @@ -0,0 +1,2 @@ +compile 16 +stderr omc: line 3: error 16 diff --git a/examples/mistake_reserved_name.om b/examples/mistake_reserved_name.om new file mode 100644 index 0000000..cbcc7bd --- /dev/null +++ b/examples/mistake_reserved_name.om @@ -0,0 +1,5 @@ +note mistake_reserved_name: len, text, read, write, stat and every host word are reserved; pick another name +fn main to int +len = int 1 +ret 0 +end diff --git a/examples/mistake_return.expect b/examples/mistake_return.expect new file mode 100644 index 0000000..904856b --- /dev/null +++ b/examples/mistake_return.expect @@ -0,0 +1,2 @@ +compile 18 +stderr omc: line 6: error 18 diff --git a/examples/mistake_return.om b/examples/mistake_return.om new file mode 100644 index 0000000..6b95ac0 --- /dev/null +++ b/examples/mistake_return.om @@ -0,0 +1,5 @@ +note mistake_return: the word is ret. The = of an assignment is optional, so return x silently assigns x to a new name return; here the function then has no ret, error 18 +fn main to int +x = int 1 +return x +end diff --git a/examples/mistake_semicolon.expect b/examples/mistake_semicolon.expect new file mode 100644 index 0000000..9c38e39 --- /dev/null +++ b/examples/mistake_semicolon.expect @@ -0,0 +1,2 @@ +compile 6 +stderr omc: line 3: error 6 diff --git a/examples/mistake_semicolon.om b/examples/mistake_semicolon.om new file mode 100644 index 0000000..9f121f5 --- /dev/null +++ b/examples/mistake_semicolon.om @@ -0,0 +1,5 @@ +note mistake_semicolon: one statement per line and no semicolons; the ; makes the number malformed +fn main to int +x = int 1; +ret 0 +end diff --git a/examples/mistake_seven_params.expect b/examples/mistake_seven_params.expect new file mode 100644 index 0000000..86e5f4a --- /dev/null +++ b/examples/mistake_seven_params.expect @@ -0,0 +1,2 @@ +compile 9 +stderr omc: line 2: error 9 diff --git a/examples/mistake_seven_params.om b/examples/mistake_seven_params.om new file mode 100644 index 0000000..af8f62a --- /dev/null +++ b/examples/mistake_seven_params.om @@ -0,0 +1,7 @@ +note mistake_seven_params: at most 6 parameters; pass a struct or an array for more +fn f a int b int c int d int e int g int h int to int +ret a +end +fn main to int +ret 0 +end diff --git a/examples/mistake_short_circuit.expect b/examples/mistake_short_circuit.expect new file mode 100644 index 0000000..63a88c0 --- /dev/null +++ b/examples/mistake_short_circuit.expect @@ -0,0 +1,2 @@ +compile 0 +exit 103 diff --git a/examples/mistake_short_circuit.om b/examples/mistake_short_circuit.om new file mode 100644 index 0000000..621ddc9 --- /dev/null +++ b/examples/mistake_short_circuit.om @@ -0,0 +1,10 @@ +note mistake_short_circuit: and/or evaluate both sides, so this still loads a[4] and traps 3 (exit 103) +note fix: test the bound in an outer if, then load inside it +fn main to int +a = new uchar 4 0 +i = ulong 4 +if and lt i len a eq get a i 0 +ret 1 +end +ret 0 +end diff --git a/examples/mistake_short_circuit.stdout b/examples/mistake_short_circuit.stdout new file mode 100644 index 0000000..e69de29 diff --git a/examples/mistake_slash_comment.expect b/examples/mistake_slash_comment.expect new file mode 100644 index 0000000..520abe4 --- /dev/null +++ b/examples/mistake_slash_comment.expect @@ -0,0 +1,2 @@ +compile 16 +stderr omc: line 2: error 16 diff --git a/examples/mistake_slash_comment.om b/examples/mistake_slash_comment.om new file mode 100644 index 0000000..dda8c3f --- /dev/null +++ b/examples/mistake_slash_comment.om @@ -0,0 +1,5 @@ +note mistake_slash_comment: note is the only comment form; // and # are unknown words +// a comment +fn main to int +ret 0 +end diff --git a/examples/mistake_struct_after_fn.expect b/examples/mistake_struct_after_fn.expect new file mode 100644 index 0000000..0659d98 --- /dev/null +++ b/examples/mistake_struct_after_fn.expect @@ -0,0 +1,2 @@ +compile 9 +stderr omc: line 5: error 9 diff --git a/examples/mistake_struct_after_fn.om b/examples/mistake_struct_after_fn.om new file mode 100644 index 0000000..c7d8052 --- /dev/null +++ b/examples/mistake_struct_after_fn.om @@ -0,0 +1,5 @@ +note mistake_struct_after_fn: a struct line comes before the first fn +fn main to int +ret 0 +end +struct P a uint end diff --git a/examples/mistake_trap_range.expect b/examples/mistake_trap_range.expect new file mode 100644 index 0000000..30adc60 --- /dev/null +++ b/examples/mistake_trap_range.expect @@ -0,0 +1,2 @@ +compile 8 +stderr omc: line 3: error 8 diff --git a/examples/mistake_trap_range.om b/examples/mistake_trap_range.om new file mode 100644 index 0000000..66074a5 --- /dev/null +++ b/examples/mistake_trap_range.om @@ -0,0 +1,4 @@ +note mistake_trap_range: trap takes 1..14; codes 9 and 10 are what contracts use, and the runtime owns 1..7 +fn main to int +trap 15 +end diff --git a/examples/mistake_value_stmt.expect b/examples/mistake_value_stmt.expect new file mode 100644 index 0000000..944c37d --- /dev/null +++ b/examples/mistake_value_stmt.expect @@ -0,0 +1,2 @@ +compile 7 +stderr omc: line 6: error 7 diff --git a/examples/mistake_value_stmt.om b/examples/mistake_value_stmt.om new file mode 100644 index 0000000..7634417 --- /dev/null +++ b/examples/mistake_value_stmt.om @@ -0,0 +1,8 @@ +note mistake_value_stmt: a function with a result cannot be a statement; bind its result. Fix: v = f +fn f to int +ret 1 +end +fn main to int +f +ret 0 +end diff --git a/examples/om2_hex_rotr.expect b/examples/om2_hex_rotr.expect new file mode 100644 index 0000000..420e65e --- /dev/null +++ b/examples/om2_hex_rotr.expect @@ -0,0 +1,2 @@ +compile 0 +exit 0 diff --git a/examples/om2_hex_rotr.om b/examples/om2_hex_rotr.om new file mode 100644 index 0000000..426fc3e --- /dev/null +++ b/examples/om2_hex_rotr.om @@ -0,0 +1,40 @@ +note om2_hex_rotr: the first line that is not blank or a note opts in to OM-2: hex literals and rotr +om2 +note ---- OM-2 output helpers: an unsized view parameter takes an array or text of any length +note outv: write all of a to stdout; a short write continues, 0 or an error exits 90 +fn outv a view uchar * to void +e = len a +p = ulong 0 +while lt p e bound 65536 +k = write 1 a p sub e p +if le k 0 +exit 90 +end +p = add p ulong k +end +end +note putu: v in decimal, then a newline +note a part of a global is error 19, so the digits go in a local array +fn putu v ulong to void +b = new uchar 21 0 +i = ulong 20 +put b 20 10 +n = v +while true bound 20 +i = sub i 1 +put b i uchar add rem n 10 48 +n = div n 10 +if eq n 0 +break +end +end +outv part b i sub 21 i +end +fn main to int +x = uint 0xdeadbeef +putu ulong x +putu ulong rotr x 8 +putu 0xffffffffffffffff +putu ulong and x 0xff +ret 0 +end diff --git a/examples/om2_hex_rotr.stdout b/examples/om2_hex_rotr.stdout new file mode 100644 index 0000000..5e043d7 --- /dev/null +++ b/examples/om2_hex_rotr.stdout @@ -0,0 +1,4 @@ +3735928559 +4024348094 +18446744073709551615 +239 diff --git a/examples/om2_param_slots.expect b/examples/om2_param_slots.expect new file mode 100644 index 0000000..420e65e --- /dev/null +++ b/examples/om2_param_slots.expect @@ -0,0 +1,2 @@ +compile 0 +exit 0 diff --git a/examples/om2_param_slots.om b/examples/om2_param_slots.om new file mode 100644 index 0000000..03fcd00 --- /dev/null +++ b/examples/om2_param_slots.om @@ -0,0 +1,24 @@ +note om2_param_slots: six parameter slots; an unsized view T * or edit T * takes two (pointer, count), every other parameter one +note here 2 unsized views (4 slots) plus 2 scalars fill all six; a sized view uchar 4 would take one slot +om2 +fn f a view uchar * b view uchar * x int y int to int +ret int add add len a len b ulong add x y +end +fn g a view uchar 4 b view uchar 4 c view uchar 4 x int y int z int to int +ret add add x y z +end +fn main to int +a = new uchar 4 0 +b = new uchar 3 0 +c = new uchar 4 0 +d = new uchar 4 0 +r = f a b 1 2 +if ne r 10 +ret 1 +end +s = g a c d 1 2 3 +if ne s 6 +ret 2 +end +ret 0 +end diff --git a/examples/om2_part_trap.expect b/examples/om2_part_trap.expect new file mode 100644 index 0000000..63a88c0 --- /dev/null +++ b/examples/om2_part_trap.expect @@ -0,0 +1,2 @@ +compile 0 +exit 103 diff --git a/examples/om2_part_trap.om b/examples/om2_part_trap.om new file mode 100644 index 0000000..3168893 --- /dev/null +++ b/examples/om2_part_trap.om @@ -0,0 +1,17 @@ +note om2_part_trap: part A off n checks off + n <= len A when it runs; past the end traps 3, exit 103 +om2 +text before "before\n" +fn sum a view uint * to ulong +s = ulong 0 +for i ulong len a +s = add s ulong get a i +end +ret s +end +fn main to int +k = write 1 before 0 len before +a = new uint 4 1 +o = ulong 3 +t = sum part a o 2 +ret 0 +end diff --git a/examples/om2_part_trap.stdout b/examples/om2_part_trap.stdout new file mode 100644 index 0000000..90be1f3 --- /dev/null +++ b/examples/om2_part_trap.stdout @@ -0,0 +1 @@ +before diff --git a/examples/om2_tour.expect b/examples/om2_tour.expect new file mode 100644 index 0000000..420e65e --- /dev/null +++ b/examples/om2_tour.expect @@ -0,0 +1,2 @@ +compile 0 +exit 0 diff --git a/examples/om2_tour.om b/examples/om2_tour.om new file mode 100644 index 0000000..c1594db --- /dev/null +++ b/examples/om2_tour.om @@ -0,0 +1,43 @@ +note om2_tour: layout, abstract/holds/seal/open, fresh, unroll (after omega-mv examples/om2-tour.om) +om2 +layout blk 8 +field lo uint at 0 little +field hi uint at 4 big +end +abstract v32 ulong +holds v32 dup32 +note the erasing constructor: the body is exactly this line +fn v32mk x uint to v32 +ret seal v32 or shl ulong x 32 ulong x +end +note fresh: every element is written before it is read (error 27 otherwise) +fn seed s edit uint 8 fresh to uint +for i uint 8 unroll +put s i mul i 3 +end +ret get s 7 +end +fn stamp c edit blk to void +put c lo 0x01020304 +put c hi 0x05060708 +end +fn main to int +s = new uint 8 0 +v = seed s +if ne v 21 +ret 1 +end +c = new uchar 8 0 +stamp c +if ne get c 0 0x04 +ret 2 +end +if ne get c 4 0x05 +ret 3 +end +u = open v32mk 7 +if ne u 0x0000000700000007 +ret 4 +end +ret 0 +end diff --git a/examples/om2_tour.stdout b/examples/om2_tour.stdout new file mode 100644 index 0000000..e69de29 diff --git a/examples/om2_views.expect b/examples/om2_views.expect new file mode 100644 index 0000000..420e65e --- /dev/null +++ b/examples/om2_views.expect @@ -0,0 +1,2 @@ +compile 0 +exit 0 diff --git a/examples/om2_views.om b/examples/om2_views.om new file mode 100644 index 0000000..472100c --- /dev/null +++ b/examples/om2_views.om @@ -0,0 +1,53 @@ +note om2_views: view T * is an unsized read-only parameter; part A off n passes a checked slice +om2 +note ---- OM-2 output helpers: an unsized view parameter takes an array or text of any length +note outv: write all of a to stdout; a short write continues, 0 or an error exits 90 +fn outv a view uchar * to void +e = len a +p = ulong 0 +while lt p e bound 65536 +k = write 1 a p sub e p +if le k 0 +exit 90 +end +p = add p ulong k +end +end +note putu: v in decimal, then a newline +note a part of a global is error 19, so the digits go in a local array +fn putu v ulong to void +b = new uchar 21 0 +i = ulong 20 +put b 20 10 +n = v +while true bound 20 +i = sub i 1 +put b i uchar add rem n 10 48 +n = div n 10 +if eq n 0 +break +end +end +outv part b i sub 21 i +end +text greet "views and slices\n" +fn sum a view uint * to ulong +s = ulong 0 +for i ulong len a +s = add s ulong get a i +end +ret s +end +fn main to int +outv greet +a = new uint 6 0 +for i ulong 6 +put a i uint add i 1 +end +putu sum a +putu sum part a 1 3 +putu sum part a 5 1 +outv part greet 0 6 +outv part greet 16 1 +ret 0 +end diff --git a/examples/om2_views.stdout b/examples/om2_views.stdout new file mode 100644 index 0000000..0edc9c2 --- /dev/null +++ b/examples/om2_views.stdout @@ -0,0 +1,5 @@ +views and slices +21 +9 +6 +views diff --git a/examples/print_decimal.expect b/examples/print_decimal.expect new file mode 100644 index 0000000..420e65e --- /dev/null +++ b/examples/print_decimal.expect @@ -0,0 +1,2 @@ +compile 0 +exit 0 diff --git a/examples/print_decimal.om b/examples/print_decimal.om new file mode 100644 index 0000000..82fb1f7 --- /dev/null +++ b/examples/print_decimal.om @@ -0,0 +1,50 @@ +note print_decimal: the output helpers every other example copies +note ---- output helpers: a function works on a global by naming it (a global is never an argument) +global ob uchar 32 +note outb: write ob[off .. off+n) to stdout; a short write continues, 0 or an error exits 90 +note bound: every pass writes at least one byte and n <= 32, so at most 32 passes +fn outb off ulong n ulong to void +e = add off n +p = off +while lt p e bound 32 +k = write 1 ob p sub e p +if le k 0 +exit 90 +end +p = add p ulong k +end +end +note putu: v in decimal, then a newline. A ulong has at most 20 digits, so 20 passes +fn putu v ulong to void +i = ulong 31 +put ob 31 10 +n = v +while true bound 20 +i = sub i 1 +put ob i uchar add rem n 10 48 +n = div n 10 +if eq n 0 +break +end +end +outb i sub 32 i +end +note putl: a signed value; -(v+1)+1 avoids negating the minimum, which would trap 1 +fn putl v long to void +if lt v 0 +put ob 0 45 +outb 0 1 +putu add ulong neg add v 1 1 +ret +end +putu ulong v +end +fn main to int +putu 0 +putu 42 +putu 18446744073709551615 +putl 9223372036854775807 +putl -9223372036854775808 +putl -1 +ret 0 +end diff --git a/examples/print_decimal.stdout b/examples/print_decimal.stdout new file mode 100644 index 0000000..02ec18c --- /dev/null +++ b/examples/print_decimal.stdout @@ -0,0 +1,6 @@ +0 +42 +18446744073709551615 +9223372036854775807 +-9223372036854775808 +-1 diff --git a/examples/stdin_count.expect b/examples/stdin_count.expect new file mode 100644 index 0000000..420e65e --- /dev/null +++ b/examples/stdin_count.expect @@ -0,0 +1,2 @@ +compile 0 +exit 0 diff --git a/examples/stdin_count.om b/examples/stdin_count.om new file mode 100644 index 0000000..314508b --- /dev/null +++ b/examples/stdin_count.om @@ -0,0 +1,71 @@ +note stdin_count: read stdin to its end in 7-byte reads, counting bytes and lines +note read may return fewer bytes than asked, 0 at the end, or minus the errno: handle all three +note ---- output helpers: a function works on a global by naming it (a global is never an argument) +global ob uchar 32 +note outb: write ob[off .. off+n) to stdout; a short write continues, 0 or an error exits 90 +note bound: every pass writes at least one byte and n <= 32, so at most 32 passes +fn outb off ulong n ulong to void +e = add off n +p = off +while lt p e bound 32 +k = write 1 ob p sub e p +if le k 0 +exit 90 +end +p = add p ulong k +end +end +note putu: v in decimal, then a newline. A ulong has at most 20 digits, so 20 passes +fn putu v ulong to void +i = ulong 31 +put ob 31 10 +n = v +while true bound 20 +i = sub i 1 +put ob i uchar add rem n 10 48 +n = div n 10 +if eq n 0 +break +end +end +outb i sub 32 i +end +note putl: a signed value; -(v+1)+1 avoids negating the minimum, which would trap 1 +fn putl v long to void +if lt v 0 +put ob 0 45 +outb 0 1 +putu add ulong neg add v 1 1 +ret +end +putu ulong v +end +global buf uchar 7 +fn main to int +bytes = ulong 0 +lines = ulong 0 +sum = ulong 0 +note bound: every pass but the last reads at least one byte; this program accepts at most 65536 bytes +while true bound 65537 +k = read 0 buf 0 7 +if lt k 0 +exit 91 +end +if eq k 0 +break +end +n = ulong k +for i ulong n +c = get buf i +sum = add sum ulong c +if eq c 10 +lines = add lines 1 +end +end +bytes = add bytes n +end +putu bytes +putu lines +putu sum +ret 0 +end diff --git a/examples/stdin_count.stdin b/examples/stdin_count.stdin new file mode 100644 index 0000000..fc835fa --- /dev/null +++ b/examples/stdin_count.stdin @@ -0,0 +1,5 @@ +alpha +beta +gamma delta + +end \ No newline at end of file diff --git a/examples/stdin_count.stdout b/examples/stdin_count.stdout new file mode 100644 index 0000000..5370da5 --- /dev/null +++ b/examples/stdin_count.stdout @@ -0,0 +1,3 @@ +27 +4 +2350 diff --git a/examples/structs.expect b/examples/structs.expect new file mode 100644 index 0000000..420e65e --- /dev/null +++ b/examples/structs.expect @@ -0,0 +1,2 @@ +compile 0 +exit 0 diff --git a/examples/structs.om b/examples/structs.om new file mode 100644 index 0000000..75e9301 --- /dev/null +++ b/examples/structs.om @@ -0,0 +1,59 @@ +note structs: 8-byte cells in order, no padding; a struct is never a wire layout +note a struct line comes before the first fn +struct Pair a uint b long end +note ---- output helpers: a function works on a global by naming it (a global is never an argument) +global ob uchar 32 +note outb: write ob[off .. off+n) to stdout; a short write continues, 0 or an error exits 90 +note bound: every pass writes at least one byte and n <= 32, so at most 32 passes +fn outb off ulong n ulong to void +e = add off n +p = off +while lt p e bound 32 +k = write 1 ob p sub e p +if le k 0 +exit 90 +end +p = add p ulong k +end +end +note putu: v in decimal, then a newline. A ulong has at most 20 digits, so 20 passes +fn putu v ulong to void +i = ulong 31 +put ob 31 10 +n = v +while true bound 20 +i = sub i 1 +put ob i uchar add rem n 10 48 +n = div n 10 +if eq n 0 +break +end +end +outb i sub 32 i +end +note putl: a signed value; -(v+1)+1 avoids negating the minimum, which would trap 1 +fn putl v long to void +if lt v 0 +put ob 0 45 +outb 0 1 +putu add ulong neg add v 1 1 +ret +end +putu ulong v +end +note swapsum: an edit parameter may be written; a view parameter may not (error 20) +fn swapsum p edit Pair to long +t = long get p a +put p a uint 7 +ret add t get p b +end +fn main to int +p = new Pair 5 -12 +v = swapsum p +putl v +putu ulong get p a +putu sizeof Pair +putu offsetof Pair b +putu sizeof uint +ret 0 +end diff --git a/examples/structs.stdout b/examples/structs.stdout new file mode 100644 index 0000000..46eda6e --- /dev/null +++ b/examples/structs.stdout @@ -0,0 +1,5 @@ +-7 +7 +16 +8 +4 diff --git a/examples/text.expect b/examples/text.expect new file mode 100644 index 0000000..420e65e --- /dev/null +++ b/examples/text.expect @@ -0,0 +1,2 @@ +compile 0 +exit 0 diff --git a/examples/text.om b/examples/text.om new file mode 100644 index 0000000..0842ed1 --- /dev/null +++ b/examples/text.om @@ -0,0 +1,48 @@ +note text: escapes are only backslash n, t, backslash and quote; len of a text is its byte count +note ---- output helpers: a function works on a global by naming it (a global is never an argument) +global ob uchar 32 +note outb: write ob[off .. off+n) to stdout; a short write continues, 0 or an error exits 90 +note bound: every pass writes at least one byte and n <= 32, so at most 32 passes +fn outb off ulong n ulong to void +e = add off n +p = off +while lt p e bound 32 +k = write 1 ob p sub e p +if le k 0 +exit 90 +end +p = add p ulong k +end +end +note putu: v in decimal, then a newline. A ulong has at most 20 digits, so 20 passes +fn putu v ulong to void +i = ulong 31 +put ob 31 10 +n = v +while true bound 20 +i = sub i 1 +put ob i uchar add rem n 10 48 +n = div n 10 +if eq n 0 +break +end +end +outb i sub 32 i +end +note putl: a signed value; -(v+1)+1 avoids negating the minimum, which would trap 1 +fn putl v long to void +if lt v 0 +put ob 0 45 +outb 0 1 +putu add ulong neg add v 1 1 +ret +end +putu ulong v +end +text t "tab\there \"q\" back\\slash\n" +fn main to int +k = write 1 t 0 len t +putu len t +putu ulong get t 0 +ret 0 +end diff --git a/examples/text.stdout b/examples/text.stdout new file mode 100644 index 0000000..088371f --- /dev/null +++ b/examples/text.stdout @@ -0,0 +1,3 @@ +tab here "q" back\slash +24 +116 diff --git a/examples/tmp_files.expect b/examples/tmp_files.expect new file mode 100644 index 0000000..420e65e --- /dev/null +++ b/examples/tmp_files.expect @@ -0,0 +1,2 @@ +compile 0 +exit 0 diff --git a/examples/tmp_files.om b/examples/tmp_files.om new file mode 100644 index 0000000..96caf93 --- /dev/null +++ b/examples/tmp_files.om @@ -0,0 +1,81 @@ +note tmp_files: make a directory and a file relative to the current directory, read it back, clean up +note run it in an empty scratch directory. Linux AArch64 values: O_WRONLY|O_CREAT|O_EXCL = 193, +note mode 0600 = 384, 0700 = 448, st_size at byte 48 of the 128-byte stat structure +note ---- output helpers: a function works on a global by naming it (a global is never an argument) +global ob uchar 32 +note outb: write ob[off .. off+n) to stdout; a short write continues, 0 or an error exits 90 +note bound: every pass writes at least one byte and n <= 32, so at most 32 passes +fn outb off ulong n ulong to void +e = add off n +p = off +while lt p e bound 32 +k = write 1 ob p sub e p +if le k 0 +exit 90 +end +p = add p ulong k +end +end +note putu: v in decimal, then a newline. A ulong has at most 20 digits, so 20 passes +fn putu v ulong to void +i = ulong 31 +put ob 31 10 +n = v +while true bound 20 +i = sub i 1 +put ob i uchar add rem n 10 48 +n = div n 10 +if eq n 0 +break +end +end +outb i sub 32 i +end +note putl: a signed value; -(v+1)+1 avoids negating the minimum, which would trap 1 +fn putl v long to void +if lt v 0 +put ob 0 45 +outb 0 1 +putu add ulong neg add v 1 1 +ret +end +putu ulong v +end +text dname "scratch" +text fname "scratch/f.txt" +text body "omega\n" +global rb uchar 16 +global sb uchar 128 +fn main to int +r = makedir dname 0 len dname 448 +putl r +fd = fopen fname 0 len fname 193 384 +if lt fd 0 +exit 93 +end +w = write int fd body 0 len body +putl w +c = fclose int fd +putl c +fd2 = fopen fname 0 len fname 0 0 +if lt fd2 0 +exit 94 +end +k = read int fd2 rb 0 16 +putl k +c2 = fclose int fd2 +s = stat fname 0 len fname sb 0 128 +putl s +sz = or uint get sb 48 shl uint get sb 49 8 +putu ulong sz +if gt k 0 +x = write 1 rb 0 ulong k +end +u = unlink fname 0 len fname +putl u +d = rmdir dname 0 len dname +putl d +gone = fopen fname 0 len fname 0 0 +putl gone +ret 0 +end diff --git a/examples/tmp_files.stdout b/examples/tmp_files.stdout new file mode 100644 index 0000000..4231fd8 --- /dev/null +++ b/examples/tmp_files.stdout @@ -0,0 +1,10 @@ +0 +6 +0 +6 +0 +6 +omega +0 +0 +-2 diff --git a/examples/trap1_overflow.expect b/examples/trap1_overflow.expect new file mode 100644 index 0000000..429946a --- /dev/null +++ b/examples/trap1_overflow.expect @@ -0,0 +1,2 @@ +compile 0 +exit 101 diff --git a/examples/trap1_overflow.om b/examples/trap1_overflow.om new file mode 100644 index 0000000..ce836b3 --- /dev/null +++ b/examples/trap1_overflow.om @@ -0,0 +1,8 @@ +note trap1_overflow: signed add past the maximum traps 1, exit 101; stdout written before stays +text before "before\n" +fn main to int +k = write 1 before 0 len before +x = long 9223372036854775807 +y = add x 1 +ret 0 +end diff --git a/examples/trap1_overflow.stdout b/examples/trap1_overflow.stdout new file mode 100644 index 0000000..90be1f3 --- /dev/null +++ b/examples/trap1_overflow.stdout @@ -0,0 +1 @@ +before diff --git a/examples/trap2_div0.expect b/examples/trap2_div0.expect new file mode 100644 index 0000000..0aa587b --- /dev/null +++ b/examples/trap2_div0.expect @@ -0,0 +1,2 @@ +compile 0 +exit 102 diff --git a/examples/trap2_div0.om b/examples/trap2_div0.om new file mode 100644 index 0000000..0efaba9 --- /dev/null +++ b/examples/trap2_div0.om @@ -0,0 +1,8 @@ +note trap2_div0: integer div or rem by zero traps 2, exit 102 +text before "before\n" +fn main to int +k = write 1 before 0 len before +d = uint 0 +q = div uint 10 d +ret 0 +end diff --git a/examples/trap2_div0.stdout b/examples/trap2_div0.stdout new file mode 100644 index 0000000..90be1f3 --- /dev/null +++ b/examples/trap2_div0.stdout @@ -0,0 +1 @@ +before diff --git a/examples/trap3_bounds.expect b/examples/trap3_bounds.expect new file mode 100644 index 0000000..63a88c0 --- /dev/null +++ b/examples/trap3_bounds.expect @@ -0,0 +1,2 @@ +compile 0 +exit 103 diff --git a/examples/trap3_bounds.om b/examples/trap3_bounds.om new file mode 100644 index 0000000..891f919 --- /dev/null +++ b/examples/trap3_bounds.om @@ -0,0 +1,9 @@ +note trap3_bounds: a run-time index outside the array traps 3, exit 103 +text before "before\n" +fn main to int +k = write 1 before 0 len before +a = new uint 4 0 +i = ulong 4 +v = get a i +ret 0 +end diff --git a/examples/trap3_bounds.stdout b/examples/trap3_bounds.stdout new file mode 100644 index 0000000..90be1f3 --- /dev/null +++ b/examples/trap3_bounds.stdout @@ -0,0 +1 @@ +before diff --git a/examples/trap4_loop.expect b/examples/trap4_loop.expect new file mode 100644 index 0000000..21ea6db --- /dev/null +++ b/examples/trap4_loop.expect @@ -0,0 +1,2 @@ +compile 0 +exit 104 diff --git a/examples/trap4_loop.om b/examples/trap4_loop.om new file mode 100644 index 0000000..e77a3f0 --- /dev/null +++ b/examples/trap4_loop.om @@ -0,0 +1,10 @@ +note trap4_loop: one pass more than the bound traps 4, exit 104 +text before "before\n" +fn main to int +k = write 1 before 0 len before +i = ulong 0 +while lt i 10 bound 5 +i = add i 1 +end +ret 0 +end diff --git a/examples/trap4_loop.stdout b/examples/trap4_loop.stdout new file mode 100644 index 0000000..90be1f3 --- /dev/null +++ b/examples/trap4_loop.stdout @@ -0,0 +1 @@ +before diff --git a/examples/trap5_conv.expect b/examples/trap5_conv.expect new file mode 100644 index 0000000..db1b967 --- /dev/null +++ b/examples/trap5_conv.expect @@ -0,0 +1,2 @@ +compile 0 +exit 105 diff --git a/examples/trap5_conv.om b/examples/trap5_conv.om new file mode 100644 index 0000000..52021b1 --- /dev/null +++ b/examples/trap5_conv.om @@ -0,0 +1,8 @@ +note trap5_conv: a conversion whose value does not fit traps 5, exit 105 +text before "before\n" +fn main to int +k = write 1 before 0 len before +x = uint 300 +c = uchar x +ret 0 +end diff --git a/examples/trap5_conv.stdout b/examples/trap5_conv.stdout new file mode 100644 index 0000000..90be1f3 --- /dev/null +++ b/examples/trap5_conv.stdout @@ -0,0 +1 @@ +before diff --git a/examples/trap6_stack.expect b/examples/trap6_stack.expect new file mode 100644 index 0000000..2fee246 --- /dev/null +++ b/examples/trap6_stack.expect @@ -0,0 +1,2 @@ +compile 0 +exit 106 diff --git a/examples/trap6_stack.om b/examples/trap6_stack.om new file mode 100644 index 0000000..139cdb4 --- /dev/null +++ b/examples/trap6_stack.om @@ -0,0 +1,13 @@ +note trap6_stack: recursion below the 8 MiB stack traps 6, exit 106 +text before "before\n" +fn deep n ulong to ulong +if eq n 0 +ret 0 +end +ret add 1 deep sub n 1 +end +fn main to int +k = write 1 before 0 len before +x = deep 100000000 +ret 0 +end diff --git a/examples/trap6_stack.stdout b/examples/trap6_stack.stdout new file mode 100644 index 0000000..90be1f3 --- /dev/null +++ b/examples/trap6_stack.stdout @@ -0,0 +1 @@ +before diff --git a/examples/trap7_shift.expect b/examples/trap7_shift.expect new file mode 100644 index 0000000..4692b41 --- /dev/null +++ b/examples/trap7_shift.expect @@ -0,0 +1,2 @@ +compile 0 +exit 107 diff --git a/examples/trap7_shift.om b/examples/trap7_shift.om new file mode 100644 index 0000000..a6c5506 --- /dev/null +++ b/examples/trap7_shift.om @@ -0,0 +1,8 @@ +note trap7_shift: a shift amount outside 0..width-1 traps 7, exit 107 +text before "before\n" +fn main to int +k = write 1 before 0 len before +s = uint 32 +x = shl uint 1 s +ret 0 +end diff --git a/examples/trap7_shift.stdout b/examples/trap7_shift.stdout new file mode 100644 index 0000000..90be1f3 --- /dev/null +++ b/examples/trap7_shift.stdout @@ -0,0 +1 @@ +before diff --git a/examples/trap_code.expect b/examples/trap_code.expect new file mode 100644 index 0000000..c360087 --- /dev/null +++ b/examples/trap_code.expect @@ -0,0 +1,2 @@ +compile 0 +exit 114 diff --git a/examples/trap_code.om b/examples/trap_code.om new file mode 100644 index 0000000..92f1b00 --- /dev/null +++ b/examples/trap_code.om @@ -0,0 +1,6 @@ +note trap_code: trap N for N in 1..14 exits 100+N; use it for your own fatal codes +text before "before\n" +fn main to int +k = write 1 before 0 len before +trap 14 +end diff --git a/examples/trap_code.stdout b/examples/trap_code.stdout new file mode 100644 index 0000000..90be1f3 --- /dev/null +++ b/examples/trap_code.stdout @@ -0,0 +1 @@ +before diff --git a/examples/unsigned_wrap.expect b/examples/unsigned_wrap.expect new file mode 100644 index 0000000..420e65e --- /dev/null +++ b/examples/unsigned_wrap.expect @@ -0,0 +1,2 @@ +compile 0 +exit 0 diff --git a/examples/unsigned_wrap.om b/examples/unsigned_wrap.om new file mode 100644 index 0000000..15e0e32 --- /dev/null +++ b/examples/unsigned_wrap.om @@ -0,0 +1,56 @@ +note unsigned_wrap: unsigned add sub mul shl neg not wrap mod 2^width; comparisons follow the type +note ---- output helpers: a function works on a global by naming it (a global is never an argument) +global ob uchar 32 +note outb: write ob[off .. off+n) to stdout; a short write continues, 0 or an error exits 90 +note bound: every pass writes at least one byte and n <= 32, so at most 32 passes +fn outb off ulong n ulong to void +e = add off n +p = off +while lt p e bound 32 +k = write 1 ob p sub e p +if le k 0 +exit 90 +end +p = add p ulong k +end +end +note putu: v in decimal, then a newline. A ulong has at most 20 digits, so 20 passes +fn putu v ulong to void +i = ulong 31 +put ob 31 10 +n = v +while true bound 20 +i = sub i 1 +put ob i uchar add rem n 10 48 +n = div n 10 +if eq n 0 +break +end +end +outb i sub 32 i +end +note putl: a signed value; -(v+1)+1 avoids negating the minimum, which would trap 1 +fn putl v long to void +if lt v 0 +put ob 0 45 +outb 0 1 +putu add ulong neg add v 1 1 +ret +end +putu ulong v +end +fn main to int +m = uint 4294967295 +putu ulong add m 1 +putu ulong sub uint 0 1 +putu ulong mul uint 65536 65536 +putu ulong neg uint 1 +putu ulong not uint 0 +putu ulong shl uint 1 31 +big = ulong 18446744073709551615 +if lt big 1 +ret 1 +end +putu add big 1 +ret 0 +end diff --git a/examples/unsigned_wrap.stdout b/examples/unsigned_wrap.stdout new file mode 100644 index 0000000..8bef3e4 --- /dev/null +++ b/examples/unsigned_wrap.stdout @@ -0,0 +1,7 @@ +0 +4294967295 +0 +4294967295 +4294967295 +2147483648 +0 diff --git a/examples/wire_le.expect b/examples/wire_le.expect new file mode 100644 index 0000000..420e65e --- /dev/null +++ b/examples/wire_le.expect @@ -0,0 +1,2 @@ +compile 0 +exit 0 diff --git a/examples/wire_le.om b/examples/wire_le.om new file mode 100644 index 0000000..39e3380 --- /dev/null +++ b/examples/wire_le.om @@ -0,0 +1,68 @@ +note wire_le: there is no byte-layout type; encode and decode integers with shifts and masks +note ---- output helpers: a function works on a global by naming it (a global is never an argument) +global ob uchar 32 +note outb: write ob[off .. off+n) to stdout; a short write continues, 0 or an error exits 90 +note bound: every pass writes at least one byte and n <= 32, so at most 32 passes +fn outb off ulong n ulong to void +e = add off n +p = off +while lt p e bound 32 +k = write 1 ob p sub e p +if le k 0 +exit 90 +end +p = add p ulong k +end +end +note putu: v in decimal, then a newline. A ulong has at most 20 digits, so 20 passes +fn putu v ulong to void +i = ulong 31 +put ob 31 10 +n = v +while true bound 20 +i = sub i 1 +put ob i uchar add rem n 10 48 +n = div n 10 +if eq n 0 +break +end +end +outb i sub 32 i +end +note putl: a signed value; -(v+1)+1 avoids negating the minimum, which would trap 1 +fn putl v long to void +if lt v 0 +put ob 0 45 +outb 0 1 +putu add ulong neg add v 1 1 +ret +end +putu ulong v +end +fn main to int +b = new uchar 4 0 +h = uint 305419896 +put b 0 uchar and h 255 +put b 1 uchar and shr h 8 255 +put b 2 uchar and shr h 16 255 +put b 3 uchar and shr h 24 255 +for i ulong 4 +putu ulong get b i +end +v = or uint get b 0 shl uint get b 1 8 +v = or v shl uint get b 2 16 +v = or v shl uint get b 3 24 +putu ulong v +note a signed 32-bit decode without integer bitcast (see omega-encoding section 5) +s = long v +put b 3 255 +u = or uint get b 0 shl uint get b 1 8 +u = or u shl uint get b 2 16 +u = or u shl uint get b 3 24 +s = long u +if ge u 2147483648 +s = sub s 4294967296 +end +putl s +ret 0 +end diff --git a/examples/wire_le.stdout b/examples/wire_le.stdout new file mode 100644 index 0000000..fe41b0e --- /dev/null +++ b/examples/wire_le.stdout @@ -0,0 +1,6 @@ +120 +86 +52 +18 +305419896 +-13347208 diff --git a/skills/omega-encoding/SKILL.md b/skills/omega-encoding/SKILL.md index 0050843..d0e48bc 100644 --- a/skills/omega-encoding/SKILL.md +++ b/skills/omega-encoding/SKILL.md @@ -148,6 +148,131 @@ correctness proof or a full gate5/host qualification. Every citation links to that commit: `https://github.com/aien-dev/omega-mv/blob/55f9b0af47de70a3d06357985cf99ae3e45c016f/#L`. +### Rerun at omega-mv `91c83438` (2026-10-31) + +The example gate now pins main `91c83438daec0bdb88bf5c077cae10f3d15d365d` (#965), `seed/out/omc` +sha256 `2aec185d4ed6d7a6a5779ed656b4e56904742bde5551b02893fb5f73916ad8d5`. On 2026-10-31, Linux +AArch64, `examples/gate.sh` against that binary printed `GATE PASS examples=98 pass=98 fail=0` +(exit 0) with no expectation changed. The rerun also showed that code 25 is emitted (it has been +since the x86 integration `bf54b19f`): `target foo` as the first line is `omc: line 1: error 25` +under both `2aec185d` and the pre-#965 `7a8b84fc`. `examples/err25_target.om` now records it, and +the gate printed `GATE PASS examples=99 pass=99 fail=0` (exit 0); with its first line changed to +`target x86linux` (a known target) that example fails (`compile exit 0, expected 25`). Negative +controls on a scratch copy of the 99-program tree each ended `GATE FAIL examples=99 pass=98 fail=1` +with exit 1: `const N ulong 16` changed to 15 in `examples/consts.om` (stdout `15` instead of +`16`), and one byte appended to `consts.stdout`. The gate pointed at the pre-#965 omc `7a8b84fc…` +was refused with exit 2. The 2026-10-29 section below is the previous pin. + +### Rerun at omega-mv `bf54b19f` (2026-10-29) + +The example gate now pins this compiler. On 2026-10-29, Linux AArch64, `examples/gate.sh` against +`seed/out/omc` sha256 `62775d2a391cfef7cde64e387655caa9809a267093112910ec76bfa568f3712b` printed +`GATE PASS examples=98 pass=98 fail=0` after the keyword-prefix expectation was updated. The same +gate pinned to `2c824805…029f` had passed 98/98 with the old expectation. A copy of the new gate +pointed at `2c824805` was refused (exit 2). + +| Item | Value | +|---|---| +| Commit | `bf54b19fa590e8ae925c0e80815516dbf41e7326` (2026-10-28, merge of PR #923) | +| `seed/omc/omc.om` | 15,624 lines, sha256 `96d51b63c8f451661ac715395078e04f39195e50c9e8fe37746cda121e4d7a1e` | +| `seed/out/omc` | sha256 `62775d2a391cfef7cde64e387655caa9809a267093112910ec76bfa568f3712b` | +| `seed/rung0/seed0.hex` | sha256 `baaf081fe6055a768485c5d25d7435681ce00b04cfa80b26c48169f78944e14d` (unchanged) | +| `docs/one_layer/OMEGESE.md` | blob `90fa5d0c32757da6e7c271e96406b75105ba8008` | + +Two defects recorded at `e5b32567` are fixed in this compiler (the #904 integration, `e2662fff`): +`fn continue_x` compiles and the program exits 7 (`examples/defect_keyword_prefix.om`); `bitcast int` +of `uint 4294967295` compares equal to -1 and `add` 2 returns 1, and `bitcast uint` of `int -1` +compares equal to 4294967295. At `2c824805` those three programs were error 16, exit 2 and exit 2, +and `add` 2 trapped 1. `fn continue` is still error 16. The #775 empty-text report was not +reproduced: a two-text unit passing `text e ""` to `view uchar *` returned len 0 on both compilers. +Keep the `part e 0 0` workaround until that report has an exact failing program. Other +"observed at e5b32567" lines below are dated history; the example suite still matches them. + +### Historical rerun at omega-mv `e5b32567` (2026-10-27) + +Every example and rule in this file that a program can show was rerun on 2026-10-27 with the +compiler below, on a Linux AArch64 host only. The 2026-10-29 section above is current where it +disagrees with this list. + +| Item | Value | +|---|---| +| Commit | `e5b32567a7aff3ce594e3254a622a846a6cd190b` (2026-10-26, merge of PR #868) | +| `seed/omc/omc.om` | 12,040 lines, sha256 `7703da00055fc0c7a91fcae43071df76a3f277dbe867cb284a3bdff3bedb7e1b` | +| `seed/out/omc` | sha256 `2c82480596bbdc50cda9626866209ef662d5834f278f839ff4ce0250c495029f` | +| `seed/rung0/seed0.hex` | sha256 `baaf081fe6055a768485c5d25d7435681ce00b04cfa80b26c48169f78944e14d` (unchanged) | +| `docs/one_layer/OMEGESE.md` | blob `119c559557e4f227dee348c0e0e1240c71a42df3` | + +The executable record is [`examples/gate.sh`](../../examples/gate.sh): it refuses any other compiler +hash, then compiles and runs 98 programs (`examples/*.om` and this skill's `examples/*.om`) against +exact expected stdout bytes, exit statuses and compiler stderr lines. Observed: +`GATE PASS examples=98 pass=98 fail=0`. Negative controls on a copy each ended `GATE FAIL` with +exit 1: one changed digit in an expected stdout, an expected exit 105 changed to 104, an expected +stderr line number changed, a removed `.expect` file, and a changed program body; a compiler with one +appended byte was refused with exit 2. Arithmetic expectations were checked with Wolfram +(`examples/WOLFRAM.md`). + +Changes and confirmations against the rules below, each observed with a program: + +- **Hex literals are OM-2 only.** In an OM-1 unit `uint 0x10` is error 6. After an `om2` line it is + 16; `0X10` (uppercase prefix) is error 6, and the value must fit the type: `int 0xffffffff` is + error 8 (`examples/om2_hex_rotr.om`, `mistake_om2_upper_hex.om`, `mistake_om2_int_hex.om`). +- **`+` is refused.** `y = x + 1` is error 5 and a value starting with `+` is error 3 + (`mistake_infix.om`). OMEGESE 9.9's "`+ - * /`" is still wrong at this pin. +- **Float to integer truncates toward zero and saturates; it never traps.** `long 1.0e30f64` is + 9223372036854775807, `long -1.0e30f64` is -9223372036854775808, `long -5.75f64` is -5, + `uint -5.5f64` is 0, `uchar 300.0f64` is 255, and a NaN converts to 0 (`float_to_int.om`). Integer + to integer conversion stays checked (trap 5). +- **The `=` of an assignment is optional** (OMEGESE line 24), so `return x` compiles as an assignment + to a new name `return`. In a value function the missing `ret` then shows as error 18 + (`mistake_return.om`). +- **`for` takes no `bound`**: `for i ulong n bound 10` is error 5 (`mistake_for_bound.om`). `while` + bounds are 1..999999 (`bound 1000000` is error 8) and `trap` takes 1..14 (`trap 15` and `trap 0` + are error 8; `trap 14` exits 114). +- **Names:** an 8-character variable compiles and 9 is error 13; a 63-character function name + compiles and 64 is error 13. `len` or `stat` as a variable is error 16, `free` is error 9, and + `bits` is an ordinary name. +- **Placement:** a `struct` line after the first `fn` is error 9; `new` inside a block is error 9; a + variable `new` length is error 16; `main` with a parameter is error 9. A `const` in function mode + compiles. +- **Parameter slots, not parameter count.** Parameters fill x0..x5: an OM-2 unsized `view T *` / + `edit T *` takes two slots (pointer, count), every other parameter one, a sized array included + (OMEGESE 9.13 "Parameter slots"). Observed: 3 sized views plus 3 scalars compile and run; 2 unsized + views plus 2 scalars compile; 2 unsized views plus 3 scalars, or 7 scalars, are error 9 on the `fn` + line (`examples/om2_param_slots.om`, `mistake_om2_param_slots.om`, `mistake_seven_params.om`). +- **Function names of 9..63 bytes are not keywords by their first 8 bytes** (fixed in the #904 + integration, measured 2026-10-29 at omc `62775d2a`). `continue_x` compiles and returns 7 + (`examples/defect_keyword_prefix.om`). At omc `2c824805` the same file was error 16. An exact + keyword name (`fn continue`) is still error 16. +- **OM-2 slices:** `part A off n` is only an argument to an unsized `view T *` parameter. As a value + of its own it is error 9, to a sized parameter error 7, of a global error 19; `off + n` past the end + traps 3 at run time (`om2_views.om`, `om2_part_trap.om`). +- **Errors 1 and 2 reproduce:** a directory as the compiler's stdin gives exit 1, + `omc: line 0: error 1`; stdout on `/dev/full` gives exit 2 with the line after the last input line + (`omc: line 5: error 2` for a 4-line unit). A 33rd `export fn` in an OM-2 unit is error 14; exports + are function mode, so an `export` beside `fn main` is error 9. +- **Error 24 was not reproduced.** 40 functions of 4,000 checked `add` lines each compiled and ran, + because trap branches stay short; the check (`disp19`, omc.om line 2465) is defensive. Codes 25 and + 26 are not emitted by any `fail` call at this pin. +- **Narrow `bitcast`:** at omc `2c824805`, `bitcast int` of `uint 4294967295` was not -1 and `add` 2 + trapped 1, and `bitcast uint` of `int -1` was not 4294967295. At omc `62775d2a` those two cases + are correct (exit 1 and exit 1; `add` 2 returns 1). `ushort`/`short`, `uchar`/`byte` and `f32` to + `int` were not retested on 2026-10-29. Do not assume they are fixed. Decode signed values + arithmetically when you have not measured the pair (`examples/wire_le.om`). +- **`byte` is signed 8-bit** (`i8`, OMEGESE line 109); `char` is not a type (error 3). +- **Empty text through `view uchar *` (omega-mv #775).** A 2026-10-27 report said `len` was 60 with + one other text and 28 with none. A two-text unit on 2026-10-29 returned 0 on both `2c824805` and + `62775d2a`, so that report was not reproduced. Keep passing `part e 0 0` + (`examples/empty_text_part.om`) until an exact failing program exists. +- **Skill examples rerun:** `fnv1a32.om` compile exit 0, empty stderr; `abc`, `a`, empty and 65535 + zero bytes gave `0be9471a`, `2c290ce4`, `c59d1c81`, `47dac371`, each exit 0; 65536 zero bytes gave + exit 2 and no output; the prime changed to `16777617` gave `55bedcf5` for `abc`. + `trap_narrow.om` compiled with exit 0 and ran with exit 105, and 44 without the unmasked store. The + section 13 inline refusal gave exit 7, `omc: line 3: error 7`. +- **Section 11a contract fixtures rerun** from `seed/omc/contracts/`: `ok.om` exit 0, `requires.om` + exit 109, `release.om` exit 0 and byte-identical to `erased.om`; `diagproof.om` stderr + `omc-check 1 erased line=3 rule=constant-true kind=requires`, `diagrelease.om` stderr + `omc-check 1 erased line=3 rule=release kind=requires`, each compile exit 0. + ### Merged IR/wasm backend (2026-10-26) Source: omega-mv main `3364a1dfd0ca50c1b82bf19ba34932d8bc10a7a9`, @@ -552,7 +677,8 @@ Evaluation is innermost first, left to right ([#L137-L141](https://github.com/ai There are no infix operators. `+ - * /` are not keywords (they are absent from the keyword table); OMEGESE 9.9 ([#L564](https://github.com/aien-dev/omega-mv/blob/55f9b0af47de70a3d06357985cf99ae3e45c016f/docs/one_layer/OMEGESE.md#L564)) writes "`+ - * /`" but its own -float fixtures use `add sub mul div` (`seed/omc/tests/float/arith.om`). Write the words. +float fixtures use `add sub mul div` (`seed/omc/tests/float/arith.om`). Write the words. Observed at +`e5b32567`: `y = x + 1` is error 5 (`examples/mistake_infix.om`). `and` / `or` evaluate **both** sides; there is no short circuit ([#L104](https://github.com/aien-dev/omega-mv/blob/55f9b0af47de70a3d06357985cf99ae3e45c016f/docs/one_layer/OMEGESE.md#L104)). `and lt i len a eq get a i 0` still loads `a[i]` when `i` is out of range and traps 3. Test the @@ -573,10 +699,12 @@ bound in an outer `if`, then load inside it. - Integer literals: decimal only, optional leading `-`, at most 20 digits, and the value must fit the type it takes (error 8), e.g. `long` -2^63..2^63-1, `ulong` 0..2^64-1. A non-digit (`12a`, `0x10`) is error 6 ([#L443-L446](https://github.com/aien-dev/omega-mv/blob/55f9b0af47de70a3d06357985cf99ae3e45c016f/docs/one_layer/OMEGESE.md#L443-L446)). In an OM-1 unit: no hex, no octal, - no character literals: write byte 65, not `'A'`. An `om2` unit accepts hex (`x = uint 0x10` compiled - and the program exited 16; the same line without `om2` is error 6; omc `befb8199...a1d`, 2026-10-26; - same results 2026-10-31 with main omc `62775d2a…712b` at omega-mv `4376c2112`; see also **Hex** in - section 8). + no character literals: write byte 65, not `'A'` (error 3). OM-2 units (first non-`note` line `om2`) + also take lowercase hex, `0xdeadbeef`, which must still fit its type (`int 0xffffffff` is error 8, + `0X10` is error 6; observed at `e5b32567`; full rule in the next item). An `om2` unit with + `x = uint 0x10` compiled and the program exited 16; the same line without `om2` is error 6 (omc + `befb8199...a1d`, 2026-10-26; same results 2026-10-31 with main omc `62775d2a…712b` at omega-mv + `4376c2112`; see also **Hex** in section 8). `true` / `false` are the bools. - Hex literals, OM-2 units only (`om2` first non-note line; `spec/omegese-om2.md` section 2): `0x` then 1..16 lowercase digits `0-9a-f`, value unsigned, typed by the place under the decimal range rule @@ -639,8 +767,13 @@ Conversions are **checked**, not truncating. `uchar x` with x = 300 traps 5. Mas `bitcast T v` reinterprets bits of the same width; `bool` and different widths are error 7, a bare number is error 11 ([omc.om#L4640-L4662](https://github.com/aien-dev/omega-mv/blob/55f9b0af47de70a3d06357985cf99ae3e45c016f/seed/omc/omc.om#L4640-L4662)). Every fixture uses it between floats and unsigned integers. The code also accepts integer-to-integer of equal -width (`bitcast int u`), but no fixture covers that; prove it with your own fixture before relying on -it, or decode signed values arithmetically (section 8). +width. At omc `2c824805` results across signedness below 64 bits were wrong (section 0). At omc +`62775d2a` the two measured 32-bit pairs are correct; narrower pairs and `f32` to `int` were not +retested. Do not bitcast an unmeasured pair; decode signed values arithmetically (section 10). + +Float to integer conversion is the exception to "checked": it truncates toward zero and saturates at +the target's limits, and a NaN gives 0, with no trap (observed at `e5b32567`, +`examples/float_to_int.om`). ## 6. Names, scope, registers @@ -699,7 +832,7 @@ From OMEGESE section 3 and 4 ([#L58-L60](https://github.com/aien-dev/omega-mv/bl - `while COND bound N`: at most N body passes, N 1..999999 (error 8 outside). Without `bound` the limit is 1000000 passes. One more pass traps 4. The condition is recomputed before every pass. - `for i T K` runs i = 0..K-1. A literal K needs no hidden guard; a name or expression K gets the - 1000000-pass guard. + 1000000-pass guard. `for` takes no `bound` word (error 5, observed at `e5b32567`). - `break` and `continue` (`omc` only, gate7); `continue` in a `while` re-runs the condition and bound. - Choose N from a proof, not a guess. Example: a read loop where every pass adds at least one byte to a 65536-byte buffer needs at most 65536 passes. Write that reasoning in a `note`. @@ -874,7 +1007,7 @@ separate namespace in the same registry (OMEGESE section 11.1). The message form | Code | Meaning | Code | Meaning | |---|---|---|---| -| 1, 2 | compiler I/O | 13 | non-function name over 8 characters | +| 1, 2 | compiler input / output (stdin a directory: 1; stdout `/dev/full`: 2; both observed) | 13 | non-function name over 8 characters | | 3 | unknown name or field | 14 | capacity at `91b3c932`: 8192 names, 4096 functions, 512 nested blocks, 1024 nesting depth, 8 MiB input/output | | 4 | line ends too early | 15 | missing `end` | | 5 | extra words on the line | 16 | syntax / unknown word | @@ -923,6 +1056,12 @@ omc `2c824805`). AUTHOR-CLAIMED, not rechecked: `global` inside a function-mode omega-bridge `431fff0a` `native c` exits 110 when an entry's array length is written as a `const` name (write the literal in the entry signature). +One minimal refusal per code is in `examples/errNN_*.om` of this repository, with its exact stderr +line in `errNN_*.expect`, and `examples/gate.sh` runs them: codes 1..23 and 27..30, observed at +`e5b32567`, plus code 25 (`err25_target`, added 2026-10-31 at `91c83438`). Code 24 has no +reproduction (section 0), and 25 and 26 were unused at `e5b32567`; since `bf54b19f` the target +checks emit 25 (section 0, rerun at `91c83438`). + ## 11a. Executable contracts (merged #807 through #768) Source: OMEGESE section 12 and `seed/omc/contracts/` at main @@ -1073,6 +1212,11 @@ check proves nothing. wrap), writes 4 little-endian bytes with a partial-write loop, distinct exit codes for each failure. - `examples/trap_narrow.om`: a masked narrowing succeeds, an unmasked one traps 5 (exit 105). +Both carry `.expect` (and for `fnv1a32`, `.stdin` `abc` and the 4 expected bytes in `.stdout`) and +run in [`examples/gate.sh`](../../examples/gate.sh) with the 97 programs in the repository's +`examples/` directory; section 0 records the `e5b32567` rerun of every row below. The portable guide +for writing a first program is [`skills/writing-omega/SKILL.md`](../writing-omega/SKILL.md). + Observed on 2026-10-25, Linux AArch64 host only, compiler sha256 `734f0a39...6b61`: | Check | Observed | diff --git a/skills/omega-encoding/examples/fnv1a32.expect b/skills/omega-encoding/examples/fnv1a32.expect new file mode 100644 index 0000000..420e65e --- /dev/null +++ b/skills/omega-encoding/examples/fnv1a32.expect @@ -0,0 +1,2 @@ +compile 0 +exit 0 diff --git a/skills/omega-encoding/examples/fnv1a32.stdin b/skills/omega-encoding/examples/fnv1a32.stdin new file mode 100644 index 0000000..f2ba8f8 --- /dev/null +++ b/skills/omega-encoding/examples/fnv1a32.stdin @@ -0,0 +1 @@ +abc \ No newline at end of file diff --git a/skills/omega-encoding/examples/fnv1a32.stdout b/skills/omega-encoding/examples/fnv1a32.stdout new file mode 100644 index 0000000..191a701 --- /dev/null +++ b/skills/omega-encoding/examples/fnv1a32.stdout @@ -0,0 +1 @@ + éG \ No newline at end of file diff --git a/skills/omega-encoding/examples/trap_narrow.expect b/skills/omega-encoding/examples/trap_narrow.expect new file mode 100644 index 0000000..db1b967 --- /dev/null +++ b/skills/omega-encoding/examples/trap_narrow.expect @@ -0,0 +1,2 @@ +compile 0 +exit 105 diff --git a/skills/omega-harness/SKILL.md b/skills/omega-harness/SKILL.md index 4f98954..c9c7ef3 100644 --- a/skills/omega-harness/SKILL.md +++ b/skills/omega-harness/SKILL.md @@ -16,6 +16,8 @@ These skills are operating guidance for coding agents. They are not a compiler a Companion skills in this package: - `omega-encoding`: the language the seeded compiler actually accepts, with verified examples. +- `writing-omega`: the portable guide for writing a first correct `.om` program, backed by the tested + programs in `examples/` and `examples/gate.sh`. - `omega-communication`: status labels, reports, handoffs and corrections. - `aien-repositories`: what AIEN builds and which repository owns a task. @@ -508,7 +510,7 @@ Before you finish, check whether your change touched any of these, and update th | You changed | Update | |---|---| -| Omega syntax, keywords, types, traps, limits, error codes, host or device words, the compiler or its pin | `omega-encoding`, plus the pins in `omega-harness` | +| Omega syntax, keywords, types, traps, limits, error codes, host or device words, the compiler or its pin | `omega-encoding` and `writing-omega`, plus the pins in `omega-harness`; add or update the program in `examples/` and rerun `examples/gate.sh` | | Build, compile, gate or verification commands, or the seed procedure | `omega-harness` sections 3 and 4 | | Conversion, encoder or bridge behavior, or what it supports | the conversion note in `omega-harness` section 2, and the README | | Status vocabulary, receipts, report or handoff conventions, wire formats | `omega-communication` | diff --git a/skills/writing-omega/SKILL.md b/skills/writing-omega/SKILL.md new file mode 100644 index 0000000..4433c75 --- /dev/null +++ b/skills/writing-omega/SKILL.md @@ -0,0 +1,411 @@ +--- +name: writing-omega +description: 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. +--- + +# Writing Omega programs + +This guide is for any agent or person writing `.om` on any machine. It needs only a clone of +[aien-dev/omega-mv](https://github.com/aien-dev/omega-mv) and of this repository. Every rule +below was observed with a program at the pin in the table; the programs are in +[`examples/`](../../examples/) and [`examples/gate.sh`](../../examples/gate.sh) reruns all of them. +For compiler internals, register rules, wire formats and the reasons behind each rule, read +[`skills/omega-encoding/SKILL.md`](../omega-encoding/SKILL.md). + +| Pin | Value | +|---|---| +| omega-mv commit | `91c83438daec0bdb88bf5c077cae10f3d15d365d` | +| compiler `seed/out/omc` | sha256 `2aec185d4ed6d7a6a5779ed656b4e56904742bde5551b02893fb5f73916ad8d5` | +| language reference | `docs/one_layer/OMEGESE.md` at that commit | +| host | Linux AArch64 only; omc writes a static AArch64 Linux ELF | + +The language reference is normative. Where this guide and OMEGESE disagree, the compiler at the pin +decides; this guide records the known disagreements. + +## 1. Compile and run + +```sh +git clone https://github.com/aien-dev/omega-mv && cd omega-mv +git checkout 91c83438daec0bdb88bf5c077cae10f3d15d365d +sha256sum seed/out/omc # must print the pinned hash +sh seed/omega-from-seed.sh # optional: rebuild omc from the 408-byte loader +seed/out/omc < prog.om > prog; echo "compile $?" +chmod +x prog && ./prog; echo "exit $?" +``` + +- omc reads the unit on stdin and writes the executable on stdout. Exit 0 means accepted. Any other + exit is the error number, and stderr has one line `omc: line N: error K`. +- **Never run the output of a refused compile**: stdout may still hold bytes. +- A unit with `fn main` is program mode (an executable). A unit without it is function mode (raw + machine words for a host to call); never execute function-mode output directly. +- Check behavior, not compile success: compare stdout bytes and the exit status with what you + expected, and run one deliberately wrong variant to see the check fail. +- To check a whole set the way this repository does: + `examples/gate.sh path/to/seed/out/omc` prints `PASS name` or `FAIL name: reason` per program and + ends `GATE PASS examples=N ...` or `GATE FAIL ...` (exit 1); a different compiler hash exits 2. + +## 2. Program shape + +``` +note hello: the smallest complete program +text msg "hello, world\n" +fn main to int +k = write 1 msg 0 len msg +if ne k long len msg +ret 1 +end +ret 0 +end +``` + +([`examples/hello.om`](../../examples/hello.om)). The rules it shows: + +- **One statement per line.** No semicolons, no braces. Blocks (`fn`, `if`, `else`, `while`, `for`, + `struct`) close with `end`. Indentation is optional. +- **Prefix words only.** Every operation is a word followed by its values: `add x 1`, + `mul add a b c`, `lt i n`. Each word has a fixed number of values. Parentheses may group a value + and add nothing: `(add a b)`. +- **Comments are `note` lines.** `//` and `#` are refused (error 16). +- **`fn NAME p1 T1 p2 T2 ... to R`**, result `R` a type or `void`. Parameters fill **6 slots**: an + OM-2 unsized `view T *` / `edit T *` takes 2 (pointer and count), every other parameter 1 (a + scalar, a sized array, a struct). Two unsized views plus three scalars is error 9 + ([`examples/om2_param_slots.om`](../../examples/om2_param_slots.om), + `mistake_om2_param_slots.om`). `fn main to int` takes no parameters and its `ret` value is the exit + status (0..255). +- **Assignment is `name = value`.** The first assignment creates the name with the value's type. The + `=` is optional, which is a trap: `return x` is accepted as "assign x to a new name `return`". +- A function may call a function defined later in the unit, and program-mode functions may recurse. +- Top-level lines are `note`, `fn`, `text`, `global`, `const`, `struct`, and in OM-2 units + `layout`, `abstract`, `holds` and `export fn`. `struct` and `layout` lines come before the first + `fn` (error 9 after it). A `const` is visible only after its line. + +Every declaration and statement form at the pin (OMEGESE sections 9 to 12 are the full rules): + +| Form | Where | Notes | +|---|---|---| +| `note ANY TEXT` | any line | a comment line | +| `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 | +| `om2 fmt` | the first line, at byte 0 | prints the canonical text of the rest of the input instead of compiling it | +| `text NAME "bytes"` | top level | a read-only `uchar` array | +| `global NAME T N` | top level, program mode | zero-filled array, never an argument | +| `const NAME T LITERAL` | top level | an integer or float value, visible after its line | +| `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 | +| `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 | +| `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` | +| `fn NAME p1 T1 ... to R` ... `end` | top level | `inline` after R in OM-2; `export fn` marks an OM-2 function-mode entry | +| parameter `p T` | `fn` line | a scalar | +| parameter `a view T N` / `a edit T N` | `fn` line | a sized array, read-only or writable | +| parameter `a view T *` / `a edit T *` | `fn` line, OM-2 | an array of any length | +| parameter `s edit T N fresh` | `fn` line, OM-2 | scratch: every element written before it is read | +| parameter `p view S` / `p edit S` | `fn` line | a struct, or an OM-2 layout | +| parameter `o out T N` | `fn` line, OM-2 | written by the unit; the calling host copies it out after status 0 | +| `name = value` | function body | the first assignment creates the name | +| `put A i v`, `put p f v` | function body | store into an array element or a field | +| `f v1 v2 ...` | function body | a call to a `void` function | +| `if C` ... `else` ... `end` | function body | `else` is optional; no `else if` | +| `while C bound N` ... `end` | function body | N 1..999999 | +| `for i T K` ... `end` | function body | `unroll` after K in OM-2, K 1..64 | +| `break`, `continue` | inside a loop | | +| `ret`, `ret v` | function body | `ret v` in a function with a result | +| `exit N`, `trap N` | function body | exit status N; trap N 1..14 exits 100+N | +| `requires C`, `ensures C` | OM-2, the first lines of a function | `result` names the returned value | +| `invariant C` | OM-2, the first line of a loop body | | + +## 3. Types and values + +| Type | Meaning | +|---|---| +| `bool` | `true` / `false`, the result of comparisons | +| `uchar`, `ushort`, `uint`, `ulong` | unsigned 8, 16, 32, 64 bit (also spelled `u8 u16 u32 u64`) | +| `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) | +| `f32`, `f64` | IEEE binary32, binary64 | +| `void` | no result (function result only) | + +- **No implicit conversion.** Both values of an operation have one type (error 7). Convert with the + type word: `long x`, `uint b`, `f64 n`. +- **A bare number takes its type from context**: the other value of its operation, the parameter it + is passed to, the result type at `ret`. With no context it is error 11: write `x = uint 5`, never + `x = 5` for a new name. +- Integer literals are decimal with an optional leading `-`. A literal that does not fit its type + is error 8. No character literals: write `uchar 65`, not `'A'` (error 3). +- Float literals need digits on both sides of the dot: `2.0f64`, `1.0e30f64`, `0.5f32`. The suffix is + optional where context gives the type. +- **Hex only in OM-2** (section 9): lowercase `0x` and lowercase digits, value must fit + (`int 0xffffffff` is error 8; write `int -1`). +- `sizeof T`, `sizeof S` and `offsetof S f` are compile-time `ulong` constants. + +## 4. Words + +| Kind | Words | +|---|---| +| arithmetic | `add sub mul div rem neg` | +| bits | `and or xor not shl shr` (`rotr rotl` in OM-2) | +| compare (give `bool`) | `eq ne lt le gt ge` | +| float | `add sub mul div neg`, `fsqrt fabs fmin fmax` | +| arrays | `new`, `get A i`, `put A i v`, `len A` | +| structs | `new S v1 v2 ...`, `get p f`, `put p f v` | +| control | `if` / `else` / `end`, `while COND bound N`, `for i T K`, `break`, `continue`, `ret`, `exit`, `trap N` | +| conversion | the type words, `bitcast T v` | +| 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 | + +- `and`, `or`, `xor` on integers of any width are bitwise, not logical: `and ulong 12 ulong 10` is 8 + ([`examples/int_bits_and.om`](../../examples/int_bits_and.om)). Compare first when you want a bool. +- `and` / `or` on bools evaluate **both** sides; there is no short circuit + ([`examples/mistake_short_circuit.om`](../../examples/mistake_short_circuit.om) traps 3 on the + index the C reader would expect to be skipped). Test the index in an outer `if`. +- Comparisons follow the type: on `ulong`, `lt x y` with x = 2^64-1 and y = 1 is false. +- `div` and `rem` on signed values round toward zero; `rem` takes the dividend's sign; + `shr` on a signed value keeps the sign. +- A function with a result is a value, not a statement: write `v = f 1`, never a bare `f 1` + (error 7). A `void` function is called as a statement. +- A call is the name then its values with no brackets or commas: `ret f 1 2`. + +## 5. Traps: what stops a running program + +A trap ends the process with exit status 100 + N. Output already written stays written. + +| Cause | Trap | Exit | Example | +|---|---|---|---| +| signed overflow in `add sub mul neg` | 1 | 101 | `examples/trap1_overflow.om` | +| `div` or `rem` by zero, and signed minimum divided by -1 | 2 | 102 | `trap2_divzero.om` | +| array index or I/O slice out of bounds | 3 | 103 | `trap3_bounds.om` | +| a loop past its bound | 4 | 104 | `trap4_loop.om` | +| an integer conversion whose value does not fit | 5 | 105 | `trap5_conv.om` | +| stack exhausted (8 MiB) by calls or local arrays | 6 | 106 | `trap6_stack.om` | +| shift or rotate amount outside 0..width-1 | 7 | 107 | `trap7_shift.om` | +| a contract check that fails (OM-2) | 9, 10 | 109, 110 | `contract_requires.om`, `contract_ensures.om` | +| `trap N`, N 1..14 | N | 100+N | `trap_code.om` (`trap 14`, exit 114) | + +- Unsigned arithmetic wraps modulo 2^width and never traps + ([`examples/unsigned_wrap.om`](../../examples/unsigned_wrap.om)). +- Integer conversions are checked: `uchar x` with x = 300 traps 5. Keep the low bits on purpose with + a mask: `uchar and x 255`. +- Float to integer truncates toward zero and saturates at the type's limits; NaN gives 0; it never + traps ([`examples/float_to_int.om`](../../examples/float_to_int.om)). No float operation traps: + 1/0 is infinity, 0/0 is NaN, and NaN compares false except with `ne`. +- `exit N` ends the process with status N directly, without the trap convention. + +## 6. Loops and bounds + +- `while COND bound N` runs the body at most N times, N 1..999999 (error 8 outside). Without + `bound` the limit is 1000000. One more pass traps 4. Choose N from an argument you can write down + in a `note`, for example "every pass consumes at least one byte of a 65536-byte input". +- `for i T K` runs i from 0 to K-1. `for` takes no `bound` (error 5); K is the limit. +- `break` and `continue` work in both loops. There is no `else if`: nest an `if` inside `else`. +- No loop runs forever and recursion is bounded by the stack. + +## 7. Arrays, texts, globals, structs + +- **Local array:** `a = new T N v`, N elements each v, only in a function's outermost block (error 9 + inside a block). N is a literal or an integer `const`; a variable N is error 16. There is no heap + and no `free` (error 9). +- **Global array:** `global NAME T N` at top level, zero-filled, program mode only. **A global is + never an argument** (error 19); a function uses it by naming it. +- **Text:** `text NAME "bytes"` is a read-only `uchar` array. Escapes are only `\n \t \\ \"` + (error 22 for others). +- **Array parameters** state type and exact length: `a view uchar 64` (read-only) or + `a edit uchar 64` (writable). Another length is error 7. In OM-2, `a view T *` / `a edit T *` take + any length. Writing to a view or text is error 20. +- `get A i` / `put A i v`: a literal index outside the array is error 21; every other index is checked + at run time (trap 3). There are no pointers and no address arithmetic. +- **Structs:** `struct Pair a uint b long end`, before the first `fn`. Every field is an 8-byte cell, + so a struct is never a wire or file layout. `p = new Pair 5 -12`, pass as `p edit Pair` or + `p view Pair` ([`examples/structs.om`](../../examples/structs.om)). +- **Bytes on the wire:** build them with shifts and masks into a `uchar` array + ([`examples/wire_le.om`](../../examples/wire_le.om)); OM-2 also has `layout`. + +## 8. Names and limits + +- Variable, parameter, global, text, const, struct and field names: at most 8 characters (error 13). + Function names: at most 63, but see section 13 for names that start with an 8-letter keyword. +- A new name may not repeat a visible name, a function or a struct (error 10). A name first assigned + inside a block ends at that block's `end`; assign it before the block to keep it. +- Reserved words cannot be names, including `len read write text new free view edit global note + exit const bound` and every host word (`stat`, `link`, `send`, `random`, `fork`, ...). `len` as a + name is error 16, `free` is error 9. +- 16 registers per function hold parameters, live names, loop counters and the temporaries of the + current statement. The 17th is error 12 (`examples/err12_registers.om`). The fix is structural: + move part of the work into a helper function that takes a few scalars and returns one value, end + the life of names you no longer need by computing them inside a block, and split a long nested + expression into several assignments of one or two words each. +- Size limits: an array up to 16777216 elements, 4 MiB of local arrays per function, 1 GiB of + globals (error 23). + +## 9. OM-2 units + +A unit whose first line that is not blank or `note` is exactly `om2` is an OM-2 unit. OM-1 code keeps +its meaning inside it. OM-2 adds: + +- lowercase hex literals; `rotr x n`, `rotl x n` on unsigned types (trap 7 for an amount outside + 0..width-1); +- unsized parameters `a view T *` / `a edit T *` with `len a` the run-time count; +- `part A off n`, only as an argument to an unsized parameter: the n elements of A from off, + checked at run time (trap 3). A part of a global is error 19; as a value of its own it is error 9; + to a sized parameter it is error 7; +- `for i T K unroll`, `fn ... inline`, `layout` (external byte layouts), `fresh` scratch arrays + (error 27), `abstract` types with `seal` / `open` (error 28), `export fn` (at most 32, error 14); +- executable contracts: `requires` and `ensures` lines at the start of a function, `invariant` as the + first line of a loop body. A failing `requires` traps 9 (exit 109), a failing `ensures` or + `invariant` traps 10 (exit 110). A clause may not call a function, use floats or host words + (error 30). The first line `om2 release` erases the checks + ([`examples/contract_release.om`](../../examples/contract_release.om)). + +Examples: [`om2_tour.om`](../../examples/om2_tour.om), [`om2_views.om`](../../examples/om2_views.om), +[`om2_hex_rotr.om`](../../examples/om2_hex_rotr.om), [`contracts_ok.om`](../../examples/contracts_ok.om). + +## 10. Host I/O + +- Every host word returns a `long`: a count, or minus the Linux errno. `read` may return fewer bytes + than asked, 0 at end of input, or a negative error; `write` may write fewer. Loop until done and + handle `k < 0` and `k == 0` separately + ([`examples/stdin_count.om`](../../examples/stdin_count.om)). +- Descriptors, flags and modes are `int`; offsets, counts and capacities `ulong`; buffers `uchar` + arrays. Slices are checked before the kernel call (trap 3). +- `main` takes no parameters: read arguments with `argcnt` and `argread` + ([`examples/echo_args.om`](../../examples/echo_args.om)) and the environment with `envcnt` and + `envread` ([`examples/env_read.om`](../../examples/env_read.om)). Short capacity returns -105. +- Host words carry the process's own permissions; they are not a sandbox. + +The 67 host words at the pin, with their values (OMEGESE section 10 has each one's exact contract). +`A` and `B` are `uchar` arrays, `off`, `n` and `capacity` are `ulong`, and descriptors, flags, modes +and ids are `int`. A path is the slice `A off n`; a packed list is a `u16` count, then `u16`-length +records. Each word is reserved: using it as a name is error 16 at the pin, while an unreserved name +in the same program compiles. + +| Area | Words | +|---|---| +| 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` | +| 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` | +| 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` | +| arguments, environment, randomness | `argcnt`, `argread index A off capacity`, `envcnt`, `envread index A off capacity`, `random A off n flags` | +| time | `monons`, `realns`, `sleepns interval` | +| 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` | + +## 11. Compiler errors + +Exit status = error number. The only message is the one stderr line `omc: line N: error K`, where N +is the line being read (0 when no line was read). One refusal per code is in `examples/errNN_*.om` +with its exact stderr line in the matching `.expect`, except 24, which needs a generated program. + +| Code | Meaning | Example | Fix | +|---|---|---|---| +| 1 | omc could not read its input | `err01_input` (stdin is a directory) | give omc a readable file on stdin | +| 2 | omc could not write its output | `err02_output` (stdout is `/dev/full`) | send stdout to a writable file with space | +| 3 | unknown name, field or function | `err03_unknown_name` | assign the name before use; check the spelling | +| 4 | the line ends before the statement is complete | `err04_line_ends` | give every word all of its values | +| 5 | words left after a complete statement | `err05_extra_words` | count each word's values; there is no infix | +| 6 | malformed number | `err06_bad_number` | decimal digits; hex only in OM-2, lowercase | +| 7 | type mismatch | `err07_type_mismatch` | convert with a type word: `add int 1 int u` | +| 8 | number out of range | `err08_out_of_range` | a literal that fits its type; a bound 1..999999; a trap code 1..14 | +| 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` | +| 10 | duplicate name | `err10_duplicate` | choose a name that is not visible, not a function, not a struct | +| 11 | a number with nothing to give it a type | `err11_ambiguous` | `x = uint 5` | +| 12 | register pool exhausted (16 per function) | `err12_registers` | fewer live names, a helper function, shorter expressions (section 8) | +| 13 | name too long | `err13_long_name` | at most 8 characters (function names 63) | +| 14 | compiler capacity: names, functions, exports, expansion | `err14_capacity` | split the function or the unit | +| 15 | the input ends inside an open block | `err15_missing_end` | close every block with `end` | +| 16 | syntax: unknown word or misplaced form | `err16_syntax` | start each line with a statement word; comments are `note` lines | +| 17 | a line after `ret`, `break`, `continue`, `trap` or `exit` in the same block | `err17_after_path` | delete the line or move it above | +| 18 | a function with a result whose `end` is reachable | `err18_missing_ret` | end every path with `ret v` | +| 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 | +| 20 | writing to a text or a view | `err20_readonly` | an `edit` parameter, or a local copy | +| 21 | a literal index outside the array | `err21_const_index` | an index 0..N-1 | +| 22 | a text escape other than `\n \t \\ \"` | `err22_text_escape` | build other bytes with `put` | +| 23 | array or pool size limit | `err23_size` | smaller arrays (section 8 limits) | +| 24 | a conditional branch farther than 1 MiB of code | generated, below | move long bodies into functions | +| 25 | unknown `target` name, or an AArch64-only path on another target | `err25_target` | omit `target` for AArch64, or name a target the unit fits (`target x86linux` with `fn main` compiles; `target x86efi` with the same unit is error 25) | +| 26 | never emitted at the pin | none | none | +| 27 | OM-2 `fresh` element read before it is written | `err27_fresh` | `put` every element before the `get` | +| 28 | OM-2 `seal` outside the constructor | `err28_seal` | `seal` only as the whole body of `fn NAMEmk ... to NAME` | +| 29 | OM-2 `layout` field past the size or overlapping | `err29_layout` | keep every field inside SIZE and apart | +| 30 | OM-2 contract clause not allowed | `err30_contract` | integer words on parameters only (and `result` in `ensures`); no calls, floats or host words | + +How the emitted set was established at the pin: in `seed/omc/omc.om`, `fn fail` (line 324) writes +the stderr line and exits with the code (`exit int code`, line 356). The only other exits are +`exit int 0` and `exit 0`, so every refusal goes through `fail`. Its callers pass the literals 1..25 +and 27..30, or forward a literal 3, 4, 6, 8, 13 or 16 through `lenval`, `nfail` and `unkfail`. No +caller passes 26, so that code is never emitted (the registry `seed/omc/error-codes.reg` lists it as +"no emitting site"). Code 25 comes from the target checks (`fail 25` in `fn emit` and six other +sites). A trap inside omc itself would exit +100 + N, which is not an error code. + +Error 24 needs more than 1 MiB of code inside one loop. This program, with 270000 copies of the +line `x = add x 1` (4 bytes of code each), was refused with `omc: line 270006: error 24`, the line +of the loop's `end`; with 140000 copies it compiled: + +```sh +{ printf 'fn main to int\nx = ulong 0\nc = true\nwhile c bound 1\n' + yes 'x = add x 1' | head -n 270000 + printf 'c = false\nend\nret int and x 1\nend\n'; } > e24.om +seed/out/omc < e24.om > e24; echo "compile $?" # compile 24 +``` + +## 12. Common mistakes + +Each row is a program in `examples/` with its observed refusal. + +| Mistake | Write instead | Refusal | Example | +|---|---|---|---| +| `y = x + 1` | `y = add x 1` | error 5 | `mistake_infix.om` | +| `f(1, 2)` | `f 1 2` | error 6 | `mistake_c_call.om` | +| `if x > 0` | `if gt x 0` | error 7 | `mistake_compare_operator.om` | +| `'A'` | `uchar 65` | error 3 | `mistake_char_literal.om` | +| `// comment` | `note comment` | error 16 | `mistake_slash_comment.om` | +| `x = 1;` | `x = uint 1` | error 6 | `mistake_semicolon.om` | +| `return x` | `ret x` | error 18 (silent assignment) | `mistake_return.om` | +| `else if c` | `else`, then a nested `if c` | error 5 | `mistake_else_if.om` | +| `fn main argc int to int` | `argcnt`, `argread` | error 9 | `mistake_main_args.om` | +| `for i ulong n bound 10` | `while lt i n bound 10` | error 5 | `mistake_for_bound.om` | +| `while c bound 1000000` | a bound 1..999999 | error 8 | `mistake_bound_range.om` | +| `a = new uchar n 0` | a literal or `const` length | error 16 | `mistake_new_var_len.om` | +| `free a` | nothing: no heap | error 9 | `mistake_free.om` | +| `len = ...` | another name | error 16 | `mistake_reserved_name.om` | +| `neg = ...` or `text neg "a"` | another name: `neg` is the negation word | error 16 | `mistake_neg_name.om` | +| a bare call `f 1` with a result | `v = f 1` | error 7 | `mistake_value_stmt.om` | +| a 7th parameter | a struct or an array | error 9 | `mistake_seven_params.om` | +| 2 `view T *` plus 3 scalars (7 slots) | a sized view, a struct, or fewer scalars | error 9 | `mistake_om2_param_slots.om` | +| `emit buf` with `buf` a global | name the global inside the function | error 19 | `err19_global_arg.om` | +| `a view uchar 8` given a 16-element array | the exact length, or OM-2 `view uchar *` | error 7 | `mistake_param_length.om` | +| `trap 15` | `trap 1` .. `trap 14` | error 8 | `mistake_trap_range.om` | +| `struct` after a `fn` | every `struct` before the first `fn` | error 9 | `mistake_struct_after_fn.om` | +| `rotr` or hex without `om2` | an `om2` first line | error 3 | `mistake_om1_rotr.om` | +| `0X10` or `0xFF` | `0x10`, `0xff` | error 6 | `mistake_om2_upper_hex.om` | +| `int 0xffffffff` | `int -1` | error 8 | `mistake_om2_int_hex.om` | +| `part` of a global | `part` of a local | error 19 | `mistake_om2_part_global.om` | +| `part` to a sized parameter | an unsized `view T *` parameter | error 7 | `mistake_om2_part_sized.om` | +| `s = part a 0 2` | `part` only as an argument | error 9 | `mistake_om2_part_statement.om` | +| `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` | + +## 13. Known compiler defects at the pin + +- **`bitcast` across signedness below 64 bits:** at this pin, `uint 4294967295` to `int` compares + equal to -1 and adding 2 returns 1, and `int -1` to `uint` compares equal to 4294967295. Those + two cases were wrong at omc `2c824805` (not equal; adding 2 trapped 1). `ushort`/`short`, + `uchar`/`byte` and `f32` to `int` were not retested on 2026-10-29. Do not assume they are fixed. + Decode signed values arithmetically when you have not measured the pair + ([`examples/wire_le.om`](../../examples/wire_le.om)). +- **Empty text through `view uchar *`** (omega-mv issue #775): a 2026-10-27 report said `len` was + 60 or 28, not 0. A two-text unit on 2026-10-29 returned 0 on this pin and on `2c824805`, so that + report was not reproduced. Keep passing `part e 0 0` + ([`examples/empty_text_part.om`](../../examples/empty_text_part.om)). +- **Function names:** a name of 9..63 bytes is not a keyword by its first 8 bytes. `continue_x` + compiles and returns 7 ([`examples/defect_keyword_prefix.om`](../../examples/defect_keyword_prefix.om)). + An exact keyword (`fn continue`) is still error 16. At omc `2c824805`, `continue_x` was error 16. +- OMEGESE 9.9 lists `+ - * /` for floats; the compiler refuses them. Write `add sub mul div`. + +## 14. Example index + +All in [`examples/`](../../examples/); each `NAME.om` has `NAME.expect` (compile status, exit status +or stderr line) and, when it prints, `NAME.stdout` with the exact bytes. Wolfram checks of the +arithmetic expectations are in [`examples/WOLFRAM.md`](../../examples/WOLFRAM.md). + +- Start here: `hello`, `exit_status`, `print_decimal`, `functions`, `loops`, `arrays`, `text`. +- Arithmetic: `int_arith`, `int_bits_and`, `unsigned_wrap`, `checked_conv`, `float_arith`, + `float_to_int`, `consts`. +- Data: `globals`, `structs`, `wire_le`. +- I/O: `stdin_count`, `echo_args`, `env_read`, `tmp_files`. +- Traps: `trap1_overflow` .. `trap7_shift`, `trap_code`. +- OM-2 and contracts: `om2_tour`, `om2_views`, `om2_hex_rotr`, `om2_part_trap`, `om2_param_slots`, + `contracts_ok`, `contract_requires`, `contract_ensures`, `contract_invariant`, `contract_release`. +- Regression guards: `empty_text_part`, `defect_keyword_prefix`. +- Refusals: `err01_input` .. `err30_contract`, `mistake_*`.