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 / omc / codereg.om

599 lines · 9182 bytes Raw Blame History
1note codereg.om -- error-code registry drift check (issue #797), compiled and run by seed/omc/gate15.sh.
2note Arguments: REGISTRY OMC_SOURCE OMEGESE IRWASM_SOURCE RANLOG. Exit 0 agrees; 1 on drift, usage or unreadable input.
3note A REGISTRY row is NS|CODE|STATUS|CASE|MEANING. NS omc and irwasm are separate namespaces: the same
4note number means different things in each. STATUS emitted or io needs at least one emitting site in the
5note namespace's source; unused needs none. Every site needs a row. An omc row names the gate15 case
6note that must have refused with that code (RANLOG lines NAME CODE). OMEGESE must hold exactly one line
7note | NS CODE | MEANING | per row and no other line of that shape.
8global fb uchar 4194304
9global rg uchar 65536
10global pth uchar 4096
11global bars ulong 4
12global st ulong 512
13global mo ulong 512
14global ml ulong 512
15global co ulong 512
16global cl ulong 512
17global sc ulong 512
18global dh ulong 512
19global rh ulong 256
20global ob uchar 512
21global on ulong 1
22text tm "FAIL codereg \nusage: codereg REGISTRY OMC_SOURCE OMEGESE IRWASM_SOURCE RANLOG\ncannot read argument\nmalformed registry row at line\nduplicate registry row\nemitting site without an emitted or io registry row\nemitted or io registry row without an emitting site\nOMEGESE row differs from the registry\nOMEGESE row count is not 1 for\ngate case refused with a code that has no emitted or io registry row\nregistry case did not refuse with its code in the gate\nmalformed OMEGESE registry row at line\nomc\nirwasm\nPASS codereg registry=\n sites=\n omegese=\n cases=\nemitted\nio\nunused\n-\nfail\nnfail\nunkfail\nlenval\nrefuse\nexit int\nnote\n| omc \n| irwasm \n | \n |"
23
24fn ob_b c ulong to void
25n = get on 0
26if lt n 512
27put ob n uchar c
28put on 0 add n 1
29end
30end
31
32fn ob_n v ulong to void
33d = new uchar 20 0
34k = ulong 0
35x = v
36for i ulong 20
37put d k uchar add 48 rem x 10
38k = add k 1
39x = div x 10
40if eq x 0
41break
42end
43end
44for j ulong k
45ob_b ulong get d sub sub k j 1
46end
47end
48
49note segat: offset of newline-separated segment k of tm.
50fn segat k ulong to ulong
51seg = ulong 0
52for i ulong len tm
53if eq seg k
54ret i
55end
56if eq get tm i 10
57seg = add seg 1
58end
59end
60ret len tm
61end
62
63fn ob_s k ulong to void
64t = segat k
65for i ulong len tm
66j = add t i
67if ge j len tm
68break
69end
70c = get tm j
71if eq c 10
72break
73end
74ob_b ulong c
75end
76end
77
78fn ob_out fd int to void
79n = get on 0
80w = write fd ob 0 n
81put on 0 0
82end
83
84note die: print FAIL, reason k; a 0 or 1 adds namespace and code b, a 2 adds number b. Exit 1.
85fn die k ulong a ulong b ulong to void
86ob_s 0
87ob_s k
88if lt a 2
89ob_b 32
90ob_s add 12 a
91ob_b 32
92ob_n b
93end
94if eq a 2
95ob_b 32
96ob_n b
97end
98ob_b 10
99ob_out 2
100exit 1
101end
102
103note load: argument idx into fb, at most cap bytes; returns the length.
104fn load idx ulong cap ulong to ulong
105r = argread idx pth 0 4096
106if lt r 1
107die 2 2 idx
108end
109fd = fopen pth 0 ulong r 524288 0
110if lt fd 0
111die 2 2 idx
112end
113n = ulong 0
114note Every pass but the last adds at least one byte, and n = cap stops it: cap + 1 passes suffice.
115for a ulong 4194305
116if eq n cap
117die 2 2 idx
118end
119k = read int fd fb n sub cap n
120if lt k 0
121die 2 2 idx
122end
123if eq k 0
124break
125end
126n = add n ulong k
127end
128c = fclose int fd
129if lt c 0
130die 2 2 idx
131end
132ret n
133end
134
135note prefix: length of segment k of tm when fb[p..e) begins with it, else 0.
136fn prefix p ulong e ulong k ulong to ulong
137t = segat k
138m = ulong 0
139for i ulong len tm
140j = add t i
141if ge j len tm
142break
143end
144c = get tm j
145if eq c 10
146break
147end
148if ge add p i e
149ret 0
150end
151if ne c get fb add p i
152ret 0
153end
154m = add m 1
155end
156ret m
157end
158
159fn wordeq p ulong q ulong k ulong to bool
160m = prefix p q k
161if eq m 0
162ret false
163end
164ret eq m sub q p
165end
166
167note sameat: rg[ro..ro+rl) equals fb[a..b).
168fn sameat ro ulong rl ulong a ulong b ulong to bool
169if ne rl sub b a
170ret false
171end
172for i ulong rl
173if ne get rg add ro i get fb add a i
174ret false
175end
176end
177ret true
178end
179
180fn eol s ulong n ulong to ulong
181i = s
182for a ulong 4194305
183if ge i n
184ret n
185end
186if eq get fb i 10
187ret i
188end
189i = add i 1
190end
191ret n
192end
193
194fn skipws s ulong e ulong to ulong
195i = s
196for a ulong 4194305
197if ge i e
198ret e
199end
200c = get fb i
201if and ne c 32 ne c 9
202ret i
203end
204i = add i 1
205end
206ret e
207end
208
209note lastw: start of the last word in fb[p..e).
210fn lastw p ulong e ulong to ulong
211i = e
212for a ulong 4194305
213if le i p
214ret p
215end
216c = get fb sub i 1
217if or eq c 32 eq c 9
218ret i
219end
220i = sub i 1
221end
222ret i
223end
224
225fn wordend p ulong e ulong to ulong
226i = p
227for a ulong 4194305
228if ge i e
229ret e
230end
231if eq get fb i 32
232ret i
233end
234i = add i 1
235end
236ret e
237end
238
239fn nextbar p ulong e ulong to ulong
240i = p
241for a ulong 65537
242if ge i e
243ret e
244end
245if eq get fb i 124
246ret i
247end
248i = add i 1
249end
250ret e
251end
252
253note numof: decimal 1..3 digits filling fb[p..q), else 0.
254fn numof p ulong q ulong to ulong
255if or ge p q gt sub q p 3
256ret 0
257end
258v = ulong 0
259for i ulong sub q p
260c = get fb add p i
261if or lt c 48 gt c 57
262ret 0
263end
264v = add mul v 10 ulong sub c 48
265end
266ret v
267end
268
269fn isnote p ulong e ulong to bool
270m = prefix p e 28
271if eq m 0
272ret false
273end
274q = add p m
275if eq q e
276ret true
277end
278c = get fb q
279ret or eq c 32 eq c 9
280end
281
282fn regns s ulong ln ulong to ulong
283b = get bars 0
284if wordeq s b 12
285ret 0
286end
287if wordeq s b 13
288ret 1
289end
290die 3 2 ln
291ret 2
292end
293
294fn regcode ln ulong to ulong
295code = numof add get bars 0 1 get bars 1
296if or eq code 0 gt code 255
297die 3 2 ln
298end
299ret code
300end
301
302fn regsv ln ulong to ulong
303p = add get bars 1 1
304q = get bars 2
305if wordeq p q 18
306ret 1
307end
308if wordeq p q 19
309ret 2
310end
311if wordeq p q 20
312ret 3
313end
314die 3 2 ln
315ret 0
316end
317
318note regcase: unused rows and irwasm rows carry no case; emitted and io omc rows name one.
319fn regcase x ulong ns ulong sv ulong ln ulong to void
320p = add get bars 2 1
321q = get bars 3
322if ge p q
323die 3 2 ln
324end
325dash = wordeq p q 21
326if and eq sv 3 not dash
327die 3 2 ln
328end
329if and eq ns 1 not dash
330die 3 2 ln
331end
332if and and eq ns 0 ne sv 3 dash
333die 3 2 ln
334end
335put co x p
336put cl x sub q p
337end
338
339fn regrow s ulong e ulong ln ulong to void
340p = s
341for i ulong 4
342q = nextbar p e
343if ge q e
344die 3 2 ln
345end
346put bars i q
347p = add q 1
348end
349if lt nextbar p e e
350die 3 2 ln
351end
352if ge p e
353die 3 2 ln
354end
355ns = regns s ln
356code = regcode ln
357x = add mul ns 256 code
358if ne get st x 0
359die 4 ns code
360end
361sv = regsv ln
362regcase x ns sv ln
363put st x sv
364put mo x p
365put ml x sub e p
366end
367
368fn regparse n ulong to ulong
369s = ulong 0
370ln = ulong 0
371rows = ulong 0
372for a ulong 65537
373if ge s n
374break
375end
376e = eol s n
377ln = add ln 1
378if gt e s
379if not isnote s e
380regrow s e ln
381rows = add rows 1
382end
383end
384s = add e 1
385end
386ret rows
387end
388
389note siteof: the code a source line emits. omc: fail, nfail or unkfail N as the whole line, lenval N
390note at the end of a line, exit int N (N not 0). irwasm: refuse N as the whole line. Note lines never.
391fn siteof s ulong e ulong ns ulong to ulong
392p = skipws s e
393if ge p e
394ret 0
395end
396if isnote p e
397ret 0
398end
399lw = lastw p e
400if le lw p
401ret 0
402end
403code = numof lw e
404if or eq code 0 gt code 255
405ret 0
406end
407pe = sub lw 1
408pw = lastw p pe
409if eq ns 1
410if and eq pw p wordeq p pe 26
411ret code
412end
413ret 0
414end
415if eq pw p
416if or or wordeq p pe 22 wordeq p pe 23 wordeq p pe 24
417ret code
418end
419end
420if wordeq pw pe 25
421ret code
422end
423if wordeq p pe 27
424ret code
425end
426ret 0
427end
428
429fn scanln n ulong ns ulong to ulong
430s = ulong 0
431t = ulong 0
432for a ulong 4194305
433if ge s n
434break
435end
436e = eol s n
437c = siteof s e ns
438if ne c 0
439x = add mul ns 256 c
440put sc x add get sc x 1
441t = add t 1
442end
443s = add e 1
444end
445ret t
446end
447
448fn sitechk to void
449for x ulong 512
450v = get st x
451used = or eq v 1 eq v 2
452if and gt get sc x 0 not used
453die 5 div x 256 rem x 256
454end
455if and used eq get sc x 0
456die 6 div x 256 rem x 256
457end
458end
459end
460
461fn docrow s ulong e ulong ln ulong to ulong
462ns = ulong 0
463m = prefix s e 29
464if eq m 0
465ns = 1
466m = prefix s e 30
467end
468if eq m 0
469ret 0
470end
471p = add s m
472q = wordend p e
473code = numof p q
474if or eq code 0 gt code 255
475die 11 2 ln
476end
477r = prefix q e 31
478if eq r 0
479die 11 2 ln
480end
481mb = add q r
482if lt e add mb 2
483die 11 2 ln
484end
485me = sub e 2
486if ne prefix me e 32 2
487die 11 2 ln
488end
489x = add mul ns 256 code
490put dh x add get dh x 1
491if eq get st x 0
492die 7 ns code
493end
494if not sameat get mo x get ml x mb me
495die 7 ns code
496end
497ret 1
498end
499
500fn docscan n ulong to ulong
501s = ulong 0
502ln = ulong 0
503t = ulong 0
504for a ulong 4194305
505if ge s n
506break
507end
508e = eol s n
509ln = add ln 1
510t = add t docrow s e ln
511s = add e 1
512end
513ret t
514end
515
516fn docchk to void
517for x ulong 512
518if and ne get st x 0 ne get dh x 1
519die 8 div x 256 rem x 256
520end
521end
522end
523
524fn ranrow s ulong e ulong to void
525lw = lastw s e
526code = numof lw e
527if or eq code 0 gt code 255
528die 9 3 0
529end
530v = get st code
531if and ne v 1 ne v 2
532die 9 0 code
533end
534if le lw s
535die 9 0 code
536end
537if sameat get co code get cl code s sub lw 1
538put rh code 1
539end
540end
541
542fn ranscan n ulong to ulong
543s = ulong 0
544t = ulong 0
545for a ulong 4194305
546if ge s n
547break
548end
549e = eol s n
550if gt e s
551ranrow s e
552t = add t 1
553end
554s = add e 1
555end
556ret t
557end
558
559fn ranchk to void
560for x ulong 256
561v = get st x
562if and or eq v 1 eq v 2 eq get rh x 0
563die 10 0 x
564end
565end
566end
567
568fn main to int
569if ne argcnt 6
570die 1 3 0
571end
572n = load 1 65536
573rows = regparse n
574for i ulong n
575put rg i get fb i
576end
577n = load 2 4194304
578s0 = scanln n 0
579n = load 4 4194304
580s1 = scanln n 1
581sitechk
582n = load 3 4194304
583d = docscan n
584docchk
585n = load 5 4194304
586c = ranscan n
587ranchk
588ob_s 14
589ob_n rows
590ob_s 15
591ob_n add s0 s1
592ob_s 16
593ob_n d
594ob_s 17
595ob_n c
596ob_b 10
597ob_out 1
598ret 0
599end