interplane.Get Omega
Read in your language

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

branch main Branches Tags History

omega-mv / seed / ng / src / main.om

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