omega-mv
Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.
Brought by drakestapleton
omega-mv / seed / ng / src / main.om
| 1 | note SPDX-License-Identifier: Apache-2.0 |
| 2 | note seed/ng/src/main.om: fn main of the ng compiler, last unit of seed/ng/ng.units. Owner: ng-ir lane |
| 3 | note (stage lanes add their modes beside their code). The first input line selects the mode; it is |
| 4 | note read apart, so the payload after its newline is region 0 of the arena (src/ir.om ar_rdin) from |
| 5 | note offset 0, as large as the arena holds (no-caps 2026-11-11). |
| 6 | note @ng ir-copy payload is ΩIR binary: read it with ir_read, write it back with ir_wr (stdout) |
| 7 | note @ng front-check payload is an Omega unit: front.om checks it (fe_check) and refuses exactly as omc |
| 8 | note (same stderr line and exit code; 64 for a unit ng does not take); nothing on stdout. A |
| 9 | note payload the arena cannot hold is error 14 at line 0, as in omc, with the ng-use record; |
| 10 | note an unreadable payload is class 27 below (omc: error 1) |
| 11 | note @ng front-ir payload is an Omega unit: checked as front-check (same refusals), then lowered to ΩIR |
| 12 | note (fe_lout, seed/ng/IR.md s13) and written with ir_wr (stdout); 64 for a unit or a |
| 13 | note construct the lowering does not take |
| 14 | note @ng opt payload is ΩIR binary: read it, optimize it (op_run, opt.om: preheaders, LICM, ROT), write it |
| 15 | note @ng opt-count the same passes; one stdout line of counts (op_put) instead of the unit |
| 16 | note @ng a64-enc payload is an encoder case list; a6_run (a64.om) writes one word per case |
| 17 | note @ng a64 payload is ΩIR binary; a6_run compiles it to an AArch64 ELF on stdout (saves as STP/LDP pairs) |
| 18 | note @ng a64 split the same with separate STR/LDR saves (seed/ng/a64/DESIGN.md) |
| 19 | note @ng a64 macho the same as `@ng a64`, as a dynamic arm64 Mach-O for macOS (DESIGN.md s11) |
| 20 | note A stage lane's hook names its mode from the mode line (ng_mlb) before main reads the payload, and runs on the |
| 21 | note payload main read (same limit and refusals as ir-copy). |
| 22 | note Exit 0 on success; a refused ΩIR input exits with its IR.md s11 class and one stderr line |
| 23 | note "ng: refused class C at OFFSET" (offset in the payload): a payload the arena cannot hold is class 23 |
| 24 | note at the bytes read, followed by the ng-use record; an unreadable one class 27 at the bytes read; |
| 25 | note unknown mode exit 2. |
| 26 | text ng_modes "@ng ir-copy@ng front-check@ng front-ir@ng opt@ng opt-count" |
| 27 | text ng_msgs "ng: refused class \n at \nng: unknown mode\n" |
| 28 | global ng_dig uchar 24 |
| 29 | global ng_ml uchar 64 |
| 30 | note refuse with class c at payload offset off |
| 31 | fn ng_bad c ulong off ulong to void |
| 32 | ng_say 0 18 |
| 33 | ng_num c |
| 34 | ng_say 19 23 |
| 35 | ng_num off |
| 36 | put ng_dig 0 10 |
| 37 | k = write 2 ng_dig 0 1 |
| 38 | note a payload or table the arena could not hold: the ng-use record follows the line |
| 39 | if ne get ar_fl 0 0 |
| 40 | ar_rec 2 |
| 41 | end |
| 42 | exit int c |
| 43 | end |
| 44 | note the mode line into ng_ml, one byte at a time up to its newline; its length, or 64 when there |
| 45 | note is no newline within 64 bytes; unreadable input is class 27 at 0 |
| 46 | fn ng_line to ulong |
| 47 | for j ulong 64 |
| 48 | k = read 0 ng_ml j 1 |
| 49 | if lt k 0 |
| 50 | ng_bad 27 0 |
| 51 | end |
| 52 | if eq k 0 |
| 53 | ret 64 |
| 54 | end |
| 55 | if eq get ng_ml j 10 |
| 56 | ret j |
| 57 | end |
| 58 | end |
| 59 | ret 64 |
| 60 | end |
| 61 | fn ng_say a ulong b ulong to void |
| 62 | k = write 2 ng_msgs a sub b a |
| 63 | end |
| 64 | fn ng_num v ulong to void |
| 65 | x = v |
| 66 | i = ulong 24 |
| 67 | for j ulong 21 |
| 68 | i = sub i 1 |
| 69 | put ng_dig i uchar add 48 rem x 10 |
| 70 | x = div x 10 |
| 71 | if eq x 0 |
| 72 | k = write 2 ng_dig i sub 24 i |
| 73 | ret |
| 74 | end |
| 75 | end |
| 76 | end |
| 77 | note the mode line (length m) is the mode text ng_modes[o, o + l) |
| 78 | fn ng_mode o ulong l ulong m ulong to bool |
| 79 | if ne m l |
| 80 | ret false |
| 81 | end |
| 82 | for j ulong m bound 64 |
| 83 | if ne get ng_ml j get ng_modes add o j |
| 84 | ret false |
| 85 | end |
| 86 | end |
| 87 | ret true |
| 88 | end |
| 89 | note the mode: 0 ir-copy, 1 opt, 2 opt-count, 3 none |
| 90 | fn ng_kind m ulong to ulong |
| 91 | if ng_mode 0 11 m |
| 92 | ret 0 |
| 93 | end |
| 94 | if ng_mode 38 7 m |
| 95 | ret 1 |
| 96 | end |
| 97 | if ng_mode 45 13 m |
| 98 | ret 2 |
| 99 | end |
| 100 | ret 3 |
| 101 | end |
| 102 | note ng_mlb j: byte j of the mode line (stage lanes' mode hooks read it; units before this one cannot name ng_ml) |
| 103 | fn ng_mlb j ulong to ulong |
| 104 | ret ulong get ng_ml j |
| 105 | end |
| 106 | note front-check: the payload is already region 0 of the arena (ng_rd), as omc reads its input; a payload the |
| 107 | note arena cannot hold is error 14 at line 0, as in omc, with the ng-use record (fe_fail) |
| 108 | fn ng_front to int |
| 109 | r = ng_rd |
| 110 | if eq r 2 |
| 111 | fe_fail 14 |
| 112 | end |
| 113 | ret fe_check get ar_inl 0 |
| 114 | end |
| 115 | note front-ir: as front-check; front.om's end of input then lowers the unit and writes it (fe_lout) |
| 116 | fn ng_fir to int |
| 117 | put f_lmode 0 1 |
| 118 | ret ng_front |
| 119 | end |
| 120 | note ng_rd: the payload into region 0 of the arena (ar_rdin), then every other region its first room |
| 121 | note (ar_init): 0 read, 2 the arena could not hold it; a read error is class 27 at the bytes read |
| 122 | fn ng_rd to ulong |
| 123 | r = ar_rdin 0 |
| 124 | if eq r 1 |
| 125 | ng_bad 27 get ar_inl 0 |
| 126 | end |
| 127 | if eq r 0 |
| 128 | ar_init |
| 129 | end |
| 130 | ret r |
| 131 | end |
| 132 | fn main to int |
| 133 | m = ng_line |
| 134 | if ng_mode 11 15 m |
| 135 | ret ng_front |
| 136 | end |
| 137 | if ng_mode 26 12 m |
| 138 | ret ng_fir |
| 139 | end |
| 140 | a = a6_mode m |
| 141 | md = ng_kind m |
| 142 | if and eq md 3 eq a 255 |
| 143 | ng_say 24 41 |
| 144 | ret 2 |
| 145 | end |
| 146 | if eq ng_rd 2 |
| 147 | ng_bad 23 get ar_inl 0 |
| 148 | end |
| 149 | n = get ar_inl 0 |
| 150 | if ne a 255 |
| 151 | a6_run a n |
| 152 | end |
| 153 | r = ir_read 0 n |
| 154 | if ne r 0 |
| 155 | ng_bad r ir_badat |
| 156 | end |
| 157 | if gt md 0 |
| 158 | op_run |
| 159 | end |
| 160 | if eq md 2 |
| 161 | ret op_put |
| 162 | end |
| 163 | w = ir_wr |
| 164 | if eq ar_out 1 1 0 w 0 |
| 165 | ret 27 |
| 166 | end |
| 167 | ret 0 |
| 168 | end |