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 / train / units-gate.om

821 lines · 15608 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note train/units-gate.om: OMEGA-TRAIN-UNITS, the gate of the pure-Omega units of Sovereign Intelligence layer 'train', in
3note seeded Omega (Linux AArch64). Build from the repository root (OM-2 program mode; seed/ng/sha256.om supplies
4note sh_dat, sh_all, sh_dig):
5note { printf 'om2\n'; cat seed/ng/sha256.om train/units-gate.om; } | seed/out/omc > train-units-gate
6note Run from the repository root: train-units-gate OMC SCRATCH
7note OMC the compiler under test; its sha256 must equal the first word of seed/out/omc.sha256, or nothing
8note runs (exit 69, nothing written)
9note SCRATCH a new directory (created 0700), at most 1024 bytes of path; an existing one is refused (exit 2)
10note Units. train/units.tsv lists every unit, one per line: NAME then the paths of its parts, single spaces; a line
11note starting with # is a comment and an empty line is skipped. NAME is 1 to 249 of A-Z a-z 0-9 _ and appears once
12note (249 leaves room for the longest scratch suffix, ".1.err", inside a 255-byte file name).
13note The parts are concatenated in order, each followed by a newline (the composition of train/units.tsv), into
14note SCRATCH/NAME.om and compiled twice by OMC: each compile exits 0 with empty stderr, and both outputs hold the same
15note bytes. A malformed or repeated row, a missing part, a failed compile, two different outputs or a table with no
16note unit is a FAIL line. The runner (train/README.md) also requires the exact unit count.
17note Control, must be caught: a compiler one byte longer fails the digest check.
18note Output: one line per unit, then OMEGA-TRAIN-UNITS PASS|FAIL units=U controls=C caught=K hardware=NOT_RUN.
19note Exit 0 PASS, 1 FAIL, 2 bad usage or setup, 69 compiler digest refused. Every input is length-checked; a trap
20note exit (101..114) would be a defect of this gate, never a pass.
21note This gate checks that the units compile reproducibly with this repository's compiler. It does not run them:
22note their behaviour checks are still C, Python and shell upstream (train/UNITS.md lists them).
23text t_pin "seed/out/omc.sha256"
24text t_tab "train/units.tsv"
25text t_om ".om"
26text t_b1 ".1"
27text t_b2 ".2"
28text t_e1 ".1.err"
29text t_e2 ".2.err"
30text t_badname "units.tsv: name outside A-Z a-z 0-9 _"
31text t_dup "units.tsv: name repeated, or more than 64 KiB of names"
32text t_empty "units.tsv names no unit"
33text t_plus "omc-plus-one"
34text t_usage "usage: train-units-gate OMC SCRATCH (run from the omega-mv repository root)\n"
35text t_refd "OMEGA-TRAIN-UNITS REFUSED: compiler digest differs from seed/out/omc.sha256 (exit 69)\n"
36text t_nopin "OMEGA-TRAIN-UNITS INVALID: cannot read a 64-hex digest from seed/out/omc.sha256\n"
37text t_noscr "OMEGA-TRAIN-UNITS INVALID: SCRATCH exists or cannot be made\n"
38text t_notab "OMEGA-TRAIN-UNITS INVALID: cannot read train/units.tsv\n"
39text t_long "OMEGA-TRAIN-UNITS INVALID: SCRATCH path longer than 1024 bytes\n"
40text t_ok "ok "
41text t_fail "FAIL "
42text t_unit "unit "
43text t_ctl "control "
44text t_bytes " bytes="
45text t_sha " sha256="
46text t_exit " exit="
47text t_src "source unreadable: "
48text t_big "output unreadable or over 16 MiB"
49text t_cmp "compile"
50text t_stderr " stderr not empty"
51text t_twice " two builds differ"
52text t_write "cannot write the composed unit in SCRATCH"
53text t_row "units.tsv: malformed row (name 1..249 bytes, at least one part)"
54text t_plong "units.tsv: a part path is longer than 4000 bytes"
55text t_caught " caught"
56text t_esc " ESCAPED"
57text t_sum "OMEGA-TRAIN-UNITS "
58text t_pass "PASS"
59text t_fl "FAIL"
60text t_su " units="
61text t_sc " controls="
62text t_sk " caught="
63text t_hw " hardware=NOT_RUN\n"
64text t_re1 "train/aien-train/native/omegallm"
65text t_re2 "train/aien-train/tests/omegallm"
66text t_re3 "train/aien-train/tools/omegallm"
67text t_re4 "train/aien-train/docs/omegallm"
68text t_remsg "re-imported migrated Omega LLM folder exists: "
69global g_pa uchar 4096
70global g_scr uchar 4096
71global g_omc uchar 4096
72global g_nm uchar 256
73global g_av uchar 8192
74global g_b uchar 16777216
75global g_u uchar 1048576
76global g_o uchar 8192
77global g_hx uchar 64
78global g_pin uchar 64
79global g_d1 uchar 32
80global g_stb uchar 4
81global g_n ulong 32
82global g_seen uchar 65536
83note g_n: 0 path length, 1 omc length, 2 scratch length (with '/'), 3 argv bytes, 4 argc, 5 output length,
84note 6 buffer length, 7 table length, 8 units, 11 failures, 12 controls, 13 caught, 14 name length, 15 g_seen length,
85note 16 unit rows
86note ---- output
87fn oc c ulong to void
88n = get g_n 5
89put g_o n uchar c
90put g_n 5 add n 1
91end
92fn ot t view uchar * to void
93for i ulong len t bound 4096
94oc ulong get t i
95end
96end
97fn onm to void
98for i ulong get g_n 14 bound 256
99oc ulong get g_nm i
100end
101end
102fn onum v ulong to void
103if ge v 10
104onum div v 10
105end
106oc add 48 rem v 10
107end
108fn ohex to void
109for j ulong 32
110b = get sh_dig j
111oc ulong sh_hexd uint shr b 4
112oc ulong sh_hexd uint and b 15
113end
114end
115fn ohx to void
116for j ulong 64
117oc ulong get g_hx j
118end
119end
120fn oflush to void
121r = write 1 g_o 0 get g_n 5
122put g_n 5 0
123end
124fn onl to void
125oc 10
126oflush
127end
128note a failed check: FAIL KIND NAME then the reason; counts a failure
129fn ofail kind view uchar * why view uchar * to void
130ot t_fail
131ot kind
132onm
133oc 32
134ot why
135onl
136put g_n 11 add get g_n 11 1
137end
138note ---- paths: g_pa[0, g_n 0)
139fn pclr to void
140put g_n 0 0
141end
142fn pc c ulong to void
143n = get g_n 0
144put g_pa n uchar c
145put g_n 0 add n 1
146end
147fn pt t view uchar * to void
148for i ulong len t bound 4096
149pc ulong get t i
150end
151end
152fn pscr to void
153for j ulong get g_n 2 bound 4096
154pc ulong get g_scr j
155end
156end
157fn pnm to void
158for j ulong get g_n 14 bound 256
159pc ulong get g_nm j
160end
161end
162note scratch file NAME then suffix
163fn psn suf view uchar * to void
164pclr
165pscr
166pnm
167pt suf
168end
169note scratch file named by a text
170fn pst t view uchar * suf view uchar * to void
171pclr
172pscr
173pt t
174pt suf
175end
176note scratch file named by a text alone
177fn psc t view uchar * to void
178pclr
179pscr
180pt t
181end
182fn nmset t view uchar * to void
183for i ulong len t bound 256
184put g_nm i get t i
185end
186put g_n 14 len t
187end
188note ---- files
189fn fopn fl ulong mode ulong to int
190r = fopen g_pa 0 get g_n 0 int fl int mode
191if lt r 0
192ret -1
193end
194ret int r
195end
196fn frd to int
197ret fopn 524288 0
198end
199fn fwr to int
200ret fopn 524865 420
201end
202fn fexe to int
203r = unlink g_pa 0 get g_n 0
204ret fopn 524865 448
205end
206fn fclo fd int to void
207if ge fd 0
208r = fclose fd
209end
210end
211note append the file at g_pa to g_b; false when unreadable or past the buffer
212fn bload to bool
213fd = frd
214if lt fd 0
215ret false
216end
217n = get g_n 6
218ok = true
219while true bound 16777218
220x = read fd g_b n sub len g_b n
221if lt x 0
222ok = false
223break
224end
225if eq x 0
226break
227end
228n = add n ulong x
229if ge n len g_b
230ok = false
231break
232end
233end
234fclo fd
235put g_n 6 n
236ret ok
237end
238note write g_b[0, g_n 6) to the file at g_pa (0644, or 0700 when exe)
239fn bsave exe bool to bool
240fd = int -1
241if exe
242fd = fexe
243else
244fd = fwr
245end
246if lt fd 0
247ret false
248end
249n = get g_n 6
250o = ulong 0
251ok = true
252while lt o n bound 16777217
253x = write fd g_b o sub n o
254if le x 0
255ok = false
256break
257end
258o = add o ulong x
259end
260fclo fd
261ret ok
262end
263note sha256 of the file at g_pa into sh_dig; false when unreadable or past 16 MiB
264fn fhash to bool
265fd = frd
266if lt fd 0
267ret false
268end
269n = ulong 0
270ok = true
271while true bound 16777218
272x = read fd sh_dat n sub len sh_dat n
273if lt x 0
274ok = false
275break
276end
277if eq x 0
278break
279end
280n = add n ulong x
281if ge n len sh_dat
282ok = false
283break
284end
285end
286fclo fd
287if not ok
288ret false
289end
290sh_all n
291ret true
292end
293note the size of the file at g_pa, or 2^63 when unreadable
294fn fsize to ulong
295put g_n 6 0
296if not bload
297ret shl ulong 1 63
298end
299ret get g_n 6
300end
301note sh_dig equals the hex in g_hx
302fn digeq to bool
303for j ulong 32
304b = get sh_dig j
305if ne get g_hx mul j 2 sh_hexd uint shr b 4
306ret false
307end
308if ne get g_hx add mul j 2 1 sh_hexd uint and b 15
309ret false
310end
311end
312ret true
313end
314fn dsave to void
315for j ulong 32
316put g_d1 j get sh_dig j
317end
318end
319fn dsame to bool
320for j ulong 32
321if ne get g_d1 j get sh_dig j
322ret false
323end
324end
325ret true
326end
327note ---- processes
328fn aclr to void
329put g_n 3 2
330put g_n 4 0
331put g_av 0 0
332put g_av 1 0
333end
334note append g_pa as one argument
335fn apa to void
336p = get g_n 3
337n = get g_n 0
338for j ulong n bound 4096
339put g_av add add p 2 j get g_pa j
340end
341put g_av p uchar and n 255
342put g_av add p 1 uchar shr n 8
343put g_n 3 add p add n 2
344c = add get g_n 4 1
345put g_n 4 c
346put g_av 0 uchar and c 255
347put g_av 1 uchar shr c 8
348end
349fn atx t view uchar * to void
350pclr
351pt t
352apa
353end
354fn redir s int d int to void
355if ne dupfd s d 0 long d
356exit 127
357end
358end
359note run the argument list with stdin, stdout, stderr fds (closed here): the exit code, 256 + the signal, 512
360note when a file could not be opened, 1000 when the child passed the 600 s deadline (killed)
361fn spawn fi int fo int fe int to ulong
362if or lt fi 0 or lt fo 0 lt fe 0
363fclo fi
364fclo fo
365fclo fe
366ret 512
367end
368pid = fork
369if lt pid 0
370exit 2
371end
372if eq pid 0
373redir fi 0
374redir fo 1
375redir fe 2
376r = execprog g_av 0 get g_n 3
377exit 127
378end
379fclo fi
380fclo fo
381fclo fe
382t0 = monons
383while true bound 1000000000
384r = waitpid int pid g_stb 0 len g_stb 1
385if eq r pid
386x = ulong get g_stb 0
387if ne x 0
388ret add 256 x
389end
390ret ulong get g_stb 1
391end
392if lt r 0
393exit 2
394end
395if gt sub monons t0 600000000000
396r = killpid int pid 9
397r = waitpid int pid g_stb 0 len g_stb 0
398ret 1000
399end
400q = sleepns 200000
401end
402exit 2
403end
404note OMC < SCRATCH/NAME.om > SCRATCH/NAME.SUF 2> SCRATCH/NAME.ERR
405fn omc suf view uchar * err view uchar * to ulong
406psn t_om
407fi = frd
408aclr
409pclr
410for j ulong get g_n 1 bound 4096
411pc ulong get g_omc j
412end
413apa
414psn suf
415fo = fexe
416psn err
417fe = fwr
418ret spawn fi fo fe
419end
420note ---- the compiler digest
421note the first 64 characters of seed/out/omc.sha256 into g_pin; false unless lowercase hex
422fn pinread to bool
423pclr
424pt t_pin
425put g_n 6 0
426if not bload
427ret false
428end
429if lt get g_n 6 64
430ret false
431end
432for j ulong 64
433c = get g_b j
434ok = or and ge c 48 le c 57 and ge c 97 le c 102
435if not ok
436ret false
437end
438put g_pin j c
439end
440ret true
441end
442note the file at g_pa hashes to g_pin
443fn pinok to bool
444if not fhash
445ret false
446end
447for j ulong 64
448put g_hx j get g_pin j
449end
450ret digeq
451end
452note ---- units
453note g_u[i] is c, for i below e (never reads at or past e)
454fn uis i ulong e ulong c ulong to bool
455if ge i e
456ret false
457end
458ret eq ulong get g_u i c
459end
460fn uisnt i ulong e ulong c ulong to bool
461if ge i e
462ret false
463end
464ret ne ulong get g_u i c
465end
466note append one newline to g_b (units.sh writes one after every part)
467fn nl to bool
468n = get g_n 6
469if ge add n 1 len g_b
470ret false
471end
472put g_b n 10
473put g_n 6 add n 1
474ret true
475end
476note a missing or unreadable part: FAIL unit NAME source unreadable: PATH (the path is in g_pa, at most 4000 bytes)
477fn psrcfail to void
478ot t_fail
479ot t_unit
480onm
481oc 32
482ot t_src
483for q ulong get g_n 0 bound 4096
484oc ulong get g_pa q
485end
486onl
487put g_n 11 add get g_n 11 1
488end
489note compose the parts g_u[s, e) into g_b as train/units.tsv does: each part's bytes, then one newline; false
490note (reported) when a part is unreadable or its path is longer than 4000 bytes
491fn compose s ulong e ulong to bool
492put g_n 6 0
493i = s
494while lt i e bound 1048576
495while uis i e 32 bound 1048576
496i = add i 1
497end
498if ge i e
499break
500end
501j = i
502while uisnt j e 32 bound 1048576
503j = add j 1
504end
505if gt sub j i 4000
506ofail t_unit t_plong
507ret false
508end
509pclr
510for q ulong sub j i bound 4096
511pc ulong get g_u add i q
512end
513if not bload
514psrcfail
515ret false
516end
517if not nl
518ofail t_unit t_big
519ret false
520end
521i = j
522end
523ret true
524end
525note compile the composed unit twice; true when both exit 0 with empty stderr and equal bytes
526fn build to bool
527psn t_om
528if not bsave false
529ofail t_unit t_write
530ret false
531end
532r1 = omc t_b1 t_e1
533r2 = omc t_b2 t_e2
534if or ne r1 0 ne r2 0
535ot t_fail
536ot t_unit
537onm
538oc 32
539ot t_cmp
540ot t_exit
541onum r1
542oc 47
543onum r2
544onl
545put g_n 11 add get g_n 11 1
546ret false
547end
548psn t_e1
549s1 = fsize
550psn t_e2
551s2 = fsize
552if or ne s1 0 ne s2 0
553ofail t_unit t_stderr
554ret false
555end
556psn t_b1
557if not fhash
558ofail t_unit t_big
559ret false
560end
561dsave
562psn t_b2
563if not fhash
564ofail t_unit t_big
565ret false
566end
567if not dsame
568ofail t_unit t_twice
569ret false
570end
571psn t_b1
572sz = fsize
573psn t_b1
574if not fhash
575ofail t_unit t_big
576ret false
577end
578ot t_ok
579ot t_unit
580onm
581ot t_bytes
582onum sz
583ot t_sha
584ohex
585onl
586put g_n 8 add get g_n 8 1
587ret true
588end
589note one table row [s, e): NAME then parts; # starts a comment line; an empty line is skipped
590fn urow s ulong e ulong to void
591if or eq s e eq get g_u s 35
592ret
593end
594put g_n 14 0
595k = s
596while uisnt k e 32 bound 1048576
597k = add k 1
598end
599if or ge k e or eq k s gt sub k s 249
600ofail t_unit t_row
601ret
602end
603for q ulong sub k s bound 256
604put g_nm q get g_u add s q
605end
606put g_n 14 sub k s
607put g_n 16 add get g_n 16 1
608if not nameok
609ofail t_unit t_badname
610ret
611end
612if not nameadd
613ofail t_unit t_dup
614ret
615end
616if compose k e
617z = build
618end
619end
620note a unit name uses only A-Z a-z 0-9 _ (A-Z a-z 0-9 _), so it names a file in SCRATCH
621fn nameok to bool
622for q ulong get g_n 14 bound 256
623c = get g_nm q
624d = and ge c 48 le c 57
625u = and ge c 65 le c 90
626l = and ge c 97 le c 122
627ok = or or d u or l eq c 95
628if not ok
629ret false
630end
631end
632ret true
633end
634note record the name in g_seen (names joined by newlines); false when it is already there or g_seen is full
635fn nameadd to bool
636n = get g_n 15
637m = get g_n 14
638p = ulong 0
639while lt p n bound 65536
640q = p
641while and lt q n ne get g_seen q 10 bound 65536
642q = add q 1
643end
644if nameat p q
645ret false
646end
647p = add q 1
648end
649if ge add add n m 1 len g_seen
650ret false
651end
652for j ulong m bound 256
653put g_seen add n j get g_nm j
654end
655put g_seen add n m 10
656put g_n 15 add add n m 1
657ret true
658end
659note g_seen[p, q) equals the current name
660fn nameat p ulong q ulong to bool
661if ne sub q p get g_n 14
662ret false
663end
664for j ulong sub q p bound 256
665if ne get g_seen add p j get g_nm j
666ret false
667end
668end
669ret true
670end
671fn table to bool
672pclr
673pt t_tab
674put g_n 6 0
675if not bload
676ret false
677end
678n = get g_n 6
679if ge n len g_u
680ret false
681end
682for q ulong n bound 1048576
683put g_u q get g_b q
684end
685put g_n 7 n
686s = ulong 0
687while lt s n bound 1048576
688e = s
689while uisnt e n 10 bound 1048576
690e = add e 1
691end
692urow s e
693s = add e 1
694end
695if eq get g_n 16 0
696nmset t_tab
697ofail t_unit t_empty
698end
699ret true
700end
701note ---- controls
702fn caught c bool what view uchar * to void
703put g_n 12 add get g_n 12 1
704nmset what
705if c
706ot t_ok
707ot t_ctl
708onm
709ot t_caught
710onl
711put g_n 13 add get g_n 13 1
712else
713ofail t_ctl t_esc
714end
715end
716note a compiler one byte longer must fail the digest check
717fn cwrong to void
718pclr
719for j ulong get g_n 1 bound 4096
720pc ulong get g_omc j
721end
722put g_n 6 0
723ok = bload
724n = get g_n 6
725put g_b n 0
726put g_n 6 add n 1
727psc t_plus
728ok = and ok bsave true
729psc t_plus
730c = and ok not pinok
731caught c t_plus
732end
733note ---- main
734fn ausage to int
735r = write 2 t_usage 0 len t_usage
736ret 2
737end
738fn cre1 t view uchar * to void
739fd = fopen t 0 len t int 524288 int 0
740if ge fd 0
741x = fclose int fd
742put g_n 11 add get g_n 11 1
743ot t_fail
744ot t_remsg
745ot t
746oc 10
747oflush
748end
749end
750fn creimp to void
751cre1 t_re1
752cre1 t_re2
753cre1 t_re3
754cre1 t_re4
755end
756fn main to int
757if ne argcnt 3
758ret ausage
759end
760r = argread 1 g_omc 0 4095
761if lt r 1
762ret ausage
763end
764put g_n 1 ulong r
765if not pinread
766r = write 2 t_nopin 0 len t_nopin
767ret 2
768end
769pclr
770for j ulong get g_n 1 bound 4096
771pc ulong get g_omc j
772end
773if not pinok
774r = write 2 t_refd 0 len t_refd
775ret 69
776end
777r = argread 2 g_scr 0 4094
778if lt r 1
779ret ausage
780end
781if gt r 1024
782r = write 2 t_long 0 len t_long
783ret 2
784end
785n = ulong r
786x = makedir g_scr 0 n 448
787if ne x 0
788r = write 2 t_noscr 0 len t_noscr
789ret 2
790end
791put g_scr n 47
792put g_n 2 add n 1
793if not table
794r = write 2 t_notab 0 len t_notab
795ret 2
796end
797creimp
798cwrong
799f = get g_n 11
800ot t_sum
801if eq f 0
802ot t_pass
803else
804ot t_fl
805end
806ot t_su
807onum get g_n 8
808ot t_sc
809onum get g_n 12
810ot t_sk
811onum get g_n 13
812ot t_hw
813oflush
814if ne f 0
815ret 1
816end
817if ne get g_n 12 get g_n 13
818ret 1
819end
820ret 0
821end