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