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/qualification/om2/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 / seed / qualification / om2 / gate.om` 2216 lines ยท 36494 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 2 note seed/qualification/om2/gate.om: OM-2 qualification coordinator (#748, ledger L836). 3 note Handwritten seeded Omega, program mode, Linux AArch64, modelled on security673/gate669.om. 4 note 5 note Run from the repository root: gate OMC OMC_SHA256 CASES SCRATCH 6 note OMC compiler under test (path); every case source is compiled by it 7 note OMC_SHA256 64 lowercase hex digits; the gate hashes OMC itself (FIPS 180-4 SHA-256 written 8 note below, constants read from the bc-derived fixtures) and refuses to run any case 9 note when the digest differs: every case is then NOT_RUN and the gate is INVALID 10 note CASES case list file, at most `1048576` bytes 11 note SCRATCH evidence directory; must not exist (exit 91), created 0700, never overwritten 12 note 13 note Case list: one line per case, words separated by single or repeated spaces, # starts a comment 14 note line. Paths are relative to the working directory. Scratch files are SCRATCH/.. 15 note NAME run SRC STDIN STDOUT STDERR EXIT [ARG ...] compile SRC (exit 0, ELF), run it with 16 note a deadline; PASS only if exit, stdout and stderr all equal the expectation 17 note NAME kill SRC STDIN ORACLE STDERR EXIT [ARG ...] a mutant: PASS only if it exits with EXIT, 18 note stderr matches and stdout DIFFERS from the oracle (reports the first byte); a 19 note survivor or any other exit is FAIL; a signal or timeout is INVALID, never a kill 20 note NAME refuse SRC CODE PASS only if the compiler exits CODE, writes no output and its 21 note diagnostic names "error CODE" 22 note NAME emit SRC STDOUT STDERR EXIT compile only: PASS only if the compiler exits EXIT and its 23 note stdout and stderr equal the expectations (the C2 manifest is a list of these) 24 note NAME same SRC1 SRC2 PASS only if both compile with exit 0 to byte-identical outputs 25 note (SRC2's scratch files carry a .b suffix); never after a subst 26 note NAME notrun REASON ... recorded as NOT_RUN (a planned case whose prerequisite is absent) 27 note cc pinned | cc SRC later cases use OMC, or a compiler built from SRC by the pinned OMC; 28 note the built compiler's sha256 is printed; a failed build makes later cases NOT_RUN 29 note deadline SECONDS per-child deadline, 1..900 (default 30) 30 note subst FROMFILE TOFILE the next run/kill/refuse/cc source gets the bytes of FROMFILE 31 note replaced by those of TOFILE; the source must contain FROMFILE exactly once 32 note SRC is one segment or several joined by + (concatenated in order into SCRATCH/.src, at 33 note most 16 MiB): a path, pack:PATH:OFF:LEN (LEN bytes of PATH from byte OFF) or cyc:PATH:N (N bytes 34 note repeating the bytes of PATH). 35 note STDIN: - (/dev/null) | file:PATH | rep:BYTE:N (N copies) | seq:N (byte i = i mod 251) | 36 note rnd:SEED:N (splitmix64 from SEED, each output word little endian). 37 note STDOUT, STDERR: - (empty) | file:PATH | line:TEXT (TEXT and a newline) | any (STDERR, and emit 38 note STDOUT). emit STDOUT also: sha:HEX (sha256 of the compiler output, 64 lowercase hex). 39 note emit STDERR also: err:LINE:CODE (exactly "omc: line LINE: error CODE" and a newline), 40 note has:PATH (each line of PATH is a whole stderr line, in any order) and tok:PATH (each 41 note line of PATH has all its words, as whole words, in one stderr line). 42 note EXIT 127 is refused: the child uses it to report an exec or redirect failure. 43 note 44 note Per case: CASE line, one " $" line per child command with its redirects, one VERDICT line: 45 note PASS, FAIL (deterministic wrong behaviour), INVALID (no evidence: malformed line, unreadable 46 note input, signal, timeout, exec failure, scratch I/O) or NOT_RUN. Final line, exit status: 47 note OM2GATE PASS 0 | FAIL 1 | NOT_RUN 2 | INVALID 3 (any INVALID case, identity mismatch, no cases). 48 note Usage error 90, existing scratch 91. This is not a sandbox: children run with the caller's 49 note permissions, the deadline covers only the direct child, and only trusted sources belong here. 50 text words "run\nkill\nrefuse\nnotrun\ncc\ndeadline\nsubst\npinned\n-\nfile:\nline:\nrep:\nseq:\nrnd:\nany\n.src\n.elf\n.cout\n.cerr\n.in\n.exp\n.eexp\n.out\n.err\nerror \nseed/qualification/om2/fixtures/sha256-k.dec\nseed/qualification/om2/fixtures/sha256-iv.dec\n/dev/null\nemit\nsame\nsha:\n.b\nerr:\nomc: line \n: error \nhas:\ntok:\ncyc:\npack:\n" 51 text msg "VERDICT \n PASS\n FAIL\n INVALID\n NOT_RUN\n compile exit=\n expected=\n run exit=\n stdout=match\n stdout differs at byte \n stderr=match\n stderr differs at byte \n mutant survived: stdout equals the oracle\n killed: stdout differs from the oracle at byte \n compiler exit 0 but its output is not an ELF file\n refusal wrote compiler output\n diagnostic does not name the expected error\n child signal; wait low byte=\n child deadline exceeded, sent SIGKILL; wait low byte=\n malformed case line\n input, source or fixture unreadable or too large\n scratch I/O, fork or argument capacity failure\n exec or redirect failed (child exit 127)\n refused with the expected error\nOM2GATE PASS\nOM2GATE FAIL\nOM2GATE INVALID\nOM2GATE NOT_RUN\n cases=\n pass=\n fail=\n invalid=\n not_run=\nIDENTITY omc \n sha256=\n pinned=\n match\n MISMATCH: every case is NOT_RUN and the gate is INVALID\n $ \n < \n > \n 2> \nCASE \n line=\n compiler build failed earlier; case not run\n omc identity mismatch; case not run\n substitution must match exactly once; matches=\n MUTATE exact-once substitution at byte \nCOMPILER \n stderr=unchecked\n a substitution was not followed by a source-building line\n no cases\nUSAGE gate OMC OMC_SHA256 CASES SCRATCH; INVALID\nINVALID scratch directory exists or cannot be created\nINVALID SHA-256 constant fixture unreadable or malformed\nINVALID case list unreadable or larger than `1048576` bytes\n not run:\n; not a meaningful kill\n compiler build: compile exit=\nDEADLINE \nSUBST \n source line=\nOM2GATE START cases=\n scratch=\n stdout sha256 differs; expected \n stdout=unchecked\n outputs identical\n outputs differ at byte \n second compile exit=\n stderr lacks expected line \n" 52 global pb uchar 4096 53 global pn ulong 1 54 global scr uchar 4096 55 global scn ulong 1 56 global omc uchar 4096 57 global omn ulong 1 58 global ccp uchar 4096 59 global ccn ulong 1 60 global pin uchar 64 61 global hexd uchar 64 62 global av uchar 4096 63 global ap ulong 2 64 global lst uchar `1048576` 65 global lsn ulong 1 66 global tko ulong 64 67 global tkl ulong 64 68 global ntk ulong 1 69 global big uchar `16777216` 70 global bgn ulong 1 71 global sfr uchar 65536 72 global sto uchar 65536 73 global sb ulong 3 74 global sx ulong 2 75 global buf uchar 65536 76 global oth uchar 65536 77 global dig uchar 32 78 global stb uchar 4 79 global gst ulong 1 80 global wlow ulong 1 81 global dl long 1 82 global cnt ulong 4 83 global ccbad ulong 1 84 global idok ulong 1 85 global wpos ulong 2 86 global lno ulong 1 87 global res ulong 8 88 global rz ulong 2 89 global kk uint 64 90 global ivs uint 8 91 global hv uint 8 92 global ws uint 64 93 global st uint 8 94 global blk uchar 64 95 global bk ulong 2 96 global nums ulong 64 97 note ---- output ------------------------------------------------------------------------------- 98 fn say id ulong to void 99 k = ulong 1 100 s = ulong 0 101 for i ulong len msg 102 if eq get msg i 10 103 if eq k id 104 r = write 1 msg s sub i s 105 ret 106 end 107 k = add k 1 108 s = add i 1 109 end 110 end 111 exit 99 112 end 113 fn newline to void 114 put dig 0 10 115 r = write 1 dig 0 1 116 end 117 fn space to void 118 put dig 0 32 119 r = write 1 dig 0 1 120 end 121 fn decimal v ulong to ulong 122 x = v 123 n = ulong 0 124 while ge x 10 125 put dig n uchar add 48 rem x 10 126 x = div x 10 127 n = add n 1 128 end 129 put dig n uchar add 48 x 130 ret add n 1 131 end 132 fn num v ulong to void 133 n = decimal v 134 for i ulong n 135 r = write 1 dig sub sub n i 1 1 136 end 137 end 138 fn showpb to void 139 r = write 1 pb 0 get pn 0 140 end 141 fn showtok t ulong to void 142 r = write 1 lst get tko t get tkl t 143 end 144 fn setbad id ulong to void 145 if eq get gst 0 0 146 put gst 0 id 147 end 148 end 149 note ---- fixed words and tokens --------------------------------------------------------------- 150 fn wordat id ulong to void 151 k = ulong 1 152 s = ulong 0 153 for i ulong len words 154 if eq get words i 10 155 if eq k id 156 put wpos 0 s 157 put wpos 1 sub i s 158 ret 159 end 160 k = add k 1 161 s = add i 1 162 end 163 end 164 exit 99 165 end 166 fn tokpre t ulong id ulong to bool 167 wordat id 168 n = get wpos 1 169 if lt get tkl t n 170 ret false 171 end 172 o = get tko t 173 s = get wpos 0 174 for i ulong n 175 if ne get lst add o i get words add s i 176 ret false 177 end 178 end 179 ret true 180 end 181 fn tokword t ulong id ulong to bool 182 wordat id 183 if ne get tkl t get wpos 1 184 ret false 185 end 186 ret tokpre t id 187 end 188 note decimal digits lst[o .. o+n); malformed or overflowing text marks the case malformed 189 fn decat o ulong n ulong to ulong 190 if or eq n 0 gt n 20 191 setbad 20 192 ret 0 193 end 194 m = not ulong 0 195 v = ulong 0 196 for i ulong n 197 c = get lst add o i 198 if or lt c 48 gt c 57 199 setbad 20 200 ret 0 201 end 202 d = ulong sub c 48 203 if gt v div sub m d 10 204 setbad 20 205 ret 0 206 end 207 v = add mul v 10 d 208 end 209 ret v 210 end 211 note field k (0-based) of the ':'-separated fields after the first skip bytes of token t 212 fn fieldat t ulong skip ulong k ulong to ulong 213 o = add get tko t skip 214 e = add get tko t get tkl t 215 f = ulong 0 216 s = o 217 for i ulong sub e o 218 if eq get lst add o i 58 219 if eq f k 220 ret decat s sub add o i s 221 end 222 f = add f 1 223 s = add add o i 1 224 end 225 end 226 if eq f k 227 ret decat s sub e s 228 end 229 setbad 20 230 ret 0 231 end 232 fn fields t ulong skip ulong to ulong 233 f = ulong 1 234 o = add get tko t skip 235 for i ulong sub get tkl t skip 236 if eq get lst add o i 58 237 f = add f 1 238 end 239 end 240 ret f 241 end 242 note ---- paths and child argument lists -------------------------------------------------------- 243 fn pclear to void 244 put pn 0 0 245 end 246 fn pbyte b uchar to void 247 n = get pn 0 248 if ge n 4095 249 setbad 22 250 ret 251 end 252 put pb n b 253 put pn 0 add n 1 254 end 255 fn pword id ulong to void 256 wordat id 257 s = get wpos 0 258 for i ulong get wpos 1 259 pbyte get words add s i 260 end 261 end 262 fn plst o ulong n ulong to void 263 for i ulong n 264 pbyte get lst add o i 265 end 266 end 267 fn pnum v ulong to void 268 n = decimal v 269 for i ulong n 270 pbyte get dig sub sub n i 1 271 end 272 end 273 fn pomc to void 274 pclear 275 for i ulong get omn 0 276 pbyte get omc i 277 end 278 end 279 fn pccp to void 280 pclear 281 for i ulong get ccn 0 282 pbyte get ccp i 283 end 284 end 285 note SCRATCH/., with ".b" appended while sx[0] is set (the second source of `same`) 286 fn pfile id ulong to void 287 pclear 288 for i ulong get scn 0 289 pbyte get scr i 290 end 291 pnum get lno 0 292 pword id 293 if ne get sx 0 0 294 pword 32 295 end 296 end 297 fn popen fl int to int 298 if ne get gst 0 0 299 ret -1 300 end 301 r = fopen pb 0 get pn 0 fl 384 302 if lt r 0 303 ret -1 304 end 305 ret int r 306 end 307 fn fclo fd int to void 308 if ge fd 0 309 r = fclose fd 310 end 311 end 312 fn aclear to void 313 put ap 0 2 314 put ap 1 0 315 end 316 fn ahead n ulong to bool 317 p = get ap 0 318 if or gt add add p n 2 len av ge get ap 1 64 319 setbad 22 320 ret false 321 end 322 put av p uchar and n 255 323 put av add p 1 uchar shr n 8 324 put ap 0 add p 2 325 put ap 1 add get ap 1 1 326 ret true 327 end 328 fn apb to void 329 n = get pn 0 330 if ahead n 331 p = get ap 0 332 for i ulong n 333 put av add p i get pb i 334 end 335 put ap 0 add p n 336 end 337 end 338 fn atok t ulong to void 339 n = get tkl t 340 o = get tko t 341 if ahead n 342 p = get ap 0 343 for i ulong n 344 put av add p i get lst add o i 345 end 346 put ap 0 add p n 347 end 348 end 349 note ---- children ------------------------------------------------------------------------------ 350 fn redir s int d int to void 351 if ne s d 352 if ne dupfd s d 0 long d 353 exit 127 354 end 355 end 356 end 357 fn reap pid int to ulong 358 t0 = monons 359 while true 360 r = waitpid pid stb 0 len stb 1 361 if eq r long pid 362 if ne get stb 0 0 363 put wlow 0 ulong get stb 0 364 setbad 18 365 ret 0 366 end 367 x = ulong get stb 1 368 if eq x 127 369 setbad 23 370 end 371 ret x 372 end 373 if lt r 0 374 setbad 22 375 ret 0 376 end 377 now = monons 378 if or lt now t0 gt sub now t0 get dl 0 379 r = killpid pid 9 380 r = waitpid pid stb 0 len stb 0 381 put wlow 0 ulong get stb 0 382 setbad 19 383 ret 0 384 end 385 if ne sleepns `1000000` 0 386 setbad 22 387 ret 0 388 end 389 end 390 exit 99 391 end 392 fn spawn fi int fo int fe int to ulong 393 newline 394 if ne get gst 0 0 395 fclo fi 396 fclo fo 397 fclo fe 398 ret 0 399 end 400 put av 0 uchar and get ap 1 255 401 put av 1 uchar shr get ap 1 8 402 pid = fork 403 if lt pid 0 404 fclo fi 405 fclo fo 406 fclo fe 407 setbad 22 408 ret 0 409 end 410 if eq pid 0 411 redir fi 0 412 redir fo 1 413 redir fe 2 414 r = execprog av 0 get ap 0 415 exit 127 416 end 417 fclo fi 418 fclo fo 419 fclo fe 420 ret reap int pid 421 end 422 note compile SCRATCH/.src with the pinned omc (pinned true) or the current compiler 423 fn compile pinned bool to ulong 424 aclear 425 say 39 426 if pinned 427 pomc 428 else 429 pccp 430 end 431 showpb 432 apb 433 say 40 434 pfile 16 435 showpb 436 fi = popen 524288 437 say 41 438 pfile 17 439 showpb 440 fo = popen 524481 441 say 42 442 pfile 19 443 showpb 444 fe = popen 524481 445 ret spawn fi fo fe 446 end 447 fn stdinpath t ulong to void 448 pclear 449 if tokword t 9 450 pword 28 451 ret 452 end 453 if tokpre t 10 454 plst add get tko t 5 sub get tkl t 5 455 ret 456 end 457 pfile 20 458 end 459 fn runprog to ulong 460 aclear 461 say 39 462 pfile 17 463 showpb 464 apb 465 for j ulong sub get ntk 0 7 466 space 467 showtok add j 7 468 atok add j 7 469 end 470 say 40 471 stdinpath 3 472 showpb 473 fi = popen 524288 474 say 41 475 pfile 23 476 showpb 477 fo = popen 524481 478 say 42 479 pfile 24 480 showpb 481 fe = popen 524481 482 ret spawn fi fo fe 483 end 484 note ---- file helpers -------------------------------------------------------------------------- 485 fn rfulla fd int to long 486 n = ulong 0 487 while lt n len buf 488 r = read fd buf n sub len buf n 489 if lt r 0 490 ret r 491 end 492 if eq r 0 493 ret long n 494 end 495 n = add n ulong r 496 end 497 ret long n 498 end 499 fn rfullb fd int to long 500 n = ulong 0 501 while lt n len oth 502 r = read fd oth n sub len oth n 503 if lt r 0 504 ret r 505 end 506 if eq r 0 507 ret long n 508 end 509 n = add n ulong r 510 end 511 ret long n 512 end 513 fn firstdif m ulong to ulong 514 for i ulong m 515 if ne get buf i get oth i 516 ret i 517 end 518 end 519 ret m 520 end 521 note first differing byte of two scratch files, or not 0 when they are equal; file b carries the 522 note ".b" suffix when sx[1] is set 523 fn diffat a ulong b ulong to ulong 524 pfile a 525 fa = popen 524288 526 put sx 0 get sx 1 527 pfile b 528 put sx 0 0 529 fb = popen 524288 530 if or lt fa 0 lt fb 0 531 fclo fa 532 fclo fb 533 setbad 22 534 ret 0 535 end 536 off = ulong 0 537 while true 538 ra = rfulla fa 539 rb = rfullb fb 540 if or lt ra 0 lt rb 0 541 fclo fa 542 fclo fb 543 setbad 22 544 ret 0 545 end 546 m = ulong ra 547 if lt rb ra 548 m = ulong rb 549 end 550 d = firstdif m 551 if lt d m 552 fclo fa 553 fclo fb 554 ret add off d 555 end 556 if or ne ra rb eq ra 0 557 fclo fa 558 fclo fb 559 if eq ra rb 560 ret not ulong 0 561 end 562 ret add off m 563 end 564 off = add off m 565 end 566 exit 99 567 end 568 fn copyfd s int d int to void 569 while true 570 r = rfulla s 571 if lt r 0 572 setbad 21 573 ret 574 end 575 if eq r 0 576 ret 577 end 578 if ne write d buf 0 ulong r r 579 setbad 22 580 ret 581 end 582 end 583 end 584 note compiler output: ELF magic, then made executable (0700); false when it is not an ELF file 585 fn elfok to bool 586 pfile 17 587 fd = popen 524288 588 if lt fd 0 589 setbad 22 590 ret false 591 end 592 r = read fd buf 0 4 593 ok = eq r 4 594 if ok 595 m1 = and eq get buf 0 127 eq get buf 1 69 596 m2 = and eq get buf 2 76 eq get buf 3 70 597 ok = and m1 m2 598 end 599 if ok 600 if ne fchmod fd 448 0 601 setbad 22 602 end 603 end 604 fclo fd 605 ret ok 606 end 607 fn isempty id ulong to bool 608 pfile id 609 fd = popen 524288 610 if lt fd 0 611 setbad 22 612 ret false 613 end 614 r = read fd buf 0 1 615 fclo fd 616 ret eq r 0 617 end 618 note does SCRATCH/.cerr contain "error CODE" not followed by another digit 619 fn names code ulong to bool 620 pfile 19 621 fd = popen 524288 622 if lt fd 0 623 setbad 22 624 ret false 625 end 626 r = rfulla fd 627 fclo fd 628 if lt r 0 629 setbad 22 630 ret false 631 end 632 wordat 25 633 s = get wpos 0 634 k = get wpos 1 635 for i ulong k 636 put oth i get words add s i 637 end 638 n = decimal code 639 for i ulong n 640 put oth add k i get dig sub sub n i 1 641 end 642 k = add k n 643 hay = ulong r 644 for i ulong hay 645 if le add i k hay 646 if hasat i k 647 if eq add i k hay 648 ret true 649 end 650 c = get buf add i k 651 if or lt c 48 gt c 57 652 ret true 653 end 654 end 655 end 656 end 657 ret false 658 end 659 fn hasat i ulong k ulong to bool 660 for j ulong k 661 if ne get buf add i j get oth j 662 ret false 663 end 664 end 665 ret true 666 end 667 note ---- inputs and expectations --------------------------------------------------------------- 668 fn splitmix to ulong 669 s = add get rz 0 `11400714819323198485` 670 put rz 0 s 671 z = mul xor s shr s 30 `13787848793156543929` 672 z = mul xor z shr z 27 `10723151780598845931` 673 ret xor z shr z 31 674 end 675 fn genone kind ulong a ulong i ulong to uchar 676 if eq kind 12 677 ret uchar a 678 end 679 if eq kind 13 680 ret uchar rem i 251 681 end 682 j = rem i 8 683 if eq j 0 684 put rz 1 splitmix 685 end 686 ret uchar and shr get rz 1 mul j 8 255 687 end 688 fn genbytes fd int kind ulong a ulong n ulong to void 689 put rz 0 a 690 done = ulong 0 691 while lt done n 692 c = sub n done 693 if gt c len buf 694 c = len buf 695 end 696 for i ulong c 697 put buf i genone kind a add done i 698 end 699 if ne write fd buf 0 c long c 700 setbad 22 701 ret 702 end 703 done = add done c 704 end 705 end 706 fn geninput t ulong to void 707 if tokword t 9 708 ret 709 end 710 if tokpre t 10 711 stdinpath t 712 fd = popen 524288 713 if lt fd 0 714 setbad 21 715 end 716 fclo fd 717 ret 718 end 719 kind = ulong 0 720 a = ulong 0 721 n = ulong 0 722 if tokpre t 12 723 if ne fields t 4 2 724 setbad 20 725 end 726 kind = ulong 12 727 a = fieldat t 4 0 728 n = fieldat t 4 1 729 if gt a 255 730 setbad 20 731 end 732 end 733 if tokpre t 13 734 if ne fields t 4 1 735 setbad 20 736 end 737 kind = ulong 13 738 n = fieldat t 4 0 739 end 740 if tokpre t 14 741 if ne fields t 4 2 742 setbad 20 743 end 744 kind = ulong 14 745 a = fieldat t 4 0 746 n = fieldat t 4 1 747 end 748 if or eq kind 0 gt n `1073741824` 749 setbad 20 750 end 751 pfile 20 752 fd = popen 524481 753 if ge fd 0 754 genbytes fd kind a n 755 end 756 fclo fd 757 end 758 note SCRATCH/. from an expectation word: -, file:PATH, has:PATH (a copy, compared line by 759 note line), line:TEXT or err:LINE:CODE (the human diagnostic "omc: line LINE: error CODE") 760 fn mkexp t ulong id ulong to void 761 pfile id 762 fo = popen 524481 763 if lt fo 0 764 setbad 22 765 ret 766 end 767 if tokword t 9 768 fclo fo 769 ret 770 end 771 if or or tokpre t 10 tokpre t 36 tokpre t 37 772 k = ulong 5 773 if or tokpre t 36 tokpre t 37 774 k = ulong 4 775 end 776 pclear 777 plst add get tko t k sub get tkl t k 778 fi = popen 524288 779 if lt fi 0 780 setbad 21 781 else 782 copyfd fi fo 783 end 784 fclo fi 785 fclo fo 786 ret 787 end 788 if tokpre t 11 789 n = sub get tkl t 5 790 o = add get tko t 5 791 for i ulong n 792 put buf i get lst add o i 793 end 794 put buf n 10 795 if ne write fo buf 0 add n 1 long add n 1 796 setbad 22 797 end 798 fclo fo 799 ret 800 end 801 if tokpre t 33 802 if ne fields t 4 2 803 setbad 20 804 fclo fo 805 ret 806 end 807 n = bufword 0 34 808 n = bufnum n fieldat t 4 0 809 n = bufword n 35 810 n = bufnum n fieldat t 4 1 811 put buf n 10 812 if eq get gst 0 0 813 if ne write fo buf 0 add n 1 long add n 1 814 setbad 22 815 end 816 end 817 fclo fo 818 ret 819 end 820 setbad 20 821 fclo fo 822 end 823 fn bufword n ulong id ulong to ulong 824 wordat id 825 s = get wpos 0 826 k = get wpos 1 827 for i ulong k 828 put buf add n i get words add s i 829 end 830 ret add n k 831 end 832 fn bufnum n ulong v ulong to ulong 833 k = decimal v 834 for i ulong k 835 put buf add n i get dig sub sub k i 1 836 end 837 ret add n k 838 end 839 note has: every LF-terminated line of SCRATCH/.eexp is a whole line of SCRATCH/.cerr; 840 note tok (tm): every such line has all its space-separated words, as whole words, in one stderr 841 note line. Not 0 when so, else the 1-based number of the first expected line not found 842 fn hasall tm bool to ulong 843 pfile 19 844 fa = popen 524288 845 pfile 22 846 fb = popen 524288 847 if or lt fa 0 lt fb 0 848 fclo fa 849 fclo fb 850 setbad 22 851 ret 0 852 end 853 ra = rfulla fa 854 rb = rfullb fb 855 fclo fa 856 fclo fb 857 if or or lt ra 0 lt rb 0 or ge ra long len buf ge rb long len oth 858 setbad 21 859 ret 0 860 end 861 na = ulong ra 862 nb = ulong rb 863 s = ulong 0 864 ln = ulong 0 865 for i ulong nb 866 if eq get oth i 10 867 ln = add ln 1 868 found = false 869 if tm 870 found = tokline na s sub i s 871 else 872 found = hasline na s sub i s 873 end 874 if not found 875 ret ln 876 end 877 s = add i 1 878 end 879 end 880 if ne s nb 881 setbad 20 882 ret 0 883 end 884 ret not ulong 0 885 end 886 fn eqat p ulong s ulong k ulong to bool 887 for j ulong k 888 if ne get buf add p j get oth add s j 889 ret false 890 end 891 end 892 ret true 893 end 894 note does buf[p-1] equal c, or is p the lower bound b 895 fn startat p ulong b ulong c uchar to bool 896 if eq p b 897 ret true 898 end 899 ret eq get buf sub p 1 c 900 end 901 fn hasline na ulong s ulong k ulong to bool 902 if gt k na 903 ret false 904 end 905 for p ulong add sub na k 1 906 if startat p 0 10 907 if or eq add p k na eq get buf add p k 10 908 if eqat p s k 909 ret true 910 end 911 end 912 end 913 end 914 ret false 915 end 916 fn tokline na ulong s ulong k ulong to bool 917 ls = ulong 0 918 for i ulong add na 1 919 if or eq i na eq get buf i 10 920 if alltoks ls i s k 921 ret true 922 end 923 ls = add i 1 924 end 925 end 926 ret false 927 end 928 fn alltoks lb ulong lz ulong s ulong k ulong to bool 929 ts = s 930 for i ulong add k 1 931 if or eq i k eq get oth add s i 32 932 te = add s i 933 if gt te ts 934 if not hastok lb lz ts sub te ts 935 ret false 936 end 937 end 938 ts = add te 1 939 end 940 end 941 ret true 942 end 943 fn hastok lb ulong lz ulong ts ulong tl ulong to bool 944 if gt tl sub lz lb 945 ret false 946 end 947 for q ulong add sub sub lz lb tl 1 948 if startat add lb q lb 32 949 if endat add add lb q tl lz 32 950 if eqat add lb q ts tl 951 ret true 952 end 953 end 954 end 955 end 956 ret false 957 end 958 note is e the upper bound z, or does buf[e] equal c 959 fn endat e ulong z ulong c uchar to bool 960 if eq e z 961 ret true 962 end 963 ret eq get buf e c 964 end 965 note ---- case sources -------------------------------------------------------------------------- 966 note one +-separated SRC segment lst[o .. o+n): a path, pack:PATH:OFF:LEN (LEN bytes of PATH from byte 967 note OFF) or cyc:PATH:N (N bytes repeating the contents of PATH, 1..65535 bytes); appended to big 968 fn addpart o ulong n ulong to void 969 if segpre o n 39 970 addpack add o 5 sub n 5 971 ret 972 end 973 if segpre o n 38 974 addcyc add o 4 sub n 4 975 ret 976 end 977 addfile o n 978 end 979 fn segpre o ulong n ulong id ulong to bool 980 wordat id 981 k = get wpos 1 982 if lt n k 983 ret false 984 end 985 s = get wpos 0 986 for i ulong k 987 if ne get lst add o i get words add s i 988 ret false 989 end 990 end 991 ret true 992 end 993 note offset of the last ':' in lst[o .. o+n), or n when there is none 994 fn lastcol o ulong n ulong to ulong 995 i = n 996 while gt i 0 997 i = sub i 1 998 if eq get lst add o i 58 999 ret i 1000 end 1001 end 1002 ret n 1003 end 1004 fn addpack o ulong n ulong to void 1005 q = lastcol o n 1006 if ge q n 1007 setbad 20 1008 ret 1009 end 1010 p = lastcol o q 1011 if ge p q 1012 setbad 20 1013 ret 1014 end 1015 k = decat add add o q 1 sub sub n q 1 1016 off = decat add add o p 1 sub sub q p 1 1017 if ne get gst 0 0 1018 ret 1019 end 1020 if gt k sub len big get bgn 0 1021 setbad 21 1022 ret 1023 end 1024 pclear 1025 plst o p 1026 fd = popen 524288 1027 if lt fd 0 1028 setbad 21 1029 ret 1030 end 1031 ok = preadall fd off k 1032 fclo fd 1033 if not ok 1034 setbad 21 1035 ret 1036 end 1037 put bgn 0 add get bgn 0 k 1038 end 1039 note k bytes of fd from position off to big at bgn 1040 fn preadall fd int off ulong k ulong to bool 1041 b = get bgn 0 1042 done = ulong 0 1043 while lt done k 1044 c = sub k done 1045 if gt c `1048576` 1046 c = ulong `1048576` 1047 end 1048 r = pread fd big add b done c long add off done 1049 if le r 0 1050 ret false 1051 end 1052 done = add done ulong r 1053 end 1054 ret true 1055 end 1056 fn addcyc o ulong n ulong to void 1057 q = lastcol o n 1058 if ge q n 1059 setbad 20 1060 ret 1061 end 1062 k = decat add add o q 1 sub sub n q 1 1063 if ne get gst 0 0 1064 ret 1065 end 1066 if gt k sub len big get bgn 0 1067 setbad 21 1068 ret 1069 end 1070 pclear 1071 plst o q 1072 fd = popen 524288 1073 if lt fd 0 1074 setbad 21 1075 ret 1076 end 1077 r = rfullb fd 1078 fclo fd 1079 if or le r 0 ge r long len oth 1080 setbad 21 1081 ret 1082 end 1083 cycfill ulong r k 1084 end 1085 note big[bgn .. bgn+k) = oth[i mod m], in 65536-byte rows (a loop with a value count traps 4 after 1086 note `1000000` passes) 1087 fn cycfill m ulong k ulong to void 1088 b = get bgn 0 1089 for r ulong add div k 65536 1 1090 s = mul r 65536 1091 c = sub k s 1092 if gt c 65536 1093 c = ulong 65536 1094 end 1095 cycrow b s c m 1096 end 1097 put bgn 0 add b k 1098 end 1099 fn cycrow b ulong s ulong c ulong m ulong to void 1100 for i ulong c 1101 put big add add b s i get oth rem add s i m 1102 end 1103 end 1104 fn addfile o ulong n ulong to void 1105 pclear 1106 plst o n 1107 fd = popen 524288 1108 if lt fd 0 1109 setbad 21 1110 ret 1111 end 1112 while true 1113 b = get bgn 0 1114 c = sub len big b 1115 if gt c len buf 1116 c = len buf 1117 end 1118 if eq c 0 1119 r = read fd buf 0 1 1120 if ne r 0 1121 setbad 21 1122 end 1123 fclo fd 1124 ret 1125 end 1126 r = read fd big b c 1127 if lt r 0 1128 setbad 21 1129 fclo fd 1130 ret 1131 end 1132 if eq r 0 1133 fclo fd 1134 ret 1135 end 1136 put bgn 0 add b ulong r 1137 end 1138 end 1139 fn matchat p ulong to bool 1140 for j ulong get sb 1 1141 if ne get big add p j get sfr j 1142 ret false 1143 end 1144 end 1145 ret true 1146 end 1147 note matches of sfr in big[base .. base+c): count in res 6, last position in res 7 1148 fn scanchnk base ulong c ulong to void 1149 for i ulong c 1150 if eq get big add base i get sfr 0 1151 if matchat add base i 1152 put res 6 add get res 6 1 1153 put res 7 add base i 1154 end 1155 end 1156 end 1157 end 1158 note exact-once position of sfr in big; otherwise the match count goes to wlow with gst 47 1159 fn findonce to ulong 1160 fl = get sb 1 1161 n = get bgn 0 1162 put res 6 0 1163 put res 7 0 1164 if ge n fl 1165 last = sub n fl 1166 base = ulong 0 1167 while le base last 1168 c = add sub last base 1 1169 if gt c 65536 1170 c = ulong 65536 1171 end 1172 scanchnk base c 1173 base = add base c 1174 end 1175 end 1176 if ne get res 6 1 1177 put wlow 0 get res 6 1178 setbad 47 1179 end 1180 ret get res 7 1181 end 1182 fn wbig fd int o ulong n ulong to void 1183 if ne write fd big o n long n 1184 setbad 22 1185 end 1186 end 1187 fn mksrc t ulong to void 1188 put bgn 0 0 1189 o = get tko t 1190 e = add o get tkl t 1191 s = o 1192 for i ulong get tkl t 1193 if eq get lst add o i 43 1194 addpart s sub add o i s 1195 s = add add o i 1 1196 end 1197 end 1198 addpart s sub e s 1199 pfile 16 1200 fd = popen 524481 1201 if lt fd 0 1202 setbad 22 1203 put sb 0 0 1204 ret 1205 end 1206 if ne get sb 0 0 1207 put sb 0 0 1208 p = findonce 1209 if eq get gst 0 0 1210 say 48 1211 num p 1212 newline 1213 wbig fd 0 p 1214 if ne write fd sto 0 get sb 2 long get sb 2 1215 setbad 22 1216 end 1217 q = add p get sb 1 1218 wbig fd q sub get bgn 0 q 1219 end 1220 else 1221 wbig fd 0 get bgn 0 1222 end 1223 fclo fd 1224 end 1225 note ---- SHA-256 (FIPS 180-4) for compiler identity only --------------------------------------- 1226 fn rotr x uint n uint to uint 1227 ret or shr x n shl x sub 32 n 1228 end 1229 fn shasched to void 1230 for i ulong 16 1231 b = mul i 4 1232 v = shl uint get blk b 24 1233 v = or v shl uint get blk add b 1 16 1234 v = or v shl uint get blk add b 2 8 1235 v = or v uint get blk add b 3 1236 put ws i v 1237 end 1238 for j ulong 48 1239 q = add j 16 1240 x = get ws sub q 15 1241 y = get ws sub q 2 1242 s0 = xor xor rotr x 7 rotr x 18 shr x 3 1243 s1 = xor xor rotr y 17 rotr y 19 shr y 10 1244 put ws q add add add get ws sub q 16 s0 get ws sub q 7 s1 1245 end 1246 end 1247 fn shat1 i ulong to uint 1248 e = get st 4 1249 s1 = xor xor rotr e 6 rotr e 11 rotr e 25 1250 ch = xor and e get st 5 and not e get st 6 1251 ret add add add add get st 7 s1 ch get kk i get ws i 1252 end 1253 fn shat2 to uint 1254 a = get st 0 1255 b = get st 1 1256 c = get st 2 1257 s0 = xor xor rotr a 2 rotr a 13 rotr a 22 1258 mj = xor xor and a b and a c and b c 1259 ret add s0 mj 1260 end 1261 fn shacomp to void 1262 shasched 1263 for i ulong 8 1264 put st i get hv i 1265 end 1266 for i ulong 64 1267 t1 = shat1 i 1268 t2 = shat2 1269 put st 7 get st 6 1270 put st 6 get st 5 1271 put st 5 get st 4 1272 put st 4 add get st 3 t1 1273 put st 3 get st 2 1274 put st 2 get st 1 1275 put st 1 get st 0 1276 put st 0 add t1 t2 1277 end 1278 for i ulong 8 1279 put hv i add get hv i get st i 1280 end 1281 end 1282 fn shabyte b uchar to void 1283 n = get bk 0 1284 put blk n b 1285 n = add n 1 1286 if eq n 64 1287 shacomp 1288 n = ulong 0 1289 end 1290 put bk 0 n 1291 put bk 1 add get bk 1 1 1292 end 1293 fn hexch v uint to uchar 1294 if lt v 10 1295 ret uchar add v 48 1296 end 1297 ret uchar add v 87 1298 end 1299 fn shafinal to void 1300 bits = mul get bk 1 8 1301 shabyte 128 1302 while ne get bk 0 56 bound 64 1303 shabyte 0 1304 end 1305 for i ulong 8 1306 shabyte uchar and shr bits mul sub 7 i 8 255 1307 end 1308 for i ulong 8 1309 v = get hv i 1310 for j ulong 8 1311 put hexd add mul i 8 j hexch and shr v mul sub 7 j 4 15 1312 end 1313 end 1314 end 1315 note hash the file named by pb into hexd; false when it cannot be read 1316 fn hashfile to bool 1317 fd = popen 524288 1318 if lt fd 0 1319 ret false 1320 end 1321 for i ulong 8 1322 put hv i get ivs i 1323 end 1324 put bk 0 0 1325 put bk 1 0 1326 while true 1327 r = read fd buf 0 len buf 1328 if lt r 0 1329 fclo fd 1330 ret false 1331 end 1332 if eq r 0 1333 fclo fd 1334 shafinal 1335 ret true 1336 end 1337 for i ulong ulong r 1338 shabyte get buf i 1339 end 1340 end 1341 ret false 1342 end 1343 note decimal numbers, one per line, each below 2^32, exactly want of them, into nums 1344 fn loadnums id ulong want ulong to bool 1345 pclear 1346 pword id 1347 fd = popen 524288 1348 if lt fd 0 1349 ret false 1350 end 1351 r = rfulla fd 1352 fclo fd 1353 if or le r 0 ge r long len buf 1354 ret false 1355 end 1356 ret parsenum ulong r want 1357 end 1358 fn parsenum n ulong want ulong to bool 1359 m = ulong not uint 0 1360 k = ulong 0 1361 v = ulong 0 1362 nd = ulong 0 1363 for i ulong n 1364 c = get buf i 1365 if and ge c 48 le c 57 1366 if ge nd 10 1367 ret false 1368 end 1369 v = add mul v 10 ulong sub c 48 1370 nd = add nd 1 1371 else 1372 if or ne c 10 eq nd 0 1373 ret false 1374 end 1375 if ge k want 1376 ret false 1377 end 1378 if gt v m 1379 ret false 1380 end 1381 put nums k v 1382 k = add k 1 1383 v = ulong 0 1384 nd = ulong 0 1385 end 1386 end 1387 ret and eq nd 0 eq k want 1388 end 1389 note ---- verdicts ------------------------------------------------------------------------------ 1390 fn verdict s ulong to void 1391 say 1 1392 showtok 0 1393 say s 1394 put cnt sub s 2 add get cnt sub s 2 1 1395 end 1396 fn invalid to void 1397 verdict 4 1398 g = get gst 0 1399 say g 1400 if or or eq g 18 eq g 19 eq g 47 1401 num get wlow 0 1402 end 1403 newline 1404 end 1405 fn header to void 1406 say 43 1407 showtok 0 1408 say 44 1409 num get lno 0 1410 newline 1411 end 1412 fn showexit a ulong id ulong b ulong to void 1413 say id 1414 num a 1415 say 7 1416 num b 1417 end 1418 fn runcase kill bool to void 1419 if lt get ntk 0 7 1420 setbad 20 1421 invalid 1422 ret 1423 end 1424 ex = decat get tko 6 get tkl 6 1425 if or gt ex 255 eq ex 127 1426 setbad 20 1427 end 1428 if or or tokpre 4 36 tokpre 5 36 or tokpre 4 37 tokpre 5 37 1429 setbad 20 1430 end 1431 if ne get gst 0 0 1432 invalid 1433 ret 1434 end 1435 mksrc 2 1436 ce = compile false 1437 if ne get gst 0 0 1438 invalid 1439 ret 1440 end 1441 if ne ce 0 1442 verdict 3 1443 showexit ce 6 0 1444 newline 1445 ret 1446 end 1447 if not elfok 1448 if ne get gst 0 0 1449 invalid 1450 ret 1451 end 1452 verdict 3 1453 say 15 1454 newline 1455 ret 1456 end 1457 geninput 3 1458 mkexp 4 21 1459 anyerr = tokword 5 15 1460 if not anyerr 1461 mkexp 5 22 1462 end 1463 if ne get gst 0 0 1464 invalid 1465 ret 1466 end 1467 rx = runprog 1468 if ne get gst 0 0 1469 invalid 1470 ret 1471 end 1472 put res 0 ex 1473 put res 1 rx 1474 put res 2 diffat 23 21 1475 put res 3 not ulong 0 1476 if not anyerr 1477 put res 3 diffat 24 22 1478 end 1479 if ne get gst 0 0 1480 invalid 1481 ret 1482 end 1483 judge kill anyerr 1484 end 1485 fn judge kill bool anyerr bool to void 1486 all = not ulong 0 1487 ex = get res 0 1488 rx = get res 1 1489 od = get res 2 1490 ed = get res 3 1491 ok = and eq rx ex eq ed all 1492 if kill 1493 ok = and ok ne od all 1494 else 1495 ok = and ok eq od all 1496 end 1497 if ok 1498 verdict 2 1499 else 1500 verdict 3 1501 end 1502 showexit rx 8 ex 1503 if eq od all 1504 if kill 1505 say 13 1506 else 1507 say 9 1508 end 1509 else 1510 if kill 1511 say 14 1512 else 1513 say 10 1514 end 1515 num od 1516 end 1517 if anyerr 1518 say 50 1519 else 1520 if eq ed all 1521 say 11 1522 else 1523 say 12 1524 num ed 1525 end 1526 end 1527 if and kill ne rx ex 1528 say 58 1529 end 1530 newline 1531 end 1532 fn refusecase to void 1533 if ne get ntk 0 4 1534 setbad 20 1535 invalid 1536 ret 1537 end 1538 code = decat get tko 3 get tkl 3 1539 if or eq code 0 gt code 255 1540 setbad 20 1541 end 1542 if ne get gst 0 0 1543 invalid 1544 ret 1545 end 1546 mksrc 2 1547 ce = compile false 1548 if ne get gst 0 0 1549 invalid 1550 ret 1551 end 1552 quiet = isempty 17 1553 named = names code 1554 if ne get gst 0 0 1555 invalid 1556 ret 1557 end 1558 if and and eq ce code quiet named 1559 verdict 2 1560 else 1561 verdict 3 1562 end 1563 showexit ce 6 code 1564 if not quiet 1565 say 16 1566 end 1567 if named 1568 say 24 1569 else 1570 say 17 1571 end 1572 newline 1573 end 1574 note emit: compile only; compiler exit, stdout (-, file:, line:, any, sha:HEX) and stderr (-, file:, 1575 note line:, err:LINE:CODE, has:PATH, any) must all equal the expectation 1576 fn emitcase to void 1577 if ne get ntk 0 6 1578 setbad 20 1579 invalid 1580 ret 1581 end 1582 ex = decat get tko 5 get tkl 5 1583 if or gt ex 255 eq ex 127 1584 setbad 20 1585 end 1586 if tokpre 3 31 1587 if not hexok 1588 setbad 20 1589 end 1590 end 1591 if ne get gst 0 0 1592 invalid 1593 ret 1594 end 1595 put res 0 ex 1596 mksrc 2 1597 put res 1 compile false 1598 if ne get gst 0 0 1599 invalid 1600 ret 1601 end 1602 if not or tokword 3 15 tokpre 3 31 1603 mkexp 3 21 1604 end 1605 if not tokword 4 15 1606 mkexp 4 22 1607 end 1608 if ne get gst 0 0 1609 invalid 1610 ret 1611 end 1612 put res 2 not ulong 0 1613 put res 3 not ulong 0 1614 put res 4 1 1615 if tokpre 3 31 1616 if not shamatch 1617 put res 4 0 1618 end 1619 else 1620 if not tokword 3 15 1621 put res 2 diffat 17 21 1622 end 1623 end 1624 if not tokword 4 15 1625 if or tokpre 4 36 tokpre 4 37 1626 put res 3 hasall tokpre 4 37 1627 else 1628 put res 3 diffat 19 22 1629 end 1630 end 1631 if ne get gst 0 0 1632 invalid 1633 ret 1634 end 1635 emitsay 1636 end 1637 note token 3 after "sha:" is 64 lowercase hex digits 1638 fn hexok to bool 1639 if ne get tkl 3 68 1640 ret false 1641 end 1642 for i ulong 64 1643 c = get lst add add get tko 3 4 i 1644 if not or and ge c 48 le c 57 and ge c 97 le c 102 1645 ret false 1646 end 1647 end 1648 ret true 1649 end 1650 note sha256 of SCRATCH/.elf (into hexd) equals the hex of token 3 1651 fn shamatch to bool 1652 pfile 17 1653 if not hashfile 1654 setbad 22 1655 ret false 1656 end 1657 for i ulong 64 1658 if ne get hexd i get lst add add get tko 3 4 i 1659 ret false 1660 end 1661 end 1662 ret true 1663 end 1664 fn emitsay to void 1665 all = not ulong 0 1666 od = get res 2 1667 ed = get res 3 1668 ok = eq get res 1 get res 0 1669 ok = and ok eq get res 4 1 1670 ok = and ok and eq od all eq ed all 1671 if ok 1672 verdict 2 1673 else 1674 verdict 3 1675 end 1676 showexit get res 1 6 get res 0 1677 if tokword 3 15 1678 say 66 1679 end 1680 if tokpre 3 31 1681 say 35 1682 r = write 1 hexd 0 64 1683 if eq get res 4 0 1684 say 65 1685 r = write 1 lst add get tko 3 4 64 1686 end 1687 end 1688 if not or tokword 3 15 tokpre 3 31 1689 if eq od all 1690 say 9 1691 else 1692 say 10 1693 num od 1694 end 1695 end 1696 if tokword 4 15 1697 say 50 1698 else 1699 if eq ed all 1700 say 11 1701 else 1702 if or tokpre 4 36 tokpre 4 37 1703 say 70 1704 else 1705 say 12 1706 end 1707 num ed 1708 end 1709 end 1710 newline 1711 end 1712 note same: SRC1 and SRC2 both compile with exit 0 to byte-identical outputs (SRC2's files carry .b) 1713 fn samecase to void 1714 if ne get ntk 0 4 1715 setbad 20 1716 invalid 1717 ret 1718 end 1719 put sx 0 1 1720 mksrc 3 1721 c2 = compile false 1722 put sx 0 0 1723 if ne get gst 0 0 1724 invalid 1725 ret 1726 end 1727 mksrc 2 1728 c1 = compile false 1729 if ne get gst 0 0 1730 invalid 1731 ret 1732 end 1733 all = not ulong 0 1734 d = all 1735 both = and eq c1 0 eq c2 0 1736 if both 1737 put sx 1 1 1738 d = diffat 17 17 1739 put sx 1 0 1740 if ne get gst 0 0 1741 invalid 1742 ret 1743 end 1744 end 1745 if and both eq d all 1746 verdict 2 1747 else 1748 verdict 3 1749 end 1750 showexit c1 6 0 1751 say 69 1752 num c2 1753 if both 1754 if eq d all 1755 say 67 1756 else 1757 say 68 1758 num d 1759 end 1760 end 1761 newline 1762 end 1763 fn notruncase to void 1764 if lt get ntk 0 3 1765 setbad 20 1766 invalid 1767 ret 1768 end 1769 verdict 5 1770 say 57 1771 for i ulong sub get ntk 0 2 1772 space 1773 showtok add i 2 1774 end 1775 newline 1776 end 1777 fn dircc to void 1778 if ne get ntk 0 2 1779 setbad 20 1780 invalid 1781 ret 1782 end 1783 if tokword 1 8 1784 for i ulong get omn 0 1785 put ccp i get omc i 1786 end 1787 put ccn 0 get omn 0 1788 put ccbad 0 0 1789 say 49 1790 pomc 1791 showpb 1792 newline 1793 ret 1794 end 1795 put ccbad 0 1 1796 mksrc 1 1797 ce = compile true 1798 if ne get gst 0 0 1799 invalid 1800 ret 1801 end 1802 if ne ce 0 1803 verdict 3 1804 showexit ce 60 0 1805 newline 1806 ret 1807 end 1808 if not elfok 1809 if ne get gst 0 0 1810 invalid 1811 ret 1812 end 1813 verdict 3 1814 say 15 1815 newline 1816 ret 1817 end 1818 pfile 17 1819 for i ulong get pn 0 1820 put ccp i get pb i 1821 end 1822 put ccn 0 get pn 0 1823 if not hashfile 1824 setbad 22 1825 invalid 1826 ret 1827 end 1828 put ccbad 0 0 1829 say 49 1830 showpb 1831 say 35 1832 r = write 1 hexd 0 64 1833 say 62 1834 num get lno 0 1835 newline 1836 end 1837 fn dirdl to void 1838 if ne get ntk 0 2 1839 setbad 20 1840 invalid 1841 ret 1842 end 1843 s = decat get tko 1 get tkl 1 1844 if or eq s 0 gt s 900 1845 setbad 20 1846 end 1847 if ne get gst 0 0 1848 invalid 1849 ret 1850 end 1851 put dl 0 mul long s `1000000000` 1852 say 60 1853 num s 1854 newline 1855 end 1856 fn loadsub t ulong to ulong 1857 pclear 1858 plst get tko t get tkl t 1859 fd = popen 524288 1860 if lt fd 0 1861 setbad 21 1862 ret 0 1863 end 1864 r = rfulla fd 1865 if eq r long len buf 1866 x = read fd oth 0 1 1867 if ne x 0 1868 setbad 21 1869 end 1870 end 1871 fclo fd 1872 if lt r 0 1873 setbad 21 1874 ret 0 1875 end 1876 ret ulong r 1877 end 1878 fn dirsub to void 1879 if or ne get ntk 0 3 ne get sb 0 0 1880 put sb 0 0 1881 setbad 20 1882 invalid 1883 ret 1884 end 1885 n = loadsub 1 1886 for i ulong n 1887 put sfr i get buf i 1888 end 1889 m = loadsub 2 1890 for i ulong m 1891 put sto i get buf i 1892 end 1893 if eq n 0 1894 setbad 20 1895 end 1896 if ne get gst 0 0 1897 invalid 1898 ret 1899 end 1900 put sb 0 1 1901 put sb 1 n 1902 put sb 2 m 1903 say 61 1904 showtok 1 1905 space 1906 showtok 2 1907 newline 1908 end 1909 note one non-comment line, already split into tokens 1910 fn docase to void 1911 put gst 0 0 1912 if tokword 0 5 1913 dircc 1914 ret 1915 end 1916 if tokword 0 6 1917 dirdl 1918 ret 1919 end 1920 if tokword 0 7 1921 dirsub 1922 ret 1923 end 1924 header 1925 if lt get ntk 0 2 1926 setbad 20 1927 invalid 1928 ret 1929 end 1930 mode = ulong 0 1931 for k ulong 4 1932 if tokword 1 add k 1 1933 mode = add k 1 1934 end 1935 end 1936 if tokword 1 29 1937 mode = ulong 5 1938 end 1939 if tokword 1 30 1940 mode = ulong 6 1941 end 1942 if and ne get sb 0 0 or or eq mode 0 eq mode 4 eq mode 6 1943 put sb 0 0 1944 setbad 51 1945 invalid 1946 ret 1947 end 1948 if eq mode 0 1949 setbad 20 1950 invalid 1951 ret 1952 end 1953 if eq get idok 0 0 1954 put sb 0 0 1955 verdict 5 1956 say 46 1957 newline 1958 ret 1959 end 1960 if and ne get ccbad 0 0 ne mode 4 1961 put sb 0 0 1962 verdict 5 1963 say 45 1964 newline 1965 ret 1966 end 1967 if eq mode 1 1968 runcase false 1969 end 1970 if eq mode 2 1971 runcase true 1972 end 1973 if eq mode 3 1974 refusecase 1975 end 1976 if eq mode 5 1977 emitcase 1978 end 1979 if eq mode 6 1980 samecase 1981 end 1982 if eq mode 4 1983 notruncase 1984 end 1985 end 1986 fn lineend p ulong to ulong 1987 n = get lsn 0 1988 for i ulong sub n p 1989 if eq get lst add p i 10 1990 ret add p i 1991 end 1992 end 1993 ret n 1994 end 1995 fn tokenize p ulong e ulong to bool 1996 put ntk 0 0 1997 s = p 1998 inw = false 1999 for i ulong sub e p 2000 c = get lst add p i 2001 if eq c 32 2002 if inw 2003 k = get ntk 0 2004 put tkl k sub add p i s 2005 put ntk 0 add k 1 2006 inw = false 2007 end 2008 else 2009 if not inw 2010 if ge get ntk 0 len tko 2011 ret false 2012 end 2013 put tko get ntk 0 add p i 2014 s = add p i 2015 inw = true 2016 end 2017 end 2018 end 2019 if inw 2020 k = get ntk 0 2021 put tkl k sub e s 2022 put ntk 0 add k 1 2023 end 2024 ret true 2025 end 2026 fn runlist to void 2027 p = ulong 0 2028 ln = ulong 0 2029 while lt p get lsn 0 2030 ln = add ln 1 2031 put lno 0 ln 2032 e = lineend p 2033 if tokenize p e 2034 if gt get ntk 0 0 2035 if ne get lst get tko 0 35 2036 docase 2037 end 2038 end 2039 else 2040 put ntk 0 1 2041 put tkl 0 0 2042 put gst 0 20 2043 invalid 2044 end 2045 p = add e 1 2046 end 2047 if ne get sb 0 0 2048 say 1 2049 wordat 7 2050 r = write 1 words get wpos 0 get wpos 1 2051 say 4 2052 say 51 2053 newline 2054 put cnt 2 add get cnt 2 1 2055 end 2056 end 2057 fn summary to int 2058 pas = get cnt 0 2059 fal = get cnt 1 2060 inv = get cnt 2 2061 nr = get cnt 3 2062 tot = add add add pas fal inv nr 2063 rc = int 0 2064 s = ulong 25 2065 if gt nr 0 2066 rc = 2 2067 s = ulong 28 2068 end 2069 if gt fal 0 2070 rc = 1 2071 s = ulong 26 2072 end 2073 if or or gt inv 0 eq tot 0 eq get idok 0 0 2074 rc = 3 2075 s = ulong 27 2076 end 2077 say s 2078 say 29 2079 num tot 2080 say 30 2081 num pas 2082 say 31 2083 num fal 2084 say 32 2085 num inv 2086 say 33 2087 num nr 2088 if eq tot 0 2089 say 52 2090 end 2091 newline 2092 ret rc 2093 end 2094 fn identity to void 2095 pomc 2096 ok = hashfile 2097 say 34 2098 showpb 2099 say 35 2100 if ok 2101 r = write 1 hexd 0 64 2102 end 2103 say 36 2104 r = write 1 pin 0 64 2105 put idok 0 0 2106 if ok 2107 put idok 0 1 2108 for i ulong 64 2109 if ne get hexd i get pin i 2110 put idok 0 0 2111 end 2112 end 2113 end 2114 if eq get idok 0 1 2115 say 37 2116 else 2117 say 38 2118 end 2119 newline 2120 end 2121 fn loadlist to bool 2122 pclear 2123 r = argread 3 pb 0 4095 2124 if lt r 1 2125 ret false 2126 end 2127 put pn 0 ulong r 2128 fd = popen 524288 2129 if lt fd 0 2130 ret false 2131 end 2132 n = ulong 0 2133 while lt n len lst 2134 x = read fd lst n sub len lst n 2135 if le x 0 2136 fclo fd 2137 put lsn 0 n 2138 ret eq x 0 2139 end 2140 n = add n ulong x 2141 end 2142 x = read fd buf 0 1 2143 fclo fd 2144 put lsn 0 n 2145 ret eq x 0 2146 end 2147 fn main to int 2148 if ne argcnt 5 2149 say 53 2150 newline 2151 ret 90 2152 end 2153 put dl 0 `30000000000` 2154 r = argread 1 omc 0 4095 2155 if lt r 1 2156 say 53 2157 newline 2158 ret 90 2159 end 2160 put omn 0 ulong r 2161 for i ulong get omn 0 2162 put ccp i get omc i 2163 end 2164 put ccn 0 get omn 0 2165 r = argread 2 pin 0 64 2166 if ne r 64 2167 say 53 2168 newline 2169 ret 90 2170 end 2171 r = argread 4 scr 0 4094 2172 if lt r 1 2173 say 53 2174 newline 2175 ret 90 2176 end 2177 n = ulong r 2178 if ne makedir scr 0 n 448 0 2179 say 54 2180 newline 2181 ret 91 2182 end 2183 put scr n 47 2184 put scn 0 add n 1 2185 say 63 2186 r = argread 3 pb 0 4095 2187 put pn 0 ulong r 2188 showpb 2189 say 64 2190 r = write 1 scr 0 n 2191 newline 2192 if not loadnums 26 64 2193 say 55 2194 newline 2195 ret 3 2196 end 2197 for i ulong 64 2198 put kk i uint get nums i 2199 end 2200 if not loadnums 27 8 2201 say 55 2202 newline 2203 ret 3 2204 end 2205 for i ulong 8 2206 put ivs i uint get nums i 2207 end 2208 identity 2209 if not loadlist 2210 say 56 2211 newline 2212 ret 3 2213 end 2214 runlist 2215 ret summary 2216 end