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 / ngdis.om

512 lines · 6952 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note seed/ng/ngdis.om: ΩIR binary on stdin to its one canonical text on stdout (seed/ng/IR.md s10).
3note Owner: ng-ir lane. Build: cat seed/ng/ngtxt.om seed/ng/ngdis.om | seed/out/omc > ngdis
4note ngdis decodes structure only (it is not the validator): it prints every unit whose bytes the
5note text can spell, ids out of range and semantic faults included, and refuses the rest with the
6note IR.md s11 class as its exit code and "ngdis: refused class C at OFFSET" on stderr:
7note 10 MAGIC, 11 VERSION, 12 TRUNCATED, 13 an enumeration or field the text cannot spell (a type
8note kind, access, space, field order, role, global class or function kind outside its set, a
9note nonzero ty on a row without one, a non-canonical const), 14 TRAILING, 15 UNKNOWN_OP,
10note 23 LIMIT: input over 16777216 bytes (at 16777216), more than 65536 types, globals, functions,
11note blocks in a function, or parameters of a function or block (at the count), 27 IO.
12text z_msg "ngdis: refused class \n at \n"
13global z_in uchar 16777216
14global z_s ulong 4
15global z_pt uint 65536
16global z_k ulong 8
17global z_pb uchar 8
18fn dz_say a ulong b ulong to void
19r = write 2 z_msg a sub b a
20end
21fn dz_bad c ulong off ulong to void
22dz_say 0 21
23put x_on 0 0
24tx_num c
25r = write 2 x_out 0 get x_on 0
26dz_say 22 26
27put x_on 0 0
28tx_num off
29tx_c 10
30r = write 2 x_out 0 get x_on 0
31exit int c
32end
33fn dz_at to ulong
34ret get z_s 0
35end
36fn dz_need k ulong to ulong
37p = get z_s 0
38if gt add p k get z_s 1
39dz_bad 12 p
40end
41put z_s 0 add p k
42ret p
43end
44fn dz_un k ulong to ulong
45p = dz_need k
46v = ulong 0
47for j ulong k bound 8
48x = ulong get z_in add p j
49v = or v shl x mul j 8
50end
51ret v
52end
53fn dz_u8 to ulong
54ret dz_un 1
55end
56fn dz_u32 to ulong
57ret dz_un 4
58end
59note a table count (IR.md s12): over 65536 is LIMIT at the count, before what it counts
60fn dz_cnt to ulong
61o = dz_at
62n = dz_u32
63if gt n 65536
64dz_bad 23 o
65end
66ret n
67end
68note ---- header and tables ------------------------------------------------------------------------
69fn dz_head to void
70n = get z_s 1
71for j ulong 7
72if ge j n
73dz_bad 12 0
74end
75x = ulong get z_in j
76if lt j 6
77if ne x dz_magic j
78dz_bad 10 0
79end
80else
81if ne x 0
82dz_bad 10 0
83end
84end
85end
86put z_s 0 7
87if ne dz_u8 9
88dz_bad 11 7
89end
90p = dz_need 16
91for j ulong 16
92if ne ulong get z_in add 8 j dz_tag j
93dz_bad 11 8
94end
95end
96end
97note magic "OSC1IR" and tag "omega.ng.ir.v1" then two zero bytes
98fn dz_magic j ulong to ulong
99if eq j 0
100ret 79
101end
102if eq j 1
103ret 83
104end
105if eq j 2
106ret 67
107end
108if eq j 3
109ret 49
110end
111if eq j 4
112ret 73
113end
114ret 82
115end
116fn dz_tag j ulong to ulong
117if ge j 14
118ret 0
119end
120if eq j 0
121ret 111
122end
123if eq j 1
124ret 109
125end
126if eq j 2
127ret 101
128end
129if eq j 3
130ret 103
131end
132if eq j 4
133ret 97
134end
135if or eq j 5 eq j 8
136ret 46
137end
138if eq j 6
139ret 110
140end
141if eq j 7
142ret 103
143end
144if eq j 9
145ret 105
146end
147if eq j 10
148ret 114
149end
150if eq j 11
151ret 46
152end
153if eq j 12
154ret 118
155end
156ret 49
157end
158fn dz_types to void
159n = dz_cnt
160for k ulong n bound 16777216
161dz_type add k 32
162end
163end
164fn dz_type t ulong to void
165o = dz_at
166kd = dz_u8
167if or eq kd 0 gt kd 6
168dz_bad 13 o
169end
170tx_kw 27
171tx_sp
172tx_ty t
173tx_c 32
174tx_c 61
175tx_sp
176tx_kw add 14 kd
177sz = ulong 0
178if or eq kd 1 eq kd 2
179sz = dz_tva kd
180end
181if eq kd 3
182sz = dz_tstr o
183end
184if or eq kd 4 eq kd 5
185dz_tref o
186end
187if eq kd 6
188dz_tfrg o
189end
190tx_nl
191tx_tset t kd sz
192end
193note vec E L, array E C; the entry's byte size
194fn dz_tva kd ulong to ulong
195e = dz_u32
196c = dz_u32
197tx_sp
198tx_ty e
199tx_sp
200tx_num c
201ret tx_mul c tx_size e
202end
203fn dz_tstr o ulong to ulong
204sz = dz_u32
205nf = dz_u32
206tx_sp
207tx_num sz
208for j ulong nf bound 16777216
209ft = dz_u32
210of = dz_u32
211od = dz_u8
212if gt od 1
213dz_bad 13 o
214end
215tx_sp
216tx_ty ft
217tx_c 64
218tx_num of
219tx_c 58
220tx_kw add 13 od
221end
222ret sz
223end
224fn dz_tref o ulong to void
225x = dz_u32
226ac = dz_u8
227sp = dz_u8
228if or gt ac 1 gt sp 4
229dz_bad 13 o
230end
231tx_sp
232tx_kw add 3 ac
233tx_sp
234tx_kw add 5 sp
235tx_sp
236tx_ty x
237end
238fn dz_tfrg o ulong to void
239ro = dz_u8
240if gt ro 2
241dz_bad 13 o
242end
243tx_sp
244tx_kw add 10 ro
245for j ulong 3
246tx_sp
247tx_num dz_un 2
248end
249tx_sp
250tx_ty dz_u32
251end
252fn dz_globs to void
253n = dz_cnt
254for g ulong n bound 16777216
255dz_glob g
256end
257end
258fn dz_glob g ulong to void
259o = dz_at
260t = dz_u32
261c = dz_u8
262if gt c 2
263dz_bad 13 o
264end
265tx_kw 6
266tx_c 32
267tx_c 64
268tx_c 103
269tx_num g
270tx_sp
271tx_ty t
272tx_sp
273if eq c 2
274tx_kw 32
275else
276tx_kw add 21 c
277end
278if eq c 1
279n = tx_size t
280p = dz_need n
281if gt n 0
282tx_sp
283end
284for j ulong n bound 1099511627776
285tx_hexn ulong get z_in add p j 2
286end
287end
288tx_nl
289end
290note ---- functions ------------------------------------------------------------------------------
291fn dz_funcs to void
292n = dz_cnt
293for f ulong n bound 16777216
294dz_fn f
295end
296end
297fn dz_fn f ulong to void
298o = dz_at
299k = dz_u8
300fl = dz_u8
301if gt k 2
302dz_bad 13 o
303end
304po = dz_at
305np = dz_u32
306if gt np 65536
307dz_bad 23 po
308end
309for j ulong np bound 65536
310put z_pt j uint dz_u32
311end
312rs = dz_u32
313tx_kw k
314tx_c 32
315tx_c 64
316tx_c 102
317tx_num f
318tx_sp
319tx_kw 23
320tx_sp
321tx_num fl
322if eq k 1
323dz_kern
324end
325for j ulong np bound 65536
326tx_sp
327tx_val add j 1
328tx_c 58
329tx_ty ulong get z_pt j
330end
331tx_c 32
332tx_c 45
333tx_c 62
334tx_sp
335tx_ty rs
336tx_nl
337put z_k 0 add np 1
338nb = dz_cnt
339for j ulong nb bound 16777216
340dz_blk j
341end
342tx_kw 28
343tx_nl
344end
345fn dz_kern to void
346tx_sp
347tx_kw 24
348for j ulong 3
349tx_sp
350tx_num dz_u32
351end
352tx_sp
353tx_kw 25
354tx_sp
355tx_num dz_u8
356end
357fn dz_blk j ulong to void
358tx_kw 26
359tx_sp
360tx_c 94
361tx_num j
362np = dz_cnt
363for k ulong np bound 16777216
364tx_sp
365v = get z_k 0
366tx_val v
367put z_k 0 add v 1
368tx_c 58
369tx_ty dz_u32
370end
371tx_nl
372n = dz_u32
373for k ulong n bound 16777216
374dz_op
375end
376end
377fn dz_op to void
378o = dz_at
379op = dz_u8
380if eq get x_rok op 0
381dz_bad 15 o
382end
383t = dz_u32
384c = ulong get x_rty op
385if and eq c 0 ne t 0
386dz_bad 13 o
387end
388m = ulong 0
389if ne get x_rim op 0
390m = dz_un 8
391end
392if and eq op 1 not tx_canon t m
393dz_bad 13 o
394end
395n = ulong 0
396if ne get x_rva op 0
397n = dz_u32
398end
399dz_defs op t
400tx_rname op
401if ne c 0
402tx_sp
403tx_ty t
404end
405if ne get x_rim op 0
406tx_sp
407dz_imm op t m
408end
409k = add add tx_ntok op ulong get x_rfx op n
410for s ulong k bound 16777216
411tx_sp
412dz_opnd op s dz_u32
413end
414tx_nl
415end
416fn dz_defs op ulong t ulong to void
417d = tx_ndef op t
418if eq d 0
419ret
420end
421v = get z_k 0
422tx_val v
423if eq d 2
424tx_sp
425tx_val add v 1
426end
427tx_sp
428tx_c 61
429tx_sp
430put z_k 0 add v d
431end
432fn dz_imm op ulong t ulong m ulong to void
433if or eq op 52 and ge op 111 le op 116
434tx_c 64
435tx_c 103
436tx_num m
437ret
438end
439if ne op 1
440tx_num m
441ret
442end
443f = tx_cf t
444if eq f 1
445tx_kw sub 31 m
446ret
447end
448if eq f 4
449tx_c 48
450tx_c 120
451tx_hexn m mul tx_sb t 2
452ret
453end
454if and eq f 3 ne shr m 63 0
455tx_c 45
456tx_num sub 0 m
457ret
458end
459tx_num m
460end
461fn dz_opnd op ulong s ulong v ulong to void
462k = tx_slot op s
463if eq k 1
464tx_c 94
465tx_num v
466ret
467end
468if eq k 2
469tx_c 64
470tx_c 102
471tx_num v
472ret
473end
474tx_val v
475end
476fn main to int
477tx_init
478n = ulong 0
479while lt n len z_in bound 16777217
480k = read 0 z_in n sub len z_in n
481if lt k 0
482dz_bad 27 n
483end
484if eq k 0
485break
486end
487n = add n ulong k
488end
489if eq n len z_in
490k = read 0 z_pb 0 1
491if lt k 0
492dz_bad 27 n
493end
494if gt k 0
495dz_bad 23 n
496end
497end
498put z_s 1 n
499dz_head
500tx_kw 29
501tx_sp
502tx_c 49
503tx_nl
504dz_types
505dz_globs
506dz_funcs
507if lt dz_at n
508dz_bad 14 dz_at
509end
510tx_flush
511ret 0
512end