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/apps/hop/Omega/hopcore.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 / apps / hop / Omega / hopcore.om` 5040 lines ยท 97566 bytes Raw Blame History 1 note hopcore: Hop's matching core, an Omega program built by Omega NG (ng front-ir, opt, a64 macho). It holds 2 note hopfuzz, the name matcher of the one box, and a main that serves it to Hop over stdin and stdout. 3 note Contract: Omega/README.md. 4 note One call scores typed text against one name: a whole match beats a prefix, which beats a later 5 note word start, initials, a plain "contains", one wrong letter, and letters in order with few gaps. 6 note The host lowercases both texts and sends one word per character: bits 0..31 a character id 7 note (equal characters get equal ids), bit 32 "letter or number", bit 33 "trimmable white space". 8 note Any malformed input fails closed as verdict 2 INVALID with the first faulting word; a text 9 note over the limits is INVALID, never cut short. Verdict 0 is "no match", 1 is "match" (score at 3). 10 11 fn isword w ulong to bool 12 ret ne and w `4294967296` 0 13 end 14 15 fn istrim w ulong to bool 16 ret ne and w `8589934592` 0 17 end 18 19 fn minu a ulong b ulong to ulong 20 if lt a b 21 ret a 22 end 23 ret b 24 end 25 26 note true when inp[a .. a+n) equals inp[b .. b+n); both runs must lie inside the buffer 27 fn same inp view ulong 256 a ulong b ulong n ulong to bool 28 for k ulong n 29 if ne get inp add a k get inp add b k 30 ret false 31 end 32 end 33 ret true 34 end 35 36 note x is one longer than y (ls characters): true when dropping one character of x gives y 37 fn skip1 inp view ulong 256 x ulong y ulong ls ulong to bool 38 k = ulong 0 39 while lt k ls bound 256 40 if ne get inp add x k get inp add y k 41 break 42 end 43 k = add k 1 44 end 45 ret same inp add x add k 1 add y k sub ls k 46 end 47 48 note edit distance at most 1, where swapping two neighbours counts as one 49 fn near inp view ulong 256 a ulong la ulong b ulong lb ulong to bool 50 if eq la lb 51 d = ulong 0 52 p = ulong 0 53 for k ulong la 54 if ne get inp add a k get inp add b k 55 if eq d 0 56 p = k 57 end 58 d = add d 1 59 end 60 end 61 if le d 1 62 ret true 63 end 64 if eq d 2 65 if lt add p 1 la 66 if eq get inp add a p get inp add b add p 1 67 if eq get inp add a add p 1 get inp add b p 68 ret true 69 end 70 end 71 end 72 end 73 ret false 74 end 75 if eq la add lb 1 76 ret skip1 inp a b lb 77 end 78 if eq lb add la 1 79 ret skip1 inp b a la 80 end 81 ret false 82 end 83 84 note score of q = inp[qa .. qa+ql) in the name inp[72 .. 72+nl); 0 means no match. ql and nl >= 1 85 fn one inp view ulong 256 qa ulong ql ulong nl ulong to ulong 86 if le ql nl 87 if same inp qa 72 ql 88 if eq ql nl 89 ret 200 90 end 91 ret sub 160 minu 30 sub nl ql 92 end 93 end 94 qw = true 95 for k ulong ql 96 if not isword get inp add qa k 97 qw = false 98 end 99 end 100 wc = ulong 0 101 later = false 102 inits = true 103 inw = false 104 for i ulong nl 105 c = get inp add 72 i 106 if isword c 107 if not inw 108 if lt wc ql 109 if ne c get inp add qa wc 110 inits = false 111 end 112 end 113 if gt wc 0 114 if qw 115 if le add i ql nl 116 if same inp qa add 72 i ql 117 later = true 118 end 119 end 120 end 121 end 122 wc = add wc 1 123 end 124 inw = true 125 else 126 inw = false 127 end 128 end 129 if later 130 ret sub 120 minu 20 div nl 3 131 end 132 if ge ql 2 133 if gt wc 1 134 if ge wc ql 135 if inits 136 ret 110 137 end 138 end 139 end 140 end 141 if le ql nl 142 for i ulong add sub nl ql 1 143 if same inp qa add 72 i ql 144 ret sub 80 minu 20 div nl 3 145 end 146 end 147 end 148 if ge ql 4 149 if le ql nl 150 if near inp qa ql 72 ql 151 ret 70 152 end 153 end 154 if le sub ql 1 nl 155 if near inp qa ql 72 sub ql 1 156 ret 70 157 end 158 end 159 if le add ql 1 nl 160 if near inp qa ql 72 add ql 1 161 ret 70 162 end 163 end 164 end 165 if lt ql 3 166 ret 0 167 end 168 qi = ulong 0 169 gaps = ulong 0 170 last = ulong 0 171 first = ulong 0 172 for i ulong nl 173 if lt qi ql 174 if eq get inp add 72 i get inp add qa qi 175 if gt qi 0 176 gaps = add gaps sub sub i last 1 177 else 178 first = i 179 end 180 last = i 181 qi = add qi 1 182 end 183 end 184 end 185 if ne qi ql 186 ret 0 187 end 188 if gt gaps ql 189 ret 0 190 end 191 t = add mul gaps 6 mul first 3 192 if ge t 45 193 ret 15 194 end 195 ret sub 60 t 196 end 197 198 note first faulting word plus 1, or 0 when the input is well formed 199 fn check inp view ulong 256 to ulong 200 if ne get inp 0 `1212568922` 201 ret 1 202 end 203 if ne get inp 1 1 204 ret 2 205 end 206 ql = get inp 2 207 nl = get inp 3 208 if gt ql 64 209 ret 3 210 end 211 if gt nl 184 212 ret 4 213 end 214 for i ulong 4 215 if ne get inp add 4 i 0 216 ret add 5 i 217 end 218 end 219 for i ulong 64 220 w = get inp add 8 i 221 if lt i ql 222 if ge w `17179869184` 223 ret add 9 i 224 end 225 if eq and w `4294967295` 0 226 ret add 9 i 227 end 228 else 229 if ne w 0 230 ret add 9 i 231 end 232 end 233 end 234 for i ulong 184 235 w = get inp add 72 i 236 if lt i nl 237 if ge w `17179869184` 238 ret add 73 i 239 end 240 if eq and w `4294967295` 0 241 ret add 73 i 242 end 243 else 244 if ne w 0 245 ret add 73 i 246 end 247 end 248 end 249 ret 0 250 end 251 252 fn hopfuzz inp view ulong 256 res edit ulong 256 to ulong 253 for i ulong 256 254 put res i 0 255 end 256 put res 0 `1212568922` 257 put res 1 1 258 e = check inp 259 if ne e 0 260 put res 2 2 261 put res 4 sub e 1 262 ret 2 263 end 264 nl = get inp 3 265 qa = ulong 8 266 qe = add 8 get inp 2 267 while lt qa qe bound 256 268 if not istrim get inp qa 269 break 270 end 271 qa = add qa 1 272 end 273 while gt qe qa bound 256 274 if not istrim get inp sub qe 1 275 break 276 end 277 qe = sub qe 1 278 end 279 ql = sub qe qa 280 if eq ql 0 281 ret 0 282 end 283 if eq nl 0 284 ret 0 285 end 286 s = one inp qa ql nl 287 if eq s 0 288 terms = ulong 0 289 sum = ulong 0 290 p = qa 291 while lt p qe bound 256 292 if eq and get inp p `4294967295` 32 293 p = add p 1 294 continue 295 end 296 b = p 297 while lt p qe bound 256 298 if eq and get inp p `4294967295` 32 299 break 300 end 301 p = add p 1 302 end 303 ts = one inp b sub p b nl 304 if eq ts 0 305 ret 0 306 end 307 terms = add terms 1 308 sum = add sum ts 309 end 310 if le terms 1 311 ret 0 312 end 313 s = sub div sum terms 10 314 end 315 put res 2 1 316 put res 3 s 317 ret 1 318 end 319 320 note ---- file-name scoring (kind 2): how well a path found on another machine matches the typed terms ---- 321 note The host sends bytes: the terms, and for each path its lowercased bytes, the lowercased bytes of its last 322 note component (its name), and the byte length of the path as written. A term found in the name scores 60 when the name 323 note starts with it and 30 otherwise; found only elsewhere in the path it scores 5; a term found nowhere, or an 324 note empty term, means no match. One point less for every 20 bytes of path; 40 more when the name is exactly as long as the terms. 325 326 fn rd16 b view uchar `1048576` o ulong to ulong 327 ret or ulong get b o shl ulong get b add o 1 8 328 end 329 330 fn rd32 b view uchar `1048576` o ulong to ulong 331 ret or rd16 b o shl rd16 b add o 2 16 332 end 333 334 note true when b[x .. x+n) equals b[y .. y+n) 335 fn beq b view uchar `1048576` x ulong y ulong n ulong to bool 336 for k ulong n 337 if ne get b add x k get b add y k 338 ret false 339 end 340 end 341 ret true 342 end 343 344 note true when the run b[t .. t+tl) occurs in b[h .. h+hl) 345 fn bhas b view uchar `1048576` h ulong hl ulong t ulong tl ulong to bool 346 if gt tl hl 347 ret false 348 end 349 for i ulong add sub hl tl 1 350 if beq b add h i t tl 351 ret true 352 end 353 end 354 ret false 355 end 356 357 note score of one path plus `1000000`, or 0 for no match. pm: 0 the number of terms, 1 where the path's bytes 358 note start, 2 how many, 3 where its name's bytes start, 4 how many, 5 the path's length as written 359 fn fscore b view uchar `1048576` toff view ulong 64 tlen view ulong 64 pm view ulong 8 to ulong 360 nt = get pm 0 361 p = get pm 1 362 pl = get pm 2 363 ns = get pm 3 364 nl = get pm 4 365 ol = get pm 5 366 s = ulong `1000000` 367 sum = ulong 0 368 for k ulong nt 369 t = get toff k 370 tl = get tlen k 371 sum = add sum tl 372 if eq tl 0 373 ret 0 374 end 375 if bhas b ns nl t tl 376 if beq b ns t tl 377 s = add s 60 378 else 379 s = add s 30 380 end 381 else 382 if bhas b p pl t tl 383 s = add s 5 384 else 385 ret 0 386 end 387 end 388 end 389 s = sub s div ol 20 390 if eq nl sum 391 s = add s 40 392 end 393 ret s 394 end 395 396 note ---- text decisions (kind 3): is it a question, which words to search for, is it a web address ---- 397 note The host lowercases the text and sends one 8-byte word per character: bits 0..31 an id (equal characters get 398 note equal ids; a character of one Unicode scalar has that scalar's number), then a flag byte: 1 letter or number, 399 note 2 trimmable white space, 4 white space, 8 white space or line end. 400 note lists: three lists of plain words, separated by "|": 0 the words a question starts with, 1 the words a search 401 note leaves out, 2 the endings of a bare web address. 402 text lists "what what's whats why how how's who who's whom whose when where which explain define translate summarize summarise describe|the and for with that this what when where does did how why can you are was were have has from into about please make need want just our my its not|com org net io dev ai co edu gov xyz me us uk ca de tv gg" 403 404 fn cid b view uchar `1048576` i ulong to ulong 405 ret rd32 b add 16 mul i 8 406 end 407 408 fn cfl b view uchar `1048576` i ulong to ulong 409 ret ulong get b add 20 mul i 8 410 end 411 412 note true when the n characters from s are exactly one word of list sec 413 fn inlist b view uchar `1048576` s ulong n ulong sec ulong to bool 414 cur = ulong 0 415 p = ulong 0 416 ln = len lists 417 while lt p ln bound 999999 418 e = p 419 while lt e ln bound 999999 420 c = ulong get lists e 421 if or eq c 32 eq c 124 422 break 423 end 424 e = add e 1 425 end 426 if eq cur sec 427 if eq sub e p n 428 ok = true 429 for k ulong n 430 if ne cid b add s k ulong get lists add p k 431 ok = false 432 end 433 end 434 if ok 435 ret true 436 end 437 end 438 end 439 if lt e ln 440 if eq ulong get lists e 124 441 cur = add cur 1 442 end 443 end 444 p = add e 1 445 end 446 ret false 447 end 448 449 note op 1: 1 when the text reads as a question: it ends with "?" and is longer than that, or it has three words 450 note or more and starts with a question word 451 fn qlike b view uchar `1048576` n ulong to ulong 452 a = ulong 0 453 e = n 454 while lt a e bound 999999 455 if eq and cfl b a 8 0 456 break 457 end 458 a = add a 1 459 end 460 while gt e a bound 999999 461 if eq and cfl b sub e 1 8 0 462 break 463 end 464 e = sub e 1 465 end 466 if gt sub e a 1 467 if eq cid b sub e 1 63 468 ret 1 469 end 470 end 471 w = ulong 0 472 fs = ulong 0 473 fl = ulong 0 474 i = a 475 while lt i e bound 999999 476 if ne and cfl b i 4 0 477 i = add i 1 478 continue 479 end 480 st = i 481 while lt i e bound 999999 482 if ne and cfl b i 4 0 483 break 484 end 485 i = add i 1 486 end 487 if eq w 0 488 fs = st 489 fl = sub i st 490 end 491 w = add w 1 492 end 493 if lt w 3 494 ret 0 495 end 496 if inlist b fs fl 0 497 ret 1 498 end 499 ret 0 500 end 501 502 note a character of a search word: a letter, a number, "-", "_" or "." 503 fn iswc b view uchar `1048576` i ulong to bool 504 if ne and cfl b i 1 0 505 ret true 506 end 507 c = cid b i 508 if eq c 45 509 ret true 510 end 511 if eq c 95 512 ret true 513 end 514 ret eq c 46 515 end 516 517 fn samec b view uchar `1048576` x ulong y ulong n ulong to bool 518 for k ulong n 519 if ne cid b add x k cid b add y k 520 ret false 521 end 522 end 523 ret true 524 end 525 526 note true when the word of wl characters at st also stands earlier in the text 527 fn seen b view uchar `1048576` st ulong wl ulong to bool 528 i = ulong 0 529 while lt i st bound 999999 530 if not iswc b i 531 i = add i 1 532 continue 533 end 534 s0 = i 535 while lt i st bound 999999 536 if not iswc b i 537 break 538 end 539 i = add i 1 540 end 541 if eq sub i s0 wl 542 if samec b s0 st wl 543 ret true 544 end 545 end 546 end 547 ret false 548 end 549 550 note op 2: the words to search for: three characters or more, not a left-out word, each once, the longest four, 551 note longest first and in the order typed among equals. Writes the count, then where each starts and its length 552 fn keyw b view uchar `1048576` n ulong ob edit uchar 65544 to ulong 553 ts = new ulong 4 0 554 tl = new ulong 4 0 555 k = ulong 0 556 i = ulong 0 557 while lt i n bound 999999 558 if not iswc b i 559 i = add i 1 560 continue 561 end 562 st = i 563 while lt i n bound 999999 564 if not iswc b i 565 break 566 end 567 i = add i 1 568 end 569 wl = sub i st 570 if lt wl 3 571 continue 572 end 573 if inlist b st wl 1 574 continue 575 end 576 if seen b st wl 577 continue 578 end 579 pos = k 580 for j ulong k 581 if lt get tl j wl 582 if eq pos k 583 pos = j 584 end 585 end 586 end 587 if lt pos 4 588 for d ulong sub 3 pos 589 u = sub 3 d 590 put tl u get tl sub u 1 591 put ts u get ts sub u 1 592 end 593 put tl pos wl 594 put ts pos st 595 if lt k 4 596 k = add k 1 597 end 598 end 599 end 600 put ob 8 uchar k 601 for j ulong k 602 s = get ts j 603 l = get tl j 604 put ob add 9 mul j 4 uchar and s 255 605 put ob add 10 mul j 4 uchar shr s 8 606 put ob add 11 mul j 4 uchar and l 255 607 put ob add 12 mul j 4 uchar shr l 8 608 end 609 ret add 1 mul k 4 610 end 611 612 fn hasscheme b view uchar `1048576` n ulong to bool 613 if lt n 7 614 ret false 615 end 616 if ne cid b 0 104 617 ret false 618 end 619 if ne cid b 1 116 620 ret false 621 end 622 if ne cid b 2 116 623 ret false 624 end 625 if ne cid b 3 112 626 ret false 627 end 628 o = ulong 4 629 if eq cid b 4 115 630 o = ulong 5 631 end 632 if lt n add o 3 633 ret false 634 end 635 if ne cid b o 58 636 ret false 637 end 638 if ne cid b add o 1 47 639 ret false 640 end 641 ret eq cid b add o 2 47 642 end 643 644 note op 3: 0 not a web address; 1 it starts with http:// or https:// (the host then checks that it names a 645 note machine); 2 a bare address such as example.com/page (the host then checks that it parses). aux: the text's 646 note length in bytes as written 647 fn weba b view uchar `1048576` n ulong aux ulong to ulong 648 if eq n 0 649 ret 0 650 end 651 if ge aux 2000 652 ret 0 653 end 654 for i ulong n 655 if ne and cfl b i 4 0 656 ret 0 657 end 658 end 659 if hasscheme b n 660 ret 1 661 end 662 h0 = ulong 0 663 while lt h0 n bound 999999 664 if ne cid b h0 47 665 break 666 end 667 h0 = add h0 1 668 end 669 h1 = h0 670 while lt h1 n bound 999999 671 if eq cid b h1 47 672 break 673 end 674 h1 = add h1 1 675 end 676 parts = ulong 0 677 ps = h0 678 i = h0 679 while le i h1 bound 999999 680 atend = eq i h1 681 dot = false 682 if not atend 683 dot = eq cid b i 46 684 end 685 if or atend dot 686 if eq i ps 687 ret 0 688 end 689 parts = add parts 1 690 if atend 691 if lt parts 2 692 ret 0 693 end 694 if inlist b ps sub i ps 2 695 ret 2 696 end 697 ret 0 698 end 699 ps = add i 1 700 else 701 if eq and cfl b i 1 0 702 if ne cid b i 45 703 ret 0 704 end 705 end 706 end 707 i = add i 1 708 end 709 ret 0 710 end 711 712 note the single-character edits that turn one spelling into another, on letters and numbers only. r: 0 and 1 the 713 note first spelling's characters [from, to), 2 and 3 the second's. Writes 4 the edits and 5 the longer length. 714 note Returns 1, and writes nothing, when a spelling has more than 4096 letters and numbers 715 fn edist b view uchar `1048576` r edit ulong 8 to ulong 716 xa = new ulong 4096 0 717 ya = new ulong 4096 0 718 row = new ulong 4097 0 719 xc = ulong 0 720 yc = ulong 0 721 i = get r 0 722 x1 = get r 1 723 while lt i x1 bound 999999 724 if ne and cfl b i 1 0 725 if ge xc 4096 726 ret 1 727 end 728 put xa xc cid b i 729 xc = add xc 1 730 end 731 i = add i 1 732 end 733 i = get r 2 734 y1 = get r 3 735 while lt i y1 bound 999999 736 if ne and cfl b i 1 0 737 if ge yc 4096 738 ret 1 739 end 740 put ya yc cid b i 741 yc = add yc 1 742 end 743 i = add i 1 744 end 745 for j ulong add yc 1 746 put row j j 747 end 748 for k ulong xc 749 prev = get row 0 750 put row 0 add k 1 751 xi = get xa k 752 for j ulong yc 753 cur = get row add j 1 754 v = add cur 1 755 w = add get row j 1 756 if lt w v 757 v = w 758 end 759 w = prev 760 if ne xi get ya j 761 w = add prev 1 762 end 763 if lt w v 764 v = w 765 end 766 put row add j 1 v 767 prev = cur 768 end 769 end 770 m = xc 771 if gt yc m 772 m = yc 773 end 774 put r 4 get row yc 775 put r 5 m 776 ret 0 777 end 778 779 note op 4: how alike two spellings are. The text is the first spelling (aux characters), then the second. Writes 780 note the edits and the longer length, each as a 16-bit number; the host divides 781 fn alike b view uchar `1048576` n ulong aux ulong ob edit uchar 65544 to ulong 782 r = new ulong 8 0 783 bad = ulong `18446744073709551615` 784 if gt aux n 785 ret bad 786 end 787 put r 0 0 788 put r 1 aux 789 put r 2 aux 790 put r 3 n 791 if ne edist b r 0 792 ret bad 793 end 794 d = get r 4 795 m = get r 5 796 put ob 8 uchar and d 255 797 put ob 9 uchar shr d 8 798 put ob 10 uchar and m 255 799 put ob 11 uchar shr m 8 800 ret 4 801 end 802 803 note op 5: which run of typed words is the fix for what was heard. The text is what was heard (aux characters), 804 note then up to four runs: the first typed word, the first two, the first three, the first four; flag 16 marks the 805 note last character of each run. Each run is compared with what was heard (fn edist); the most alike wins, the 806 note shorter run among equals. Returns which run (1 to 4), or 0 for no fix: the winner is less than half alike, or 807 note is the very text that was heard (the host says which runs are: bit k-1 of sm). 255: a spelling is too long 808 fn pick b view uchar `1048576` n ulong aux ulong sm ulong to ulong 809 r = new ulong 8 0 810 if gt aux n 811 ret 255 812 end 813 bk = ulong 0 814 bn = ulong 0 815 bd = ulong 1 816 k = ulong 0 817 i = aux 818 while lt i n bound 999999 819 e = i 820 while lt e n bound 999999 821 f = cfl b e 822 e = add e 1 823 if ne and f 16 0 824 break 825 end 826 end 827 k = add k 1 828 if gt k 4 829 break 830 end 831 put r 0 0 832 put r 1 aux 833 put r 2 i 834 put r 3 e 835 if ne edist b r 0 836 ret 255 837 end 838 m = get r 5 839 nu = ulong 1 840 de = ulong 1 841 if gt m 0 842 nu = sub m get r 4 843 de = m 844 end 845 if eq bk 0 846 bk = k 847 bn = nu 848 bd = de 849 else 850 if gt mul nu bd mul bn de 851 bk = k 852 bn = nu 853 bd = de 854 end 855 end 856 i = e 857 end 858 if eq bk 0 859 ret 0 860 end 861 if lt mul bn 2 bd 862 ret 0 863 end 864 if ne and shr sm sub bk 1 1 0 865 ret 0 866 end 867 ret bk 868 end 869 870 note kind 3: op, the number of characters n (at most 16384), aux and 0 as four 32-bit numbers, then n character 871 note words. Returns the reply length, or `18446744073709551615` for a malformed body or an unknown op 872 fn texts ib view uchar `1048576` nb ulong ob edit uchar 65544 to ulong 873 bad = ulong `18446744073709551615` 874 if lt nb 16 875 ret bad 876 end 877 op = rd32 ib 0 878 n = rd32 ib 4 879 aux = rd32 ib 8 880 if gt n 16384 881 ret bad 882 end 883 if ne nb add 16 mul n 8 884 ret bad 885 end 886 if eq op 1 887 put ob 8 uchar qlike ib n 888 ret 1 889 end 890 if eq op 2 891 ret keyw ib n ob 892 end 893 if eq op 3 894 put ob 8 uchar weba ib n aux 895 ret 1 896 end 897 if eq op 4 898 ret alike ib n aux ob 899 end 900 if eq op 5 901 put ob 8 uchar pick ib n aux rd32 ib 12 902 ret 1 903 end 904 ret bad 905 end 906 907 note ---- the helper process ---- 908 note hopcore main: Hop's core as a helper process. A request is 8 bytes (kind, then body length n, both 32-bit 909 note little-endian) and n body bytes, n at most `1048576`. The reply is 8 bytes (status, then length m) and m bytes. 910 note Status 0 is an answer; 1 an unknown kind; 2 a malformed body. End of input ends it with status 0; a body 911 note over the limit or a short read ends it with status 3 (the host starts a fresh one). 912 note Kind 1, names: the body is k cases of 2048 bytes (256 words, the hopfuzz input); 3 bytes back per case: 913 note verdict, score low byte, score high byte. At most 512 cases. 914 note Kind 2, paths: 16-bit little-endian fields: number of terms (at most 64), number of paths (at most 16000); 915 note each term as length then bytes; each path as three lengths (its lowercased bytes, its name's lowercased 916 note bytes, the path as written), then the path bytes, then the name bytes. 4 bytes back per path: 0 for no 917 note match, else the score plus `1000000`. 918 note Kind 3, text: see fn texts. Op 1 and op 3 answer one byte; op 2 a count, then two 16-bit numbers a word; 919 note op 4 two 16-bit numbers; op 5 one byte. 920 note Kind 4, corrected words: see fn wdiff. Kind 5, a board line or a time: see fn board. Kind 6, a whole board: see fn asm. Kind 7, the members' state and the graph: see fn status. 921 922 note fill b[0 .. n) from stdin; false at end of input or on a short read 923 fn rdn b edit uchar `1048576` n ulong to bool 924 got = ulong 0 925 while lt got n bound 999999 926 k = read 0 b got sub n got 927 if le k 0 928 ret false 929 end 930 got = add got ulong k 931 end 932 ret true 933 end 934 935 fn wrn b view uchar 65544 n ulong to bool 936 p = ulong 0 937 while lt p n bound 999999 938 k = write 1 b p sub n p 939 if le k 0 940 ret false 941 end 942 p = add p ulong k 943 end 944 ret true 945 end 946 947 fn put32 b edit uchar 65544 o ulong v ulong to void 948 put b o uchar and v 255 949 put b add o 1 uchar and shr v 8 255 950 put b add o 2 uchar and shr v 16 255 951 put b add o 3 uchar and shr v 24 255 952 end 953 954 note kind 1: returns the reply length, or `18446744073709551615` for a malformed body 955 note ---- one line of a plain-text board (kind 5) ---- 956 note A swarm's board is a text file, one post a line: 957 note