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/seed/ng/front/gate-front.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 / seed / ng / front / gate-front.om` 1751 lines ยท 31262 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 2 note seed/ng/front/gate-front.om: the differential front gate of ng-front (Hive NG; DECISIONS D5, D6, D9). 3 note Handwritten seeded Omega, program mode, Linux AArch64, built by the pinned seed/out/omc. The child, 4 note segment and SHA-256 helpers follow seed/qualification/om2/gate.om; its SHA-256 constants are read 5 note from that directory's bc-derived fixtures, never typed here. 6 note 7 note Run from the repository root: 8 note gate-front OMC OMC_SHA256 SRC DECLARED MUTANTS SCRATCH CASES [CASES ...] 9 note OMC the oracle compiler; its sha256 must be OMC_SHA256 (64 lowercase hex) or no case runs (INVALID) 10 note SRC the checker source: segments joined by + (a path, pack:PATH:OFF:LEN, cyc:PATH:N, units:LIST for 11 note the units of an ng.units-form list in its order) concatenated in 12 note order; OMC compiles it to SCRATCH/fecheck. The checker reads one unit on stdin, writes nothing 13 note on stdout, or exactly what omc writes there (om2 diagnostics, check mode), and exits 0 14 note (accepted) or as omc refuses (stderr `omc: line N: error K`, exit K). A segment in:PATH is not 15 note source: the bytes of PATH (4096 at most) go before each case on the checker's stdin only (the 16 note mode line of the ng unit, `@ng front-check`); omc reads the case alone. 17 note DECLARED lines `NAME beyond K REASON...`: omc refuses NAME with exit K for a code-generator limit (12, 14, 18 note 24 or 25) and the checker must accept it (BEYOND_OMC, D6); `NAME scope K REASON...`: a unit form 19 note this front end does not take yet; omc must exit K and the checker 64; `NAME ngonly K REASON...`: 20 note a bound of the checker's own that omc reaches through another limit first; both must exit K 21 note (stderr not compared: the lines differ); `NAME ngcap K REASON...`: an input the checker refuses 22 note with exit K at one of ng's own fixed tables (REASON names it) that omc, which has no table 23 note capacities since 2026-11-11 (OMEGESE 9.6), takes past it: the checker must exit K and omc a 24 note status other than K below 100. Every ngcap row is counted on a line of its own before the 25 note verdict (NGCAP), so the gap stays visible until ng's tables are lifted, and a row whose input 26 note the checker accepts fails. K is decimal, 0-255. Every listed NAME must be a case. 27 note MUTANTS lines `NAME FROM TO`: SRC with the bytes of file FROM (present exactly once) replaced by the bytes 28 note of file TO, compiled to SCRATCH/NAME. KILLED when some case FAILs under it, else SURVIVED. 29 note SCRATCH a new directory (created 0700; an existing one is INVALID) 30 note CASES lines `NAME SRC`, or the C2 manifest form `NAME emit SRC ...`; lines starting with # and blank 31 note lines are skipped, and so is a line whose first word is `deadline`. 32 note A case is exact unless DECLARED: PASS needs equal exit status and equal stderr bytes from omc and the 33 note checker (all of them: each stderr has its own descriptor and the two are compared in 65536-byte 34 note chunks), and an empty checker stdout or one equal to omc's. The last line is the verdict: 35 note NGCAP ng still refuses C inputs omc accepts: ng front's fixed tables (declared ngcap rows) [when C > 0] 36 note FRONTGATE PASS|FAIL|INVALID cases=N exact=E beyond=B scope=S ngonly=O ngcap=C fail=F mutants=M killed=K 37 note Exit 0 PASS, 1 FAIL (any failing case, unused declaration or surviving mutant), 2 INVALID. 38 39 text msg "FRONTGATE PASS\nFRONTGATE FAIL\nFRONTGATE INVALID\n cases=\n exact=\n beyond=\n scope=\n fail=\n mutants=\n killed=\nFAIL \n omc=\n ng=\n omc stderr: \n ng stderr: \n ng wrote stdout\nKILLED \n at \nSURVIVED \nUNUSED declared \nINVALID: \nusage: gate-front OMC OMC_SHA256 SRC DECLARED MUTANTS SCRATCH CASES [CASES ...]\noracle sha256 differs from OMC_SHA256\nSHA-256 fixture unreadable\nscratch exists or cannot be made\nchecker build failed, omc exit=\nmutant build failed: \nsource unreadable, malformed or too large: \nlist file unreadable or too large: \nfork, memfd or descriptor failure\nchild deadline exceeded\nmutant FROM not present exactly once: \nORACLE \nCHECKER \n sha256=\nmalformed declared line: \n ngonly=\nmalformed mutant line\n ngcap=\nNGCAP ng still refuses \n inputs omc accepts: ng front's fixed tables (declared ngcap rows)\n" 40 text words "pack:\ncyc:\nemit\ndeadline\nbeyond\nscope\nfecheck\n/\n.om\n/dev/null\nseed/qualification/om2/fixtures/sha256-k.dec\nseed/qualification/om2/fixtures/sha256-iv.dec\nin:\nunits:\nngonly\nngcap\n" 41 global ub uchar 65536 42 43 global ar uchar 65536 44 global ao ulong 64 45 global al ulong 64 46 global na ulong 1 47 global tb uchar 4096 48 global tn ulong 1 49 global pb uchar 4096 50 global pn ulong 1 51 global av uchar 8192 52 global ap ulong 2 53 global big uchar `16777216` 54 global bgn ulong 1 55 global cs uchar `16777216` 56 global csn ulong 1 57 global lst uchar `4194304` 58 global lsn ulong 1 59 global dec uchar `1048576` 60 global dnm uchar 262144 61 global dnn ulong 1 62 global dcn ulong 1 63 global dno ulong 4096 64 global dnl ulong 4096 65 global dcl uchar 4096 66 global dcd uchar 4096 67 global dus uchar 4096 68 global dhit ulong 1 69 global ndc ulong 1 70 global tko ulong 16 71 global tkl ulong 16 72 global ntk ulong 1 73 global eo uchar 65536 74 global eon ulong 1 75 global eg uchar 65536 76 global ob uchar 65536 77 global egn ulong 1 78 global buf uchar 65536 79 global stb uchar 4 80 global fds int 6 81 global pfx uchar 4096 82 global pfn ulong 1 83 global bad ulong 1 84 global cnt ulong 9 85 global dig uchar 32 86 global wpos ulong 2 87 global nums ulong 64 88 global kk uint 64 89 global ivs uint 8 90 global hv uint 8 91 global ws uint 64 92 global st uint 8 93 global blk uchar 64 94 global bk ulong 2 95 global hexd uchar 64 96 global mode ulong 1 97 global hit ulong 1 98 global nfl ulong 1 99 global chk uchar 4096 100 global chn ulong 1 101 102 note ---- output ---------------------------------------------------------------------------------- 103 fn seg id ulong to void 104 k = ulong 1 105 s = ulong 0 106 for i ulong len msg 107 if eq get msg i 10 108 if eq k id 109 put wpos 0 s 110 put wpos 1 sub i s 111 ret 112 end 113 k = add k 1 114 s = add i 1 115 end 116 end 117 exit 99 118 end 119 fn say id ulong to void 120 seg id 121 r = write 1 msg get wpos 0 get wpos 1 122 end 123 fn newline to void 124 put dig 0 10 125 r = write 1 dig 0 1 126 end 127 fn num v ulong to void 128 x = v 129 n = ulong 0 130 while ge x 10 bound 32 131 put dig n uchar add 48 rem x 10 132 x = div x 10 133 n = add n 1 134 end 135 put dig n uchar add 48 x 136 n = add n 1 137 for i ulong n 138 r = write 1 dig sub sub n i 1 1 139 end 140 end 141 fn showarg k ulong to void 142 r = write 1 ar get ao k get al k 143 end 144 fn showtok t ulong to void 145 r = write 1 lst get tko t get tkl t 146 end 147 fn showtb to void 148 r = write 1 tb 0 get tn 0 149 end 150 fn showpb to void 151 r = write 1 pb 0 get pn 0 152 end 153 note the first line of a captured stderr (at most 200 bytes) 154 fn showeo to void 155 n = get eon 0 156 i = ulong 0 157 while and lt i n lt i 200 bound 256 158 if eq get eo i 10 159 n = i 160 else 161 i = add i 1 162 end 163 end 164 r = write 1 eo 0 i 165 end 166 fn showeg to void 167 n = get egn 0 168 i = ulong 0 169 while and lt i n lt i 200 bound 256 170 if eq get eg i 10 171 n = i 172 else 173 i = add i 1 174 end 175 end 176 r = write 1 eg 0 i 177 end 178 fn setbad id ulong to void 179 if eq get bad 0 0 180 put bad 0 id 181 end 182 end 183 184 note ---- fixed words ------------------------------------------------------------------------------ 185 fn wordat id ulong to void 186 k = ulong 1 187 s = ulong 0 188 for i ulong len words 189 if eq get words i 10 190 if eq k id 191 put wpos 0 s 192 put wpos 1 sub i s 193 ret 194 end 195 k = add k 1 196 s = add i 1 197 end 198 end 199 exit 99 200 end 201 note tb[o .. o+n) starts with word id 202 fn tbpre o ulong n ulong id ulong to bool 203 wordat id 204 k = get wpos 1 205 if lt n k 206 ret false 207 end 208 s = get wpos 0 209 for i ulong k 210 if ne get tb add o i get words add s i 211 ret false 212 end 213 end 214 ret true 215 end 216 note tb[o .. o+n) is word id 217 fn tbis o ulong n ulong id ulong to bool 218 wordat id 219 if ne n get wpos 1 220 ret false 221 end 222 ret tbpre o n id 223 end 224 225 note ---- the scratch buffer tb (one token, argument or path at a time) ---------------------------- 226 fn tbclr to void 227 put tn 0 0 228 end 229 fn tbbyte b uchar to void 230 n = get tn 0 231 if ge n 4095 232 setbad 28 233 ret 234 end 235 put tb n b 236 put tn 0 add n 1 237 end 238 fn tbarg k ulong to void 239 tbclr 240 o = get ao k 241 for i ulong get al k 242 tbbyte get ar add o i 243 end 244 end 245 fn tbtok t ulong to void 246 tbclr 247 o = get tko t 248 for i ulong get tkl t 249 tbbyte get lst add o i 250 end 251 end 252 fn tbdec o ulong n ulong to void 253 tbclr 254 for i ulong n 255 tbbyte get dec add o i 256 end 257 end 258 note declared names live in dnm, apart from dec, which the mutant list later reuses 259 fn tbdnm o ulong n ulong to void 260 tbclr 261 for i ulong n 262 tbbyte get dnm add o i 263 end 264 end 265 266 note ---- paths -------------------------------------------------------------------------------------- 267 fn pclear to void 268 put pn 0 0 269 end 270 fn pbyte b uchar to void 271 n = get pn 0 272 if ge n 4095 273 setbad 30 274 ret 275 end 276 put pb n b 277 put pn 0 add n 1 278 end 279 fn ptb o ulong n ulong to void 280 for i ulong n 281 pbyte get tb add o i 282 end 283 end 284 fn pword id ulong to void 285 wordat id 286 s = get wpos 0 287 for i ulong get wpos 1 288 pbyte get words add s i 289 end 290 end 291 fn parg k ulong to void 292 o = get ao k 293 for i ulong get al k 294 pbyte get ar add o i 295 end 296 end 297 note SCRATCH/ followed by tb (a mutant name) or by a fixed word 298 fn pscr to void 299 pclear 300 parg 6 301 pword 8 302 end 303 fn popen fl int to int 304 r = fopen pb 0 get pn 0 fl 448 305 if lt r 0 306 ret -1 307 end 308 ret int r 309 end 310 fn fclo fd int to void 311 if ge fd 0 312 r = fclose fd 313 end 314 end 315 316 note ---- decimal fields ------------------------------------------------------------------------------- 317 fn tbnum o ulong n ulong to ulong 318 if or eq n 0 gt n 19 319 setbad 28 320 ret 0 321 end 322 v = ulong 0 323 for i ulong n 324 c = get tb add o i 325 if or lt c 48 gt c 57 326 setbad 28 327 ret 0 328 end 329 v = add mul v 10 ulong sub c 48 330 end 331 ret v 332 end 333 fn tblastc o ulong n ulong to ulong 334 i = n 335 while gt i 0 bound 4096 336 i = sub i 1 337 if eq get tb add o i 58 338 ret i 339 end 340 end 341 ret n 342 end 343 344 note ---- sources into big ------------------------------------------------------------------------------ 345 fn bigpre fd int off ulong k ulong to bool 346 b = get bgn 0 347 done = ulong 0 348 while lt done k bound 100000 349 c = sub k done 350 if gt c `1048576` 351 c = ulong `1048576` 352 end 353 r = pread fd big add b done c long add off done 354 if le r 0 355 ret false 356 end 357 done = add done ulong r 358 end 359 ret true 360 end 361 fn addpack o ulong n ulong to void 362 q = tblastc o n 363 if ge q n 364 setbad 28 365 ret 366 end 367 p = tblastc o q 368 if ge p q 369 setbad 28 370 ret 371 end 372 k = tbnum add add o q 1 sub sub n q 1 373 off = tbnum add add o p 1 sub sub q p 1 374 if ne get bad 0 0 375 ret 376 end 377 if gt k sub len big get bgn 0 378 setbad 28 379 ret 380 end 381 pclear 382 ptb o p 383 fd = popen 524288 384 if lt fd 0 385 setbad 28 386 ret 387 end 388 ok = bigpre fd off k 389 fclo fd 390 if not ok 391 setbad 28 392 ret 393 end 394 put bgn 0 add get bgn 0 k 395 end 396 fn cycrow b ulong s ulong c ulong m ulong to void 397 for i ulong c 398 put big add add b s i get buf rem add s i m 399 end 400 end 401 fn addcyc o ulong n ulong to void 402 q = tblastc o n 403 if ge q n 404 setbad 28 405 ret 406 end 407 k = tbnum add add o q 1 sub sub n q 1 408 if ne get bad 0 0 409 ret 410 end 411 if gt k sub len big get bgn 0 412 setbad 28 413 ret 414 end 415 pclear 416 ptb o q 417 fd = popen 524288 418 if lt fd 0 419 setbad 28 420 ret 421 end 422 r = read fd buf 0 len buf 423 fclo fd 424 if or le r 0 ge r long len buf 425 setbad 28 426 ret 427 end 428 m = ulong r 429 b = get bgn 0 430 for row ulong add div k 65536 1 431 s = mul row 65536 432 c = sub k s 433 if gt c 65536 434 c = ulong 65536 435 end 436 cycrow b s c m 437 end 438 put bgn 0 add b k 439 end 440 fn addfile o ulong n ulong to void 441 pclear 442 ptb o n 443 addpb 444 end 445 note the file at the path in pb appended to big 446 fn addpb to void 447 fd = popen 524288 448 if lt fd 0 449 setbad 28 450 ret 451 end 452 go = true 453 while go bound 100000 454 b = get bgn 0 455 if ge b len big 456 setbad 28 457 go = false 458 else 459 r = read fd big b sub len big b 460 if lt r 0 461 setbad 28 462 go = false 463 else 464 if eq r 0 465 go = false 466 else 467 put bgn 0 add b ulong r 468 end 469 end 470 end 471 end 472 fclo fd 473 end 474 note in:PATH: the bytes of PATH into pfx (the checker's stdin prefix), not into big 475 fn addpfx o ulong n ulong to void 476 b0 = get bgn 0 477 addfile o n 478 k = sub get bgn 0 b0 479 if gt k len pfx 480 setbad 28 481 k = ulong 0 482 end 483 for i ulong k 484 put pfx i get big add b0 i 485 end 486 put pfn 0 k 487 put bgn 0 b0 488 end 489 note units:PATH: each line `SHA256 PATH` of the units list at PATH (the seed/ng/ng.units form) as a path 490 note segment, in order; the pins are ngbuild's to check, not this gate's 491 fn addunit o ulong n ulong to void 492 pclear 493 ptb o n 494 fd = popen 524288 495 if lt fd 0 496 setbad 28 497 ret 498 end 499 r = read fd ub 0 len ub 500 fclo fd 501 if or le r 0 ge r long len ub 502 setbad 28 503 ret 504 end 505 m = ulong r 506 s = ulong 0 507 for i ulong add m 1 508 if or eq i m eq get ub i 10 509 unitln s i 510 s = add i 1 511 end 512 end 513 end 514 note the unit on the list line ub[s, e) (64 hex digits, a space, the path); an empty line adds nothing 515 fn unitln s ulong e ulong to void 516 if eq s e 517 ret 518 end 519 if le e add s 65 520 setbad 28 521 ret 522 end 523 pclear 524 for i ulong sub e add s 65 525 pbyte get ub add add s 65 i 526 end 527 addpb 528 end 529 fn addseg o ulong n ulong to void 530 if tbpre o n 14 531 addunit add o 6 sub n 6 532 ret 533 end 534 if tbpre o n 13 535 addpfx add o 3 sub n 3 536 ret 537 end 538 if tbpre o n 1 539 addpack add o 5 sub n 5 540 ret 541 end 542 if tbpre o n 2 543 addcyc add o 4 sub n 4 544 ret 545 end 546 addfile o n 547 end 548 note the +-joined source spec in tb, appended to big 549 fn addsrc to void 550 n = get tn 0 551 s = ulong 0 552 for i ulong add n 1 553 if or eq i n eq get tb i 43 554 if eq i s 555 setbad 28 556 else 557 addseg s sub i s 558 end 559 s = add i 1 560 end 561 end 562 end 563 564 note ---- whole files into lst / dec -------------------------------------------------------------------- 565 fn readlst to bool 566 fd = popen 524288 567 if lt fd 0 568 ret false 569 end 570 n = ulong 0 571 go = true 572 while go bound 100000 573 r = read fd lst n sub len lst n 574 if le r 0 575 go = false 576 if lt r 0 577 n = len lst 578 end 579 else 580 n = add n ulong r 581 if ge n len lst 582 go = false 583 end 584 end 585 end 586 fclo fd 587 put lsn 0 n 588 ret lt n len lst 589 end 590 fn readdec to bool 591 fd = popen 524288 592 if lt fd 0 593 ret false 594 end 595 n = ulong 0 596 go = true 597 while go bound 100000 598 r = read fd dec n sub len dec n 599 if le r 0 600 go = false 601 if lt r 0 602 n = len dec 603 end 604 else 605 n = add n ulong r 606 if ge n len dec 607 go = false 608 end 609 end 610 end 611 fclo fd 612 put dcn 0 n 613 ret lt n len dec 614 end 615 616 note lst[j] is inside the line (j < e) and not a blank 617 fn intok j ulong e ulong to bool 618 c = get lst j 619 ret and lt j e and ne c 32 ne c 9 620 end 621 note ---- tokens of lst[s .. e) ------------------------------------------------------------------------- 622 fn tokenize s ulong e ulong to void 623 put ntk 0 0 624 i = s 625 while lt i e bound `4194304` 626 c = get lst i 627 if or eq c 32 eq c 9 628 i = add i 1 629 else 630 t = get ntk 0 631 j = i 632 while intok j e bound `4194304` 633 j = add j 1 634 end 635 if lt t 16 636 put tko t i 637 put tkl t sub j i 638 put ntk 0 add t 1 639 end 640 i = j 641 end 642 end 643 end 644 fn lineend p ulong to ulong 645 n = get lsn 0 646 i = p 647 while and lt i n ne get lst i 10 bound `4194304` 648 i = add i 1 649 end 650 ret i 651 end 652 653 note ---- declared table ---------------------------------------------------------------------------------- 654 note dtok: the next word of dec at or after p, as (offset, length) in wpos; stops at a newline 655 fn dword p ulong e ulong to void 656 i = p 657 while and lt i e dblank i bound `1048576` 658 i = add i 1 659 end 660 j = i 661 while and lt j e not dblank j bound `1048576` 662 j = add j 1 663 end 664 put wpos 0 i 665 put wpos 1 sub j i 666 end 667 fn dblank i ulong to bool 668 c = get dec i 669 ret or eq c 32 eq c 9 670 end 671 fn loaddec to bool 672 n = get dcn 0 673 p = ulong 0 674 while lt p n bound `1048576` 675 e = p 676 while and lt e n ne get dec e 10 bound `1048576` 677 e = add e 1 678 end 679 dword p e 680 o = get wpos 0 681 l = get wpos 1 682 if and gt l 0 ne get dec o 35 683 k = get ndc 0 684 if ge k 4096 685 ret false 686 end 687 dword add o l e 688 co = get wpos 0 689 cl = get wpos 1 690 tbdec co cl 691 c = ulong 0 692 if tbis 0 get tn 0 5 693 c = ulong 1 694 end 695 if tbis 0 get tn 0 6 696 c = ulong 2 697 end 698 if tbis 0 get tn 0 15 699 c = ulong 3 700 end 701 if tbis 0 get tn 0 16 702 c = ulong 4 703 end 704 dword add co cl e 705 tbdec get wpos 0 get wpos 1 706 v = tbcode 707 if or eq c 0 gt v 255 708 say 36 709 tbdec o l 710 showtb 711 newline 712 put bad 0 36 713 ret false 714 end 715 if not dnmadd k o l 716 ret false 717 end 718 put dnl k l 719 put dcl k uchar c 720 put dcd k uchar v 721 put dus k 0 722 put ndc 0 add k 1 723 end 724 p = add e 1 725 end 726 ret true 727 end 728 note tb is a decimal exit code 0-255: its value, else 1000 729 fn tbcode to ulong 730 n = get tn 0 731 if or eq n 0 gt n 3 732 ret 1000 733 end 734 v = ulong 0 735 for i ulong n 736 c = get tb i 737 if or lt c 48 gt c 57 738 ret 1000 739 end 740 v = add mul v 10 ulong sub c 48 741 end 742 ret v 743 end 744 note the declared class of case token 0 (0 exact, 1 beyond, 2 scope, 3 ngonly, 4 ngcap), marking the entry used and 745 note keeping its index in dhit 746 fn dclass to ulong 747 o = get tko 0 748 l = get tkl 0 749 for k ulong get ndc 0 750 if eq get dnl k l 751 if dsame get dno k o l 752 put dus k 1 753 put dhit 0 k 754 ret ulong get dcl k 755 end 756 end 757 end 758 ret 0 759 end 760 note copy declared name dec[o .. o+l) into dnm as entry k's name; false when dnm is full 761 fn dnmadd k ulong o ulong l ulong to bool 762 s = get dnn 0 763 if gt add s l len dnm 764 ret false 765 end 766 for i ulong l 767 put dnm add s i get dec add o i 768 end 769 put dnn 0 add s l 770 put dno k s 771 ret true 772 end 773 note dnm[d .. d+l) equals lst[o .. o+l) 774 fn dsame d ulong o ulong l ulong to bool 775 for i ulong l 776 if ne get dnm add d i get lst add o i 777 ret false 778 end 779 end 780 ret true 781 end 782 783 note ---- children ----------------------------------------------------------------------------------------- 784 fn aclear to void 785 put ap 0 2 786 put ap 1 0 787 end 788 fn ahead n ulong to void 789 p = get ap 0 790 if gt add add p n 2 len av 791 setbad 30 792 ret 793 end 794 put av p uchar and n 255 795 put av add p 1 uchar shr n 8 796 put ap 0 add p 2 797 put ap 1 add get ap 1 1 798 end 799 fn apb to void 800 n = get pn 0 801 ahead n 802 p = get ap 0 803 if le add p n len av 804 for i ulong n 805 put av add p i get pb i 806 end 807 put ap 0 add p n 808 end 809 end 810 fn redir s int d int to void 811 if ne s d 812 if ne dupfd s d 0 long d 813 exit 127 814 end 815 end 816 end 817 note wait for pid: its exit status, 256 + the signal, or 1000 when the deadline (900 s) passed and it was killed 818 fn reap pid int to ulong 819 t0 = monons 820 while true bound `1000000000` 821 r = waitpid pid stb 0 len stb 1 822 if eq r long pid 823 if ne get stb 0 0 824 ret add 256 ulong get stb 0 825 end 826 ret ulong get stb 1 827 end 828 if lt r 0 829 setbad 30 830 ret 999 831 end 832 now = monons 833 if gt sub now t0 `900000000000` 834 r = killpid pid 9 835 r = waitpid pid stb 0 len stb 0 836 setbad 31 837 ret 1000 838 end 839 q = sleepns 100000 840 end 841 ret 999 842 end 843 fn spawn fi int fo int fe int to ulong 844 put av 0 uchar and get ap 1 255 845 put av 1 uchar shr get ap 1 8 846 if ne fseek fi 0 0 0 847 setbad 30 848 ret 999 849 end 850 pid = fork 851 if lt pid 0 852 setbad 30 853 ret 999 854 end 855 if eq pid 0 856 redir fi 0 857 redir fo 1 858 redir fe 2 859 r = execprog av 0 get ap 0 860 exit 127 861 end 862 ret reap int pid 863 end 864 note reset descriptor fd to an empty file 865 fn empty fd int to void 866 if ne ftrunc fd 0 0 867 setbad 30 868 end 869 if ne fseek fd 0 0 0 870 setbad 30 871 end 872 end 873 note the first 65536 bytes of a captured stderr, omc's (fds[5]) into eo, the checker's (fds[1]) into eg, for the 874 note FAIL lines only; the comparison is samefd over the whole of both descriptors 875 fn grab fd int to ulong 876 if ne fseek fd 0 0 0 877 setbad 30 878 ret 0 879 end 880 n = ulong 0 881 go = true 882 while go bound 100000 883 r = read fd buf n sub len buf n 884 if le r 0 885 go = false 886 else 887 n = add n ulong r 888 if ge n len buf 889 go = false 890 end 891 end 892 end 893 ret n 894 end 895 fn grabo to void 896 n = grab get fds 5 897 for i ulong n 898 put eo i get buf i 899 end 900 put eon 0 n 901 end 902 fn grabg to void 903 n = grab get fds 1 904 for i ulong n 905 put eg i get buf i 906 end 907 put egn 0 n 908 end 909 note big into descriptor fds[0]; with an in: prefix also pfx then big into fds[4] (the checker's stdin) 910 fn putsrc to void 911 fd = get fds 0 912 empty fd 913 wrbig fd 914 p = get pfn 0 915 if gt p 0 916 f4 = get fds 4 917 empty f4 918 k = ulong 0 919 while lt k p bound 100000 920 r = write f4 pfx k sub p k 921 if le r 0 922 setbad 30 923 ret 924 end 925 k = add k ulong r 926 end 927 wrbig f4 928 end 929 end 930 fn wrbig fd int to void 931 n = get bgn 0 932 off = ulong 0 933 while lt off n bound 100000 934 r = write fd big off sub n off 935 if le r 0 936 setbad 30 937 ret 938 end 939 off = add off ulong r 940 end 941 end 942 943 note ---- SHA-256 (FIPS 180-4), as seed/qualification/om2/gate.om ----------------------------------------- 944 fn rotr x uint n uint to uint 945 ret or shr x n shl x sub 32 n 946 end 947 fn shasched to void 948 for i ulong 16 949 b = mul i 4 950 v = shl uint get blk b 24 951 v = or v shl uint get blk add b 1 16 952 v = or v shl uint get blk add b 2 8 953 v = or v uint get blk add b 3 954 put ws i v 955 end 956 for j ulong 48 957 q = add j 16 958 x = get ws sub q 15 959 y = get ws sub q 2 960 s0 = xor xor rotr x 7 rotr x 18 shr x 3 961 s1 = xor xor rotr y 17 rotr y 19 shr y 10 962 put ws q add add add get ws sub q 16 s0 get ws sub q 7 s1 963 end 964 end 965 fn shat1 i ulong to uint 966 e = get st 4 967 s1 = xor xor rotr e 6 rotr e 11 rotr e 25 968 ch = xor and e get st 5 and not e get st 6 969 ret add add add add get st 7 s1 ch get kk i get ws i 970 end 971 fn shat2 to uint 972 a = get st 0 973 b = get st 1 974 c = get st 2 975 s0 = xor xor rotr a 2 rotr a 13 rotr a 22 976 mj = xor xor and a b and a c and b c 977 ret add s0 mj 978 end 979 fn shacomp to void 980 shasched 981 for i ulong 8 982 put st i get hv i 983 end 984 for i ulong 64 985 t1 = shat1 i 986 t2 = shat2 987 put st 7 get st 6 988 put st 6 get st 5 989 put st 5 get st 4 990 put st 4 add get st 3 t1 991 put st 3 get st 2 992 put st 2 get st 1 993 put st 1 get st 0 994 put st 0 add t1 t2 995 end 996 for i ulong 8 997 put hv i add get hv i get st i 998 end 999 end 1000 fn shabyte b uchar to void 1001 n = get bk 0 1002 put blk n b 1003 n = add n 1 1004 if eq n 64 1005 shacomp 1006 n = ulong 0 1007 end 1008 put bk 0 n 1009 put bk 1 add get bk 1 1 1010 end 1011 fn hexch v uint to uchar 1012 if lt v 10 1013 ret uchar add v 48 1014 end 1015 ret uchar add v 87 1016 end 1017 fn shafinal to void 1018 bits = mul get bk 1 8 1019 shabyte 128 1020 while ne get bk 0 56 bound 64 1021 shabyte 0 1022 end 1023 for i ulong 8 1024 shabyte uchar and shr bits mul sub 7 i 8 255 1025 end 1026 for i ulong 8 1027 v = get hv i 1028 for j ulong 8 1029 put hexd add mul i 8 j hexch and shr v mul sub 7 j 4 15 1030 end 1031 end 1032 end 1033 note hash the file named by pb into hexd; false when it cannot be read 1034 fn hashfile to bool 1035 fd = popen 524288 1036 if lt fd 0 1037 ret false 1038 end 1039 for i ulong 8 1040 put hv i get ivs i 1041 end 1042 put bk 0 0 1043 put bk 1 0 1044 while true bound `100000000` 1045 r = read fd buf 0 len buf 1046 if lt r 0 1047 fclo fd 1048 ret false 1049 end 1050 if eq r 0 1051 fclo fd 1052 shafinal 1053 ret true 1054 end 1055 for i ulong ulong r 1056 shabyte get buf i 1057 end 1058 end 1059 ret false 1060 end 1061 note decimal numbers below 2^32, one per line, exactly want of them, from fixed word id into nums 1062 fn loadnums id ulong want ulong to bool 1063 pclear 1064 pword id 1065 fd = popen 524288 1066 if lt fd 0 1067 ret false 1068 end 1069 r = read fd buf 0 len buf 1070 fclo fd 1071 if or le r 0 ge r long len buf 1072 ret false 1073 end 1074 k = ulong 0 1075 v = ulong 0 1076 nd = ulong 0 1077 for i ulong ulong r 1078 c = get buf i 1079 if and ge c 48 le c 57 1080 if ge nd 10 1081 ret false 1082 end 1083 v = add mul v 10 ulong sub c 48 1084 nd = add nd 1 1085 else 1086 if or ne c 10 eq nd 0 1087 ret false 1088 end 1089 if or ge k want gt v `4294967295` 1090 ret false 1091 end 1092 put nums k v 1093 k = add k 1 1094 v = ulong 0 1095 nd = ulong 0 1096 end 1097 end 1098 ret and eq nd 0 eq k want 1099 end 1100 fn showhex to void 1101 r = write 1 hexd 0 64 1102 end 1103 1104 note ---- building --------------------------------------------------------------------------------------------- 1105 note write big to pb (created 0700) 1106 fn bigfile to bool 1107 fd = popen 524865 1108 if lt fd 0 1109 ret false 1110 end 1111 n = get bgn 0 1112 off = ulong 0 1113 while lt off n bound 100000 1114 r = write fd big off sub n off 1115 if le r 0 1116 fclo fd 1117 ret false 1118 end 1119 off = add off ulong r 1120 end 1121 fclo fd 1122 ret true 1123 end 1124 note compile the file at pb (big was written there) with OMC to pb without its .om suffix, which becomes 1125 note chk and pb again; omc's exit 1126 fn build to ulong 1127 fi = popen 524288 1128 if lt fi 0 1129 ret 999 1130 end 1131 put pn 0 sub get pn 0 3 1132 setchk 1133 fo = popen 524865 1134 if lt fo 0 1135 fclo fi 1136 ret 999 1137 end 1138 aclear 1139 pclear 1140 parg 1 1141 apb 1142 empty get fds 1 1143 x = spawn fi fo get fds 1 1144 fclo fi 1145 fclo fo 1146 pclear 1147 for i ulong get chn 0 1148 pbyte get chk i 1149 end 1150 ret x 1151 end 1152 1153 note descriptor b has the bytes of descriptor a, all of them (compared in 65536-byte chunks) 1154 fn samefd a int b int to bool 1155 if ne fseek a 0 2 fseek b 0 2 1156 ret false 1157 end 1158 if or ne fseek a 0 0 0 ne fseek b 0 0 0 1159 ret false 1160 end 1161 while true bound 1000 1162 r = read a buf 0 len buf 1163 if le r 0 1164 ret eq r 0 1165 end 1166 if not samechk b ulong r 1167 ret false 1168 end 1169 end 1170 ret false 1171 end 1172 note the next n bytes of fd b equal buf[0 .. n) 1173 fn samechk b int n ulong to bool 1174 k = ulong 0 1175 while lt k n bound 100000 1176 r = read b ob k sub n k 1177 if le r 0 1178 ret false 1179 end 1180 k = add k ulong r 1181 end 1182 for i ulong n 1183 if ne get ob i get buf i 1184 ret false 1185 end 1186 end 1187 ret true 1188 end 1189 note ---- one case ------------------------------------------------------------------------------------------------ 1190 note the checker's stdin: fds[4] (prefix and case) with an in: prefix, else fds[0] (the case, as omc reads it) 1191 fn chkin to int 1192 if gt get pfn 0 0 1193 ret get fds 4 1194 end 1195 ret get fds 0 1196 end 1197 note run the source in big through omc and through the checker at chk; judge the pair 1198 fn runcase cls ulong to bool 1199 putsrc 1200 aclear 1201 pclear 1202 parg 1 1203 apb 1204 empty get fds 5 1205 empty get fds 2 1206 xo = spawn get fds 0 get fds 2 get fds 5 1207 grabo 1208 aclear 1209 pclear 1210 for i ulong get chn 0 1211 pbyte get chk i 1212 end 1213 apb 1214 empty get fds 1 1215 empty get fds 3 1216 xn = spawn chkin get fds 3 get fds 1 1217 grabg 1218 sz = fseek get fds 3 0 2 1219 ok = false 1220 cd = ulong get dcd get dhit 0 1221 if eq cls 0 1222 ok = and eq xo xn samefd get fds 5 get fds 1 1223 end 1224 if eq cls 1 1225 ok = and eq xo cd eq xn 0 1226 end 1227 if eq cls 2 1228 ok = and eq xo cd eq xn 64 1229 end 1230 if eq cls 3 1231 ok = and eq xo cd eq xn cd 1232 end 1233 if eq cls 4 1234 ok = and and eq xn cd ne xo cd lt xo 100 1235 end 1236 if ne sz 0 1237 if not samefd get fds 2 get fds 3 1238 ok = false 1239 else 1240 sz = long 0 1241 end 1242 end 1243 if and not ok eq get mode 0 0 1244 put nfl 0 add get nfl 0 1 1245 if le get nfl 0 60 1246 say 11 1247 showtok 0 1248 say 12 1249 num xo 1250 say 13 1251 num xn 1252 if ne sz 0 1253 say 16 1254 end 1255 newline 1256 say 14 1257 showeo 1258 newline 1259 say 15 1260 showeg 1261 newline 1262 end 1263 end 1264 ret ok 1265 end 1266 note the cases of list file arg k; in mode 1 stop at the first failing case (kept in hit) and return false 1267 fn runlist k ulong to bool 1268 tbarg k 1269 pclear 1270 ptb 0 get tn 0 1271 if not readlst 1272 say 21 1273 say 29 1274 showpb 1275 newline 1276 put bad 0 29 1277 ret false 1278 end 1279 n = get lsn 0 1280 p = ulong 0 1281 while lt p n bound `4194304` 1282 e = lineend p 1283 tokenize p e 1284 t = get ntk 0 1285 skip = eq t 0 1286 if not skip 1287 c = get lst get tko 0 1288 skip = eq c 35 1289 end 1290 if not skip 1291 tbtok 0 1292 skip = tbis 0 get tn 0 4 1293 end 1294 if and not skip lt t 2 1295 skip = true 1296 end 1297 if not skip 1298 s = ulong 1 1299 if gt t 2 1300 tbtok 1 1301 if tbis 0 get tn 0 3 1302 s = ulong 2 1303 end 1304 end 1305 tbtok s 1306 put bgn 0 0 1307 addsrc 1308 if ne get bad 0 0 1309 say 21 1310 say 28 1311 showtok 0 1312 newline 1313 ret false 1314 end 1315 cls = dclass 1316 ok = runcase cls 1317 if ne get bad 0 0 1318 say 21 1319 say get bad 0 1320 showtok 0 1321 newline 1322 ret false 1323 end 1324 if eq get mode 0 0 1325 put cnt 0 add get cnt 0 1 1326 if ok 1327 ci = add cls 1 1328 if eq cls 3 1329 ci = ulong 7 1330 end 1331 if eq cls 4 1332 ci = ulong 8 1333 end 1334 put cnt ci add get cnt ci 1 1335 else 1336 put cnt 4 add get cnt 4 1 1337 end 1338 else 1339 if not ok 1340 put hit 0 p 1341 ret false 1342 end 1343 end 1344 end 1345 p = add e 1 1346 end 1347 ret true 1348 end 1349 1350 note ---- main ------------------------------------------------------------------------------------------------------ 1351 fn verdict v ulong to int 1352 if gt get cnt 8 0 1353 say 40 1354 num get cnt 8 1355 say 41 1356 newline 1357 end 1358 say v 1359 say 4 1360 num get cnt 0 1361 say 5 1362 num get cnt 1 1363 say 6 1364 num get cnt 2 1365 say 7 1366 num get cnt 3 1367 say 37 1368 num get cnt 7 1369 say 39 1370 num get cnt 8 1371 say 8 1372 num get cnt 4 1373 say 9 1374 num get cnt 5 1375 say 10 1376 num get cnt 6 1377 newline 1378 if eq v 1 1379 ret 0 1380 end 1381 if eq v 2 1382 ret 1 1383 end 1384 ret 2 1385 end 1386 fn invalid id ulong to int 1387 say 21 1388 say id 1389 newline 1390 ret verdict 3 1391 end 1392 fn loadargs to bool 1393 n = argcnt 1394 if or lt n 8 gt n 64 1395 ret false 1396 end 1397 o = ulong 0 1398 for i ulong ulong n 1399 r = argread i ar o sub len ar o 1400 if le r 0 1401 ret false 1402 end 1403 put ao i o 1404 put al i ulong r 1405 o = add o ulong r 1406 end 1407 put na 0 ulong n 1408 ret true 1409 end 1410 note run the mutants of file arg 5 against every case list; mode 1 1411 fn mutants to void 1412 tbarg 5 1413 pclear 1414 ptb 0 get tn 0 1415 if not readdec 1416 setbad 29 1417 ret 1418 end 1419 n = get dcn 0 1420 p = ulong 0 1421 while lt p n bound `1048576` 1422 e = p 1423 while and lt e n ne get dec e 10 bound `1048576` 1424 e = add e 1 1425 end 1426 dword p e 1427 mo = get wpos 0 1428 ml = get wpos 1 1429 if and gt ml 0 ne get dec mo 35 1430 onemut mo ml e 1431 if ne get bad 0 0 1432 ret 1433 end 1434 end 1435 p = add e 1 1436 end 1437 end 1438 note substitute and build one mutant (dec name at mo, ml; its FROM and TO words follow before e), then run it 1439 fn onemut mo ulong ml ulong e ulong to void 1440 dword add mo ml e 1441 fo = get wpos 0 1442 fl = get wpos 1 1443 dword add fo fl e 1444 tw = get wpos 0 1445 tl = get wpos 1 1446 if or eq fl 0 eq tl 0 1447 setbad 38 1448 ret 1449 end 1450 put cnt 5 add get cnt 5 1 1451 if not mutsub fo fl tw tl 1452 if eq get bad 0 0 1453 say 32 1454 tbdec mo ml 1455 showtb 1456 newline 1457 setbad 32 1458 end 1459 ret 1460 end 1461 tbdec mo ml 1462 pscr 1463 ptb 0 get tn 0 1464 pword 9 1465 if not bigfile 1466 setbad 30 1467 ret 1468 end 1469 x = build 1470 if ne x 0 1471 say 27 1472 showtb 1473 newline 1474 setbad 27 1475 ret 1476 end 1477 pscr 1478 ptb 0 get tn 0 1479 setchk 1480 mutrun mo ml 1481 pscr 1482 pword 7 1483 setchk 1484 end 1485 note the checker path chk = pb 1486 fn setchk to void 1487 for i ulong get pn 0 1488 put chk i get pb i 1489 end 1490 put chn 0 get pn 0 1491 end 1492 note big = cs with the bytes of file dec[fo, fl) replaced by those of file dec[tw, tl); false when the 1493 note first file is empty, longer than 65536 bytes, or not present in cs exactly once 1494 fn mutsub fo ulong fl ulong tw ulong tl ulong to bool 1495 tbdec fo fl 1496 put bgn 0 0 1497 addfile 0 get tn 0 1498 fz = get bgn 0 1499 if or ne get bad 0 0 or eq fz 0 gt fz 65536 1500 ret false 1501 end 1502 for i ulong fz 1503 put buf i get big i 1504 end 1505 at = findonce fz 1506 if ge at get csn 0 1507 ret false 1508 end 1509 for i ulong at bound `16777216` 1510 put big i get cs i 1511 end 1512 put bgn 0 at 1513 tbdec tw tl 1514 addfile 0 get tn 0 1515 if ne get bad 0 0 1516 ret false 1517 end 1518 ret mutrest add at fz 1519 end 1520 note append cs[s .. csn) to big 1521 fn mutrest s ulong to bool 1522 b = get bgn 0 1523 rest = sub get csn 0 s 1524 if gt rest sub len big b 1525 setbad 28 1526 ret false 1527 end 1528 for i ulong rest bound `16777216` 1529 put big add b i get cs add s i 1530 end 1531 put bgn 0 add b rest 1532 ret true 1533 end 1534 note run the mutant checker (chk) over the case lists until a case fails 1535 fn mutrun mo ulong ml ulong to void 1536 put mode 0 1 1537 killed = false 1538 k = ulong 7 1539 while and not killed lt k get na 0 bound 64 1540 if not runlist k 1541 killed = true 1542 end 1543 if ne get bad 0 0 1544 ret 1545 end 1546 k = add k 1 1547 end 1548 put mode 0 0 1549 tbdec mo ml 1550 if killed 1551 put cnt 6 add get cnt 6 1 1552 say 17 1553 showtb 1554 say 18 1555 p = get hit 0 1556 tokenize p lineend p 1557 showtok 0 1558 newline 1559 else 1560 say 19 1561 showtb 1562 newline 1563 put cnt 4 add get cnt 4 1 1564 end 1565 end 1566 note the only place in cs where buf[0 .. fz) starts, or csn when it is absent or appears twice 1567 fn findonce fz ulong to ulong 1568 n = get csn 0 1569 if lt n fz 1570 ret n 1571 end 1572 found = n 1573 for i ulong add sub n fz 1 bound `16777216` 1574 if matchat i fz 1575 if lt found n 1576 ret n 1577 end 1578 found = i 1579 end 1580 end 1581 ret found 1582 end 1583 note cs[i .. i+fz) equals buf[0 .. fz) 1584 fn matchat i ulong fz ulong to bool 1585 for j ulong fz 1586 if ne get cs add i j get buf j 1587 ret false 1588 end 1589 end 1590 ret true 1591 end 1592 1593 note the oracle identity, the scratch directory and the child descriptors; 0 or an INVALID message id 1594 fn setup to ulong 1595 if not loadnums 11 64 1596 ret 24 1597 end 1598 for i ulong 64 1599 put kk i uint get nums i 1600 end 1601 if not loadnums 12 8 1602 ret 24 1603 end 1604 for i ulong 8 1605 put ivs i uint get nums i 1606 end 1607 pclear 1608 parg 1 1609 if not hashfile 1610 ret 23 1611 end 1612 say 33 1613 showpb 1614 say 35 1615 showhex 1616 newline 1617 tbarg 2 1618 if ne get tn 0 64 1619 ret 23 1620 end 1621 for i ulong 64 1622 if ne get tb i get hexd i 1623 ret 23 1624 end 1625 end 1626 pclear 1627 parg 6 1628 if lt makedir pb 0 get pn 0 448 0 1629 ret 25 1630 end 1631 ret fdsetup 1632 end 1633 fn fdsetup to ulong 1634 m0 = memfd words 0 4 1 1635 m1 = memfd words 0 4 1 1636 m2 = memfd words 0 4 1 1637 m3 = memfd words 0 4 1 1638 m4 = memfd words 0 4 1 1639 if or or lt m0 0 lt m1 0 or or lt m2 0 lt m3 0 lt m4 0 1640 ret 30 1641 end 1642 put fds 0 int m0 1643 put fds 1 int m1 1644 put fds 2 int m2 1645 put fds 3 int m3 1646 put fds 4 int m4 1647 m5 = memfd words 0 4 1 1648 if lt m5 0 1649 ret 30 1650 end 1651 put fds 5 int m5 1652 tbarg 4 1653 pclear 1654 ptb 0 get tn 0 1655 if not readdec 1656 ret 29 1657 end 1658 if not loaddec 1659 if eq get bad 0 36 1660 ret 36 1661 end 1662 ret 29 1663 end 1664 ret 0 1665 end 1666 note SRC into cs and compiled to SCRATCH/fecheck (chk); 0, an INVALID message id, or 1000 + omc's exit 1667 fn mkcheck to ulong 1668 tbarg 3 1669 put bgn 0 0 1670 addsrc 1671 if ne get bad 0 0 1672 ret 28 1673 end 1674 n = get bgn 0 1675 for i ulong n bound `16777216` 1676 put cs i get big i 1677 end 1678 put csn 0 n 1679 pscr 1680 pword 7 1681 pword 9 1682 if not bigfile 1683 ret 30 1684 end 1685 x = build 1686 if ne x 0 1687 ret add 1000 x 1688 end 1689 if not hashfile 1690 ret 30 1691 end 1692 say 34 1693 showpb 1694 say 35 1695 showhex 1696 newline 1697 ret 0 1698 end 1699 note every case list, then the unused declarations; false on a setup failure (bad) 1700 fn runall to bool 1701 k = ulong 7 1702 while lt k get na 0 bound 64 1703 if not runlist k 1704 ret false 1705 end 1706 k = add k 1 1707 end 1708 for d ulong get ndc 0 1709 if eq get dus d 0 1710 say 20 1711 tbdnm get dno d get dnl d 1712 showtb 1713 newline 1714 put cnt 4 add get cnt 4 1 1715 end 1716 end 1717 ret true 1718 end 1719 fn main to int 1720 if not loadargs 1721 say 22 1722 newline 1723 ret 2 1724 end 1725 e = setup 1726 if ne e 0 1727 ret invalid e 1728 end 1729 e = mkcheck 1730 if ge e 1000 1731 say 26 1732 num sub e 1000 1733 newline 1734 put cnt 4 1 1735 ret verdict 2 1736 end 1737 if ne e 0 1738 ret invalid e 1739 end 1740 if not runall 1741 ret invalid get bad 0 1742 end 1743 mutants 1744 if ne get bad 0 0 1745 ret invalid get bad 0 1746 end 1747 if eq get cnt 4 0 1748 ret verdict 1 1749 end 1750 ret verdict 2 1751 end