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
omega-mv / seed / kflow / kflow.om
| 1 | note kflow.om -- KernelFlow milestone 1 conductor, seeded Omega (OM-2), built with seed/out/omc. |
| 2 | note usage (from the omega-mv root): kflow SPEC STATE |
| 3 | note SPEC lines ('#' starts a comment): |
| 4 | note tool NAME PATH NAME is asm2, nvdisasm, cuobjdump, kemu or kpack; all five are required |
| 5 | note tsub LINE OLD NEW next job only: in the table line whose name is LINE, token OLD becomes NEW |
| 6 | note lsub OLD NEW next job only: in the listing, token OLD becomes NEW (exactly one hit) |
| 7 | note nointent next job only: ignore ';=' intent lines in the listing |
| 8 | note job NAME ARCH TABLE LISTING REF HARNESS REGS P... ARCH 80|121, REF a referee .bin or '-', |
| 9 | note HARNESS a kemu harness or '-', P each p8|1|2|4|8 (kpack parameter sizes) |
| 10 | note expect STAGE STATUS about the job just above; STAGE encode|verify|package|emulate|gpu|cloud|job |
| 11 | note Stages: encode (asm2), verify (nvdisasm decode + referee bytes or ';=' intent texts), package |
| 12 | note (kpack cubin, cuobjdump -sass texts must equal the verify texts), emulate (kemu), gpu and cloud |
| 13 | note (queued job files only). Status is NOT_RUN, INVALID, INCOMPLETE, VALID-UNPROVEN or QUALIFIED; |
| 14 | note M1 never reaches QUALIFIED. INVALID stops the job. Each stage result is cached under |
| 15 | note STATE/cache/KEY.* where KEY = sha256(stage, tool sha256, input sha256s, parameters). |
| 16 | note Exit 0 when every expectation held, 1 when one failed, 2 on a spec or setup error. |
| 17 | text wd "/cache/\n/work/\n/jobs/\n/queue/gpu/\n/queue/cloud/\n.bin\n.dis\n.cubin\n.cdis\n.emu\n.st\n.in\n.int\n.err\n.receipt\n.job\nkey\nSM\n-b\n-sass\n20261026\n0\n/queue\n.log\nseed/qualification/om2/fixtures/sha256-k.dec\nseed/qualification/om2/fixtures/sha256-iv.dec\n/dev/null\nencode\nverify\npackage\nemulate\ngpu\ncloud\njob\nNOT_RUN\nINVALID\nINCOMPLETE\nVALID-UNPROVEN\nQUALIFIED\nasm2\nnvdisasm\ncuobjdump\nkemu\nkpack\ntool\njob\ntsub\nlsub\nnointent\nexpect\nkflow: \nhit\nmiss\n-\nkflow: spec error at line \nkflow: expect FAIL line \nKFLOW expectations met=\n failed=\n cache=\n key=\nname=\narch=\ncubin=\ncubin_sha256=\nharness=\nseed=\nstatus=NOT_RUN\nparams=\nregs=\nkflow-m1: no stage is QUALIFIED; gpu and cloud are queued job files, not runs\nbin_sha256=\nNOP\nrequires=gpu-window\nrequires=cloud-budget-cap\n got \n jobs=\n/jobs\n/cache\n/work\n/queue/gpu\n/queue/cloud\nkflow: usage: kflow SPEC STATE\n80\n121\n.cerr\nkflow: cannot read the SHA-256 fixtures (run from the omega-mv root)\ncanon INVALID (input unreadable, or tsub/lsub did not hit exactly once)\n/\n=\n \n, expected \n" |
| 18 | global spc uchar 262144 |
| 19 | global pb uchar 4096 |
| 20 | global pn ulong 1 |
| 21 | global ob uchar 65536 |
| 22 | global on ulong 1 |
| 23 | global fa uchar 1048576 |
| 24 | global fc uchar 1048576 |
| 25 | global cn ulong 1 |
| 26 | global ib uchar 262144 |
| 27 | global inn ulong 1 |
| 28 | global nx uchar 1048576 |
| 29 | global nn ulong 1 |
| 30 | global av uchar 4096 |
| 31 | global ap ulong 2 |
| 32 | global tko ulong 48 |
| 33 | global tkl ulong 48 |
| 34 | global ntk ulong 1 |
| 35 | global tp uchar 1280 |
| 36 | global tpl ulong 8 |
| 37 | global th uchar 320 |
| 38 | global sth uchar 256 |
| 39 | global stl ulong 1 |
| 40 | global md ulong 20 |
| 41 | global sk uchar 512 |
| 42 | global ss ulong 8 |
| 43 | global sh ulong 8 |
| 44 | global jn ulong 4 |
| 45 | global cnt ulong 4 |
| 46 | global hexd uchar 64 |
| 47 | global hb uchar 64 |
| 48 | global hd uchar 64 |
| 49 | global wv ulong 2 |
| 50 | global dig uchar 32 |
| 51 | global stb uchar 4 |
| 52 | global buf uchar 65536 |
| 53 | global kk uint 64 |
| 54 | global ivs uint 8 |
| 55 | global hv uint 8 |
| 56 | global ws uint 64 |
| 57 | global st uint 8 |
| 58 | global blk uchar 64 |
| 59 | global bk ulong 2 |
| 60 | global nums ulong 64 |
| 61 | note md: 0-5 tsub LINE/OLD/NEW (offset,length into spc), 6-9 lsub OLD/NEW, 10 nointent, 11 tsub set, |
| 62 | note 12 lsub set, 13-16 the active substitution. jn: 1 line number, 3 job status. cnt: 0 met, 1 failed, 2 jobs. |
| 63 | note ---- words and builders ------------------------------------------------------------------------- |
| 64 | fn wlook id ulong to void |
| 65 | k = ulong 1 |
| 66 | s = ulong 0 |
| 67 | for i ulong len wd |
| 68 | if eq get wd i 10 |
| 69 | if eq k id |
| 70 | put wv 0 s |
| 71 | put wv 1 sub i s |
| 72 | ret |
| 73 | end |
| 74 | k = add k 1 |
| 75 | s = add i 1 |
| 76 | end |
| 77 | end |
| 78 | exit 99 |
| 79 | end |
| 80 | fn isbl c uchar to bool |
| 81 | ret or or eq c 32 eq c 9 eq c 13 |
| 82 | end |
| 83 | fn pclear to void |
| 84 | put pn 0 0 |
| 85 | end |
| 86 | fn pbyte b uchar to void |
| 87 | n = get pn 0 |
| 88 | if ge n sub len pb 1 |
| 89 | exit 98 |
| 90 | end |
| 91 | put pb n b |
| 92 | put pn 0 add n 1 |
| 93 | end |
| 94 | fn pword id ulong to void |
| 95 | wlook id |
| 96 | o = get wv 0 |
| 97 | for i ulong get wv 1 |
| 98 | pbyte get wd add o i |
| 99 | end |
| 100 | end |
| 101 | fn ptok t ulong to void |
| 102 | o = get tko t |
| 103 | for i ulong get tkl t |
| 104 | pbyte get spc add o i |
| 105 | end |
| 106 | end |
| 107 | fn pstate to void |
| 108 | for i ulong get stl 0 |
| 109 | pbyte get sth i |
| 110 | end |
| 111 | end |
| 112 | fn phex k ulong to void |
| 113 | for i ulong 64 |
| 114 | pbyte get sk add mul k 64 i |
| 115 | end |
| 116 | end |
| 117 | fn pcache k ulong ext ulong to void |
| 118 | pclear |
| 119 | pstate |
| 120 | pword 1 |
| 121 | phex k |
| 122 | pword ext |
| 123 | end |
| 124 | fn pwork ext ulong to void |
| 125 | pclear |
| 126 | pstate |
| 127 | pword 2 |
| 128 | ptok 1 |
| 129 | pword ext |
| 130 | end |
| 131 | fn obyte c uchar to void |
| 132 | n = get on 0 |
| 133 | if ge n len ob |
| 134 | exit 96 |
| 135 | end |
| 136 | put ob n c |
| 137 | put on 0 add n 1 |
| 138 | end |
| 139 | fn oword id ulong to void |
| 140 | wlook id |
| 141 | o = get wv 0 |
| 142 | for i ulong get wv 1 |
| 143 | obyte get wd add o i |
| 144 | end |
| 145 | end |
| 146 | fn otok t ulong to void |
| 147 | o = get tko t |
| 148 | for i ulong get tkl t |
| 149 | obyte get spc add o i |
| 150 | end |
| 151 | end |
| 152 | fn onl to void |
| 153 | obyte 10 |
| 154 | end |
| 155 | fn ohexd to void |
| 156 | for i ulong 64 |
| 157 | obyte get hexd i |
| 158 | end |
| 159 | end |
| 160 | fn ohb to void |
| 161 | for i ulong 64 |
| 162 | obyte get hb i |
| 163 | end |
| 164 | end |
| 165 | fn ohd to void |
| 166 | for i ulong 64 |
| 167 | obyte get hd i |
| 168 | end |
| 169 | end |
| 170 | fn otool k ulong to void |
| 171 | for i ulong 64 |
| 172 | obyte get th add mul k 64 i |
| 173 | end |
| 174 | end |
| 175 | fn ohex k ulong to void |
| 176 | for i ulong 64 |
| 177 | obyte get sk add mul k 64 i |
| 178 | end |
| 179 | end |
| 180 | fn opb to void |
| 181 | for i ulong get pn 0 |
| 182 | obyte get pb i |
| 183 | end |
| 184 | end |
| 185 | fn ostat s ulong to void |
| 186 | oword add 35 s |
| 187 | end |
| 188 | fn onum v ulong to void |
| 189 | x = v |
| 190 | n = ulong 0 |
| 191 | while ge x 10 bound 64 |
| 192 | put dig n uchar add 48 rem x 10 |
| 193 | x = div x 10 |
| 194 | n = add n 1 |
| 195 | end |
| 196 | put dig n uchar add 48 x |
| 197 | n = add n 1 |
| 198 | for i ulong n |
| 199 | obyte get dig sub sub n i 1 |
| 200 | end |
| 201 | end |
| 202 | fn sob to void |
| 203 | r = write 1 ob 0 get on 0 |
| 204 | put on 0 0 |
| 205 | end |
| 206 | fn say id ulong to void |
| 207 | put on 0 0 |
| 208 | oword id |
| 209 | onl |
| 210 | sob |
| 211 | end |
| 212 | fn cbyte c uchar to void |
| 213 | n = get cn 0 |
| 214 | if ge n len fc |
| 215 | exit 95 |
| 216 | end |
| 217 | put fc n c |
| 218 | put cn 0 add n 1 |
| 219 | end |
| 220 | fn ibyte c uchar to void |
| 221 | n = get inn 0 |
| 222 | if ge n len ib |
| 223 | exit 94 |
| 224 | end |
| 225 | put ib n c |
| 226 | put inn 0 add n 1 |
| 227 | end |
| 228 | fn nbyte c uchar to void |
| 229 | n = get nn 0 |
| 230 | if ge n len nx |
| 231 | exit 93 |
| 232 | end |
| 233 | put nx n c |
| 234 | put nn 0 add n 1 |
| 235 | end |
| 236 | note ---- files ------------------------------------------------------------------------------------- |
| 237 | fn ropen to int |
| 238 | r = fopen pb 0 get pn 0 524288 0 |
| 239 | if lt r 0 |
| 240 | ret -1 |
| 241 | end |
| 242 | ret int r |
| 243 | end |
| 244 | fn wopen to int |
| 245 | r = fopen pb 0 get pn 0 524865 420 |
| 246 | if lt r 0 |
| 247 | ret -1 |
| 248 | end |
| 249 | ret int r |
| 250 | end |
| 251 | fn fclo fd int to void |
| 252 | if ge fd 0 |
| 253 | r = fclose fd |
| 254 | end |
| 255 | end |
| 256 | fn rda to long |
| 257 | fd = ropen |
| 258 | if lt fd 0 |
| 259 | ret -1 |
| 260 | end |
| 261 | n = ulong 0 |
| 262 | while true |
| 263 | r = read fd fa n sub len fa n |
| 264 | if le r 0 |
| 265 | fclo fd |
| 266 | if lt r 0 |
| 267 | ret -1 |
| 268 | end |
| 269 | ret long n |
| 270 | end |
| 271 | n = add n ulong r |
| 272 | if ge n len fa |
| 273 | fclo fd |
| 274 | ret -1 |
| 275 | end |
| 276 | end |
| 277 | ret -1 |
| 278 | end |
| 279 | fn rdc to long |
| 280 | fd = ropen |
| 281 | if lt fd 0 |
| 282 | ret -1 |
| 283 | end |
| 284 | n = ulong 0 |
| 285 | while true |
| 286 | r = read fd fc n sub len fc n |
| 287 | if le r 0 |
| 288 | fclo fd |
| 289 | if lt r 0 |
| 290 | ret -1 |
| 291 | end |
| 292 | ret long n |
| 293 | end |
| 294 | n = add n ulong r |
| 295 | if ge n len fc |
| 296 | fclo fd |
| 297 | ret -1 |
| 298 | end |
| 299 | end |
| 300 | ret -1 |
| 301 | end |
| 302 | fn rds to long |
| 303 | fd = ropen |
| 304 | if lt fd 0 |
| 305 | ret -1 |
| 306 | end |
| 307 | n = ulong 0 |
| 308 | while true |
| 309 | r = read fd spc n sub len spc n |
| 310 | if le r 0 |
| 311 | fclo fd |
| 312 | if lt r 0 |
| 313 | ret -1 |
| 314 | end |
| 315 | ret long n |
| 316 | end |
| 317 | n = add n ulong r |
| 318 | if ge n len spc |
| 319 | fclo fd |
| 320 | ret -1 |
| 321 | end |
| 322 | end |
| 323 | ret -1 |
| 324 | end |
| 325 | fn wob to bool |
| 326 | fd = wopen |
| 327 | if lt fd 0 |
| 328 | ret false |
| 329 | end |
| 330 | w = write fd ob 0 get on 0 |
| 331 | c = fclose fd |
| 332 | ret and eq w long get on 0 eq c 0 |
| 333 | end |
| 334 | fn wfc to bool |
| 335 | fd = wopen |
| 336 | if lt fd 0 |
| 337 | ret false |
| 338 | end |
| 339 | w = write fd fc 0 get cn 0 |
| 340 | c = fclose fd |
| 341 | ret and eq w long get cn 0 eq c 0 |
| 342 | end |
| 343 | fn wfi to bool |
| 344 | fd = wopen |
| 345 | if lt fd 0 |
| 346 | ret false |
| 347 | end |
| 348 | w = write fd ib 0 get inn 0 |
| 349 | c = fclose fd |
| 350 | ret and eq w long get inn 0 eq c 0 |
| 351 | end |
| 352 | fn mkd id ulong to void |
| 353 | pclear |
| 354 | pstate |
| 355 | if ne id 0 |
| 356 | pword id |
| 357 | end |
| 358 | r = makedir pb 0 get pn 0 493 |
| 359 | end |
| 360 | note ---- children (pattern from seed/qualification/om2/gate.om) ------------------------------------- |
| 361 | fn aclear to void |
| 362 | put ap 0 2 |
| 363 | put ap 1 0 |
| 364 | end |
| 365 | fn ahead n ulong to void |
| 366 | p = get ap 0 |
| 367 | if or gt add add p n 2 len av ge get ap 1 64 |
| 368 | exit 97 |
| 369 | end |
| 370 | put av p uchar and n 255 |
| 371 | put av add p 1 uchar shr n 8 |
| 372 | put ap 0 add p 2 |
| 373 | put ap 1 add get ap 1 1 |
| 374 | end |
| 375 | fn aput c uchar to void |
| 376 | p = get ap 0 |
| 377 | put av p c |
| 378 | put ap 0 add p 1 |
| 379 | end |
| 380 | fn apb to void |
| 381 | ahead get pn 0 |
| 382 | for i ulong get pn 0 |
| 383 | aput get pb i |
| 384 | end |
| 385 | end |
| 386 | fn atok t ulong to void |
| 387 | ahead get tkl t |
| 388 | o = get tko t |
| 389 | for i ulong get tkl t |
| 390 | aput get spc add o i |
| 391 | end |
| 392 | end |
| 393 | fn aword id ulong to void |
| 394 | wlook id |
| 395 | ahead get wv 1 |
| 396 | o = get wv 0 |
| 397 | for i ulong get wv 1 |
| 398 | aput get wd add o i |
| 399 | end |
| 400 | end |
| 401 | fn atool k ulong to void |
| 402 | n = get tpl k |
| 403 | ahead n |
| 404 | for i ulong n |
| 405 | aput get tp add mul k 256 i |
| 406 | end |
| 407 | end |
| 408 | fn redir s int d int to void |
| 409 | if ne s d |
| 410 | if ne dupfd s d 0 long d |
| 411 | exit 127 |
| 412 | end |
| 413 | end |
| 414 | end |
| 415 | fn reap pid int to ulong |
| 416 | t0 = monons |
| 417 | while true |
| 418 | r = waitpid pid stb 0 len stb 1 |
| 419 | if eq r long pid |
| 420 | if ne get stb 0 0 |
| 421 | ret 256 |
| 422 | end |
| 423 | ret ulong get stb 1 |
| 424 | end |
| 425 | if lt r 0 |
| 426 | ret 256 |
| 427 | end |
| 428 | now = monons |
| 429 | if gt sub now t0 120000000000 |
| 430 | r = killpid pid 9 |
| 431 | r = waitpid pid stb 0 len stb 0 |
| 432 | ret 256 |
| 433 | end |
| 434 | r = sleepns 1000000 |
| 435 | end |
| 436 | ret 256 |
| 437 | end |
| 438 | fn spawn fi int fo int fe int to ulong |
| 439 | put av 0 uchar and get ap 1 255 |
| 440 | put av 1 uchar shr get ap 1 8 |
| 441 | pid = fork |
| 442 | if lt pid 0 |
| 443 | fclo fi |
| 444 | fclo fo |
| 445 | fclo fe |
| 446 | ret 256 |
| 447 | end |
| 448 | if eq pid 0 |
| 449 | redir fi 0 |
| 450 | redir fo 1 |
| 451 | redir fe 2 |
| 452 | r = execprog av 0 get ap 0 |
| 453 | exit 127 |
| 454 | end |
| 455 | fclo fi |
| 456 | fclo fo |
| 457 | fclo fe |
| 458 | ret reap int pid |
| 459 | end |
| 460 | fn nullin to int |
| 461 | pclear |
| 462 | pword 27 |
| 463 | ret ropen |
| 464 | end |
| 465 | note ---- SHA-256 (FIPS 180-4), copied from seed/qualification/om2/gate.om --------------------------- |
| 466 | fn rotr x uint n uint to uint |
| 467 | ret or shr x n shl x sub 32 n |
| 468 | end |
| 469 | fn shasched to void |
| 470 | for i ulong 16 |
| 471 | b = mul i 4 |
| 472 | v = shl uint get blk b 24 |
| 473 | v = or v shl uint get blk add b 1 16 |
| 474 | v = or v shl uint get blk add b 2 8 |
| 475 | v = or v uint get blk add b 3 |
| 476 | put ws i v |
| 477 | end |
| 478 | for j ulong 48 |
| 479 | q = add j 16 |
| 480 | x = get ws sub q 15 |
| 481 | y = get ws sub q 2 |
| 482 | s0 = xor xor rotr x 7 rotr x 18 shr x 3 |
| 483 | s1 = xor xor rotr y 17 rotr y 19 shr y 10 |
| 484 | put ws q add add add get ws sub q 16 s0 get ws sub q 7 s1 |
| 485 | end |
| 486 | end |
| 487 | fn shat1 i ulong to uint |
| 488 | e = get st 4 |
| 489 | s1 = xor xor rotr e 6 rotr e 11 rotr e 25 |
| 490 | ch = xor and e get st 5 and not e get st 6 |
| 491 | ret add add add add get st 7 s1 ch get kk i get ws i |
| 492 | end |
| 493 | fn shat2 to uint |
| 494 | a = get st 0 |
| 495 | b = get st 1 |
| 496 | c = get st 2 |
| 497 | s0 = xor xor rotr a 2 rotr a 13 rotr a 22 |
| 498 | mj = xor xor and a b and a c and b c |
| 499 | ret add s0 mj |
| 500 | end |
| 501 | fn shacomp to void |
| 502 | shasched |
| 503 | for i ulong 8 |
| 504 | put st i get hv i |
| 505 | end |
| 506 | for i ulong 64 |
| 507 | t1 = shat1 i |
| 508 | t2 = shat2 |
| 509 | put st 7 get st 6 |
| 510 | put st 6 get st 5 |
| 511 | put st 5 get st 4 |
| 512 | put st 4 add get st 3 t1 |
| 513 | put st 3 get st 2 |
| 514 | put st 2 get st 1 |
| 515 | put st 1 get st 0 |
| 516 | put st 0 add t1 t2 |
| 517 | end |
| 518 | for i ulong 8 |
| 519 | put hv i add get hv i get st i |
| 520 | end |
| 521 | end |
| 522 | fn shabyte b uchar to void |
| 523 | n = get bk 0 |
| 524 | put blk n b |
| 525 | n = add n 1 |
| 526 | if eq n 64 |
| 527 | shacomp |
| 528 | n = ulong 0 |
| 529 | end |
| 530 | put bk 0 n |
| 531 | put bk 1 add get bk 1 1 |
| 532 | end |
| 533 | fn hexch v uint to uchar |
| 534 | if lt v 10 |
| 535 | ret uchar add v 48 |
| 536 | end |
| 537 | ret uchar add v 87 |
| 538 | end |
| 539 | fn shafinal to void |
| 540 | bits = mul get bk 1 8 |
| 541 | shabyte 128 |
| 542 | while ne get bk 0 56 bound 64 |
| 543 | shabyte 0 |
| 544 | end |
| 545 | for i ulong 8 |
| 546 | shabyte uchar and shr bits mul sub 7 i 8 255 |
| 547 | end |
| 548 | for i ulong 8 |
| 549 | v = get hv i |
| 550 | for j ulong 8 |
| 551 | put hexd add mul i 8 j hexch and shr v mul sub 7 j 4 15 |
| 552 | end |
| 553 | end |
| 554 | end |
| 555 | fn hashfile to bool |
| 556 | fd = ropen |
| 557 | if lt fd 0 |
| 558 | ret false |
| 559 | end |
| 560 | for i ulong 8 |
| 561 | put hv i get ivs i |
| 562 | end |
| 563 | put bk 0 0 |
| 564 | put bk 1 0 |
| 565 | while true |
| 566 | r = read fd buf 0 len buf |
| 567 | if lt r 0 |
| 568 | fclo fd |
| 569 | ret false |
| 570 | end |
| 571 | if eq r 0 |
| 572 | fclo fd |
| 573 | shafinal |
| 574 | ret true |
| 575 | end |
| 576 | for i ulong ulong r |
| 577 | shabyte get buf i |
| 578 | end |
| 579 | end |
| 580 | ret false |
| 581 | end |
| 582 | fn parsenum n ulong want ulong to bool |
| 583 | m = ulong not uint 0 |
| 584 | k = ulong 0 |
| 585 | v = ulong 0 |
| 586 | nd = ulong 0 |
| 587 | for i ulong n |
| 588 | c = get buf i |
| 589 | if and ge c 48 le c 57 |
| 590 | if ge nd 10 |
| 591 | ret false |
| 592 | end |
| 593 | v = add mul v 10 ulong sub c 48 |
| 594 | nd = add nd 1 |
| 595 | else |
| 596 | if or ne c 10 eq nd 0 |
| 597 | ret false |
| 598 | end |
| 599 | if ge k want |
| 600 | ret false |
| 601 | end |
| 602 | if gt v m |
| 603 | ret false |
| 604 | end |
| 605 | put nums k v |
| 606 | k = add k 1 |
| 607 | v = ulong 0 |
| 608 | nd = ulong 0 |
| 609 | end |
| 610 | end |
| 611 | ret and eq nd 0 eq k want |
| 612 | end |
| 613 | fn loadnums id ulong want ulong to bool |
| 614 | pclear |
| 615 | pword id |
| 616 | fd = ropen |
| 617 | if lt fd 0 |
| 618 | ret false |
| 619 | end |
| 620 | r = read fd buf 0 len buf |
| 621 | fclo fd |
| 622 | if or le r 0 ge r long len buf |
| 623 | ret false |
| 624 | end |
| 625 | ret parsenum ulong r want |
| 626 | end |
| 627 | fn consts to bool |
| 628 | if not loadnums 25 64 |
| 629 | ret false |
| 630 | end |
| 631 | for i ulong 64 |
| 632 | put kk i uint get nums i |
| 633 | end |
| 634 | if not loadnums 26 8 |
| 635 | ret false |
| 636 | end |
| 637 | for i ulong 8 |
| 638 | put ivs i uint get nums i |
| 639 | end |
| 640 | ret true |
| 641 | end |
| 642 | note ---- spec tokens -------------------------------------------------------------------------------- |
| 643 | fn tend i ulong to void |
| 644 | k = get ntk 0 |
| 645 | put tkl k sub i get tko k |
| 646 | if lt k 47 |
| 647 | put ntk 0 add k 1 |
| 648 | end |
| 649 | end |
| 650 | fn toks s ulong e ulong to void |
| 651 | put ntk 0 0 |
| 652 | w = false |
| 653 | for j ulong sub e s |
| 654 | i = add s j |
| 655 | c = get spc i |
| 656 | if eq c 35 |
| 657 | if w |
| 658 | tend i |
| 659 | end |
| 660 | ret |
| 661 | end |
| 662 | if isbl c |
| 663 | if w |
| 664 | tend i |
| 665 | w = false |
| 666 | end |
| 667 | else |
| 668 | if not w |
| 669 | put tko get ntk 0 i |
| 670 | w = true |
| 671 | end |
| 672 | end |
| 673 | end |
| 674 | if w |
| 675 | tend e |
| 676 | end |
| 677 | end |
| 678 | fn tokis t ulong id ulong to bool |
| 679 | wlook id |
| 680 | n = get wv 1 |
| 681 | if ne get tkl t n |
| 682 | ret false |
| 683 | end |
| 684 | o = get tko t |
| 685 | w = get wv 0 |
| 686 | for i ulong n |
| 687 | if ne get spc add o i get wd add w i |
| 688 | ret false |
| 689 | end |
| 690 | end |
| 691 | ret true |
| 692 | end |
| 693 | fn tfind t ulong base ulong n ulong to ulong |
| 694 | for k ulong n |
| 695 | if tokis t add base k |
| 696 | ret k |
| 697 | end |
| 698 | end |
| 699 | ret n |
| 700 | end |
| 701 | note ---- canonical encoder input: table (tsub) + listing (lsub, comments and blank lines removed) ---- |
| 702 | fn tokend i ulong lz ulong to ulong |
| 703 | j = i |
| 704 | while and lt j lz not isbl get fa j bound 999999 |
| 705 | j = add j 1 |
| 706 | end |
| 707 | ret j |
| 708 | end |
| 709 | fn skipbl i ulong lz ulong to ulong |
| 710 | j = i |
| 711 | while and lt j lz isbl get fa j bound 999999 |
| 712 | j = add j 1 |
| 713 | end |
| 714 | ret j |
| 715 | end |
| 716 | fn eqspan a ulong n ulong so ulong sl ulong to bool |
| 717 | if ne n sl |
| 718 | ret false |
| 719 | end |
| 720 | for i ulong n |
| 721 | if ne get fa add a i get spc add so i |
| 722 | ret false |
| 723 | end |
| 724 | end |
| 725 | ret true |
| 726 | end |
| 727 | fn pnew to void |
| 728 | o = get md 15 |
| 729 | for i ulong get md 16 |
| 730 | cbyte get spc add o i |
| 731 | end |
| 732 | end |
| 733 | fn cpline ls ulong lz ulong sb bool to ulong |
| 734 | h = ulong 0 |
| 735 | i = ls |
| 736 | while lt i lz bound 999999 |
| 737 | c = get fa i |
| 738 | if isbl c |
| 739 | cbyte c |
| 740 | i = add i 1 |
| 741 | else |
| 742 | te = tokend i lz |
| 743 | if and sb eqspan i sub te i get md 13 get md 14 |
| 744 | pnew |
| 745 | h = add h 1 |
| 746 | else |
| 747 | for j ulong sub te i |
| 748 | cbyte get fa add i j |
| 749 | end |
| 750 | end |
| 751 | i = te |
| 752 | end |
| 753 | end |
| 754 | ret h |
| 755 | end |
| 756 | fn sectok ls ulong lz ulong to bool |
| 757 | a = skipbl ls lz |
| 758 | b = tokend a lz |
| 759 | c = skipbl b lz |
| 760 | d = tokend c lz |
| 761 | ret eqspan c sub d c get md 0 get md 1 |
| 762 | end |
| 763 | fn tline ls ulong lz ulong to ulong |
| 764 | sb = false |
| 765 | if eq get md 11 1 |
| 766 | sb = sectok ls lz |
| 767 | end |
| 768 | ret cpline ls lz sb |
| 769 | end |
| 770 | fn ctable n ulong to ulong |
| 771 | put md 13 get md 2 |
| 772 | put md 14 get md 3 |
| 773 | put md 15 get md 4 |
| 774 | put md 16 get md 5 |
| 775 | h = ulong 0 |
| 776 | s = ulong 0 |
| 777 | for i ulong n |
| 778 | if eq get fa i 10 |
| 779 | h = add h tline s i |
| 780 | cbyte 10 |
| 781 | s = add i 1 |
| 782 | end |
| 783 | end |
| 784 | if lt s n |
| 785 | h = add h tline s n |
| 786 | cbyte 10 |
| 787 | end |
| 788 | ret h |
| 789 | end |
| 790 | fn isint a ulong lz ulong to bool |
| 791 | if ge add a 1 lz |
| 792 | ret false |
| 793 | end |
| 794 | ret and eq get fa a 59 eq get fa add a 1 61 |
| 795 | end |
| 796 | fn intent a ulong lz ulong to void |
| 797 | if ne get md 10 1 |
| 798 | b = add a 2 |
| 799 | for j ulong sub lz b |
| 800 | ibyte get fa add b j |
| 801 | end |
| 802 | ibyte 10 |
| 803 | end |
| 804 | end |
| 805 | fn bkbl j ulong a ulong to bool |
| 806 | if le j a |
| 807 | ret false |
| 808 | end |
| 809 | ret isbl get fa sub j 1 |
| 810 | end |
| 811 | fn cutsc a ulong lz ulong to ulong |
| 812 | j = a |
| 813 | while and lt j lz ne get fa j 59 bound 999999 |
| 814 | j = add j 1 |
| 815 | end |
| 816 | while bkbl j a bound 999999 |
| 817 | j = sub j 1 |
| 818 | end |
| 819 | ret j |
| 820 | end |
| 821 | fn lline ls ulong lz ulong to ulong |
| 822 | a = skipbl ls lz |
| 823 | if isint a lz |
| 824 | intent a lz |
| 825 | ret 0 |
| 826 | end |
| 827 | e = cutsc a lz |
| 828 | if eq e a |
| 829 | ret 0 |
| 830 | end |
| 831 | h = cpline ls e eq get md 12 1 |
| 832 | cbyte 10 |
| 833 | ret h |
| 834 | end |
| 835 | fn clist n ulong to ulong |
| 836 | put md 13 get md 6 |
| 837 | put md 14 get md 7 |
| 838 | put md 15 get md 8 |
| 839 | put md 16 get md 9 |
| 840 | h = ulong 0 |
| 841 | s = ulong 0 |
| 842 | for i ulong n |
| 843 | if eq get fa i 10 |
| 844 | h = add h lline s i |
| 845 | s = add i 1 |
| 846 | end |
| 847 | end |
| 848 | if lt s n |
| 849 | h = add h lline s n |
| 850 | end |
| 851 | ret h |
| 852 | end |
| 853 | fn canon to bool |
| 854 | put cn 0 0 |
| 855 | put inn 0 0 |
| 856 | pclear |
| 857 | ptok 3 |
| 858 | n = rda |
| 859 | if le n 0 |
| 860 | ret false |
| 861 | end |
| 862 | h = ctable ulong n |
| 863 | if and eq get md 11 1 ne h 1 |
| 864 | ret false |
| 865 | end |
| 866 | pclear |
| 867 | ptok 4 |
| 868 | n = rda |
| 869 | if le n 0 |
| 870 | ret false |
| 871 | end |
| 872 | h = clist ulong n |
| 873 | if and eq get md 12 1 ne h 1 |
| 874 | ret false |
| 875 | end |
| 876 | pwork 12 |
| 877 | if not wfc |
| 878 | ret false |
| 879 | end |
| 880 | pwork 13 |
| 881 | ret wfi |
| 882 | end |
| 883 | note ---- instruction-text normalization (nvdisasm / cuobjdump / intent lines) into nx ----------------- |
| 884 | fn ishex c uchar to bool |
| 885 | ret or and ge c 48 le c 57 and ge c 97 le c 102 |
| 886 | end |
| 887 | fn trl e ulong a ulong to bool |
| 888 | if le e a |
| 889 | ret false |
| 890 | end |
| 891 | c = get fa sub e 1 |
| 892 | ret or isbl c eq c 59 |
| 893 | end |
| 894 | fn nemit a ulong b ulong to void |
| 895 | e = b |
| 896 | while trl e a bound 999999 |
| 897 | e = sub e 1 |
| 898 | end |
| 899 | p = false |
| 900 | y = false |
| 901 | for j ulong sub e a |
| 902 | c = get fa add a j |
| 903 | if isbl c |
| 904 | p = y |
| 905 | else |
| 906 | if p |
| 907 | nbyte 32 |
| 908 | p = false |
| 909 | end |
| 910 | nbyte c |
| 911 | y = true |
| 912 | end |
| 913 | end |
| 914 | if y |
| 915 | nbyte 10 |
| 916 | end |
| 917 | end |
| 918 | fn opener ls ulong lz ulong to ulong |
| 919 | for j ulong sub lz ls |
| 920 | i = add ls j |
| 921 | if lt add i 2 lz |
| 922 | o = and eq get fa i 47 eq get fa add i 1 42 |
| 923 | if and o ishex get fa add i 2 |
| 924 | ret i |
| 925 | end |
| 926 | end |
| 927 | end |
| 928 | ret lz |
| 929 | end |
| 930 | fn closer a ulong lz ulong to ulong |
| 931 | for j ulong sub lz a |
| 932 | i = add a j |
| 933 | if lt add i 1 lz |
| 934 | if and eq get fa i 42 eq get fa add i 1 47 |
| 935 | ret add i 2 |
| 936 | end |
| 937 | end |
| 938 | end |
| 939 | ret lz |
| 940 | end |
| 941 | fn nextcm a ulong lz ulong to ulong |
| 942 | for j ulong sub lz a |
| 943 | i = add a j |
| 944 | if lt add i 1 lz |
| 945 | if and eq get fa i 47 eq get fa add i 1 42 |
| 946 | ret i |
| 947 | end |
| 948 | end |
| 949 | end |
| 950 | ret lz |
| 951 | end |
| 952 | fn nline ls ulong lz ulong dm bool to void |
| 953 | if not dm |
| 954 | nemit skipbl ls lz lz |
| 955 | ret |
| 956 | end |
| 957 | p = opener ls lz |
| 958 | if eq p lz |
| 959 | ret |
| 960 | end |
| 961 | a = closer p lz |
| 962 | e = nextcm a lz |
| 963 | nemit skipbl a e e |
| 964 | end |
| 965 | fn normz n ulong dm bool to void |
| 966 | s = ulong 0 |
| 967 | for i ulong n |
| 968 | if eq get fa i 10 |
| 969 | nline s i dm |
| 970 | s = add i 1 |
| 971 | end |
| 972 | end |
| 973 | if lt s n |
| 974 | nline s n dm |
| 975 | end |
| 976 | end |
| 977 | note dis = nx[0,m), intent = nx[m,nn): intent must be a nonempty prefix of dis, the rest only NOP lines |
| 978 | fn isnop o ulong to bool |
| 979 | if ne get nx o 78 |
| 980 | ret false |
| 981 | end |
| 982 | if ne get nx add o 1 79 |
| 983 | ret false |
| 984 | end |
| 985 | if ne get nx add o 2 80 |
| 986 | ret false |
| 987 | end |
| 988 | ret eq get nx add o 3 10 |
| 989 | end |
| 990 | fn nopsonly a ulong b ulong to bool |
| 991 | if ne rem sub b a 4 0 |
| 992 | ret false |
| 993 | end |
| 994 | for k ulong div sub b a 4 |
| 995 | o = add a mul k 4 |
| 996 | if not isnop o |
| 997 | ret false |
| 998 | end |
| 999 | end |
| 1000 | ret true |
| 1001 | end |
| 1002 | fn intok m ulong to bool |
| 1003 | il = sub get nn 0 m |
| 1004 | if or eq il 0 gt il m |
| 1005 | ret false |
| 1006 | end |
| 1007 | for i ulong il |
| 1008 | if ne get nx i get nx add m i |
| 1009 | ret false |
| 1010 | end |
| 1011 | end |
| 1012 | ret nopsonly il m |
| 1013 | end |
| 1014 | fn sameh m ulong to bool |
| 1015 | if or eq m 0 ne sub get nn 0 m m |
| 1016 | ret false |
| 1017 | end |
| 1018 | for i ulong m |
| 1019 | if ne get nx i get nx add m i |
| 1020 | ret false |
| 1021 | end |
| 1022 | end |
| 1023 | ret true |
| 1024 | end |
| 1025 | note ---- stage cache ---------------------------------------------------------------------------------- |
| 1026 | fn keybeg k ulong to void |
| 1027 | put on 0 0 |
| 1028 | oword 34 |
| 1029 | oword 90 |
| 1030 | oword add 28 k |
| 1031 | onl |
| 1032 | end |
| 1033 | fn mkkey k ulong to void |
| 1034 | pclear |
| 1035 | pstate |
| 1036 | pword 2 |
| 1037 | pword 17 |
| 1038 | if not wob |
| 1039 | exit 92 |
| 1040 | end |
| 1041 | if not hashfile |
| 1042 | exit 92 |
| 1043 | end |
| 1044 | for i ulong 64 |
| 1045 | put sk add mul k 64 i get hexd i |
| 1046 | end |
| 1047 | end |
| 1048 | fn cached k ulong to bool |
| 1049 | pcache k 11 |
| 1050 | fd = ropen |
| 1051 | if lt fd 0 |
| 1052 | ret false |
| 1053 | end |
| 1054 | r = read fd dig 0 1 |
| 1055 | fclo fd |
| 1056 | if ne r 1 |
| 1057 | ret false |
| 1058 | end |
| 1059 | put ss k ulong sub get dig 0 48 |
| 1060 | put sh k 1 |
| 1061 | ret true |
| 1062 | end |
| 1063 | fn stash k ulong s ulong to ulong |
| 1064 | put ss k s |
| 1065 | put on 0 0 |
| 1066 | obyte uchar add 48 s |
| 1067 | pcache k 11 |
| 1068 | if not wob |
| 1069 | exit 91 |
| 1070 | end |
| 1071 | ret s |
| 1072 | end |
| 1073 | note ---- stages --------------------------------------------------------------------------------------- |
| 1074 | fn senc to ulong |
| 1075 | pwork 12 |
| 1076 | if not hashfile |
| 1077 | ret stash 0 1 |
| 1078 | end |
| 1079 | keybeg 0 |
| 1080 | otool 0 |
| 1081 | onl |
| 1082 | ohexd |
| 1083 | onl |
| 1084 | mkkey 0 |
| 1085 | if cached 0 |
| 1086 | ret get ss 0 |
| 1087 | end |
| 1088 | aclear |
| 1089 | atool 0 |
| 1090 | pwork 12 |
| 1091 | fi = ropen |
| 1092 | pcache 0 6 |
| 1093 | fo = wopen |
| 1094 | pcache 0 14 |
| 1095 | fe = wopen |
| 1096 | rc = spawn fi fo fe |
| 1097 | s = ulong 1 |
| 1098 | if eq rc 0 |
| 1099 | pcache 0 6 |
| 1100 | n = rda |
| 1101 | if and gt n 0 eq rem n 16 0 |
| 1102 | s = ulong 3 |
| 1103 | end |
| 1104 | end |
| 1105 | ret stash 0 s |
| 1106 | end |
| 1107 | fn refeq to ulong |
| 1108 | pcache 0 6 |
| 1109 | n = rda |
| 1110 | pclear |
| 1111 | ptok 5 |
| 1112 | m = rdc |
| 1113 | if or le n 0 ne n m |
| 1114 | ret 1 |
| 1115 | end |
| 1116 | for i ulong ulong n |
| 1117 | if ne get fa i get fc i |
| 1118 | ret 1 |
| 1119 | end |
| 1120 | end |
| 1121 | ret 3 |
| 1122 | end |
| 1123 | fn intchk to ulong |
| 1124 | put nn 0 0 |
| 1125 | pcache 1 7 |
| 1126 | n = rda |
| 1127 | if le n 0 |
| 1128 | ret 1 |
| 1129 | end |
| 1130 | normz ulong n true |
| 1131 | m = get nn 0 |
| 1132 | pwork 13 |
| 1133 | n = rda |
| 1134 | if lt n 0 |
| 1135 | ret 1 |
| 1136 | end |
| 1137 | normz ulong n false |
| 1138 | if intok m |
| 1139 | ret 3 |
| 1140 | end |
| 1141 | ret 1 |
| 1142 | end |
| 1143 | fn verkey to bool |
| 1144 | pcache 0 6 |
| 1145 | if not hashfile |
| 1146 | exit 90 |
| 1147 | end |
| 1148 | for i ulong 64 |
| 1149 | put hb i get hexd i |
| 1150 | end |
| 1151 | keybeg 1 |
| 1152 | otool 1 |
| 1153 | onl |
| 1154 | ohb |
| 1155 | onl |
| 1156 | otok 2 |
| 1157 | onl |
| 1158 | r = not tokis 5 54 |
| 1159 | if r |
| 1160 | pclear |
| 1161 | ptok 5 |
| 1162 | if not hashfile |
| 1163 | ret false |
| 1164 | end |
| 1165 | ohexd |
| 1166 | else |
| 1167 | oword 54 |
| 1168 | end |
| 1169 | onl |
| 1170 | if gt get inn 0 0 |
| 1171 | pwork 13 |
| 1172 | if not hashfile |
| 1173 | exit 90 |
| 1174 | end |
| 1175 | ohexd |
| 1176 | else |
| 1177 | oword 54 |
| 1178 | end |
| 1179 | onl |
| 1180 | mkkey 1 |
| 1181 | ret true |
| 1182 | end |
| 1183 | fn sver to ulong |
| 1184 | if not verkey |
| 1185 | put ss 1 1 |
| 1186 | ret 1 |
| 1187 | end |
| 1188 | if cached 1 |
| 1189 | ret get ss 1 |
| 1190 | end |
| 1191 | aclear |
| 1192 | atool 1 |
| 1193 | aword 19 |
| 1194 | pclear |
| 1195 | pword 18 |
| 1196 | ptok 2 |
| 1197 | apb |
| 1198 | pcache 0 6 |
| 1199 | apb |
| 1200 | fi = nullin |
| 1201 | pcache 1 7 |
| 1202 | fo = wopen |
| 1203 | pcache 1 14 |
| 1204 | fe = wopen |
| 1205 | rc = spawn fi fo fe |
| 1206 | s = ulong 1 |
| 1207 | if eq rc 0 |
| 1208 | if not tokis 5 54 |
| 1209 | s = refeq |
| 1210 | else |
| 1211 | if gt get inn 0 0 |
| 1212 | s = intchk |
| 1213 | else |
| 1214 | s = ulong 2 |
| 1215 | end |
| 1216 | end |
| 1217 | end |
| 1218 | ret stash 1 s |
| 1219 | end |
| 1220 | fn cmpdis to ulong |
| 1221 | put nn 0 0 |
| 1222 | pcache 1 7 |
| 1223 | n = rda |
| 1224 | if le n 0 |
| 1225 | ret 1 |
| 1226 | end |
| 1227 | normz ulong n true |
| 1228 | m = get nn 0 |
| 1229 | pcache 2 9 |
| 1230 | n = rda |
| 1231 | if le n 0 |
| 1232 | ret 1 |
| 1233 | end |
| 1234 | normz ulong n true |
| 1235 | if sameh m |
| 1236 | ret 3 |
| 1237 | end |
| 1238 | ret 1 |
| 1239 | end |
| 1240 | fn pkgkey to void |
| 1241 | pcache 1 7 |
| 1242 | if not hashfile |
| 1243 | exit 90 |
| 1244 | end |
| 1245 | for i ulong 64 |
| 1246 | put hd i get hexd i |
| 1247 | end |
| 1248 | keybeg 2 |
| 1249 | otool 4 |
| 1250 | onl |
| 1251 | otool 2 |
| 1252 | onl |
| 1253 | ohb |
| 1254 | onl |
| 1255 | ohd |
| 1256 | onl |
| 1257 | for t ulong sub get ntk 0 1 |
| 1258 | u = add t 1 |
| 1259 | if or lt u 3 gt u 6 |
| 1260 | otok u |
| 1261 | obyte 32 |
| 1262 | end |
| 1263 | end |
| 1264 | onl |
| 1265 | mkkey 2 |
| 1266 | end |
| 1267 | fn sdump to ulong |
| 1268 | aclear |
| 1269 | atool 2 |
| 1270 | aword 20 |
| 1271 | pcache 2 8 |
| 1272 | apb |
| 1273 | fi = nullin |
| 1274 | pcache 2 9 |
| 1275 | fo = wopen |
| 1276 | pcache 2 85 |
| 1277 | fe = wopen |
| 1278 | rc = spawn fi fo fe |
| 1279 | if ne rc 0 |
| 1280 | ret 1 |
| 1281 | end |
| 1282 | ret cmpdis |
| 1283 | end |
| 1284 | fn spkg to ulong |
| 1285 | pkgkey |
| 1286 | if cached 2 |
| 1287 | ret get ss 2 |
| 1288 | end |
| 1289 | aclear |
| 1290 | atool 4 |
| 1291 | atok 2 |
| 1292 | atok 1 |
| 1293 | pcache 0 6 |
| 1294 | apb |
| 1295 | pcache 2 8 |
| 1296 | apb |
| 1297 | atok 7 |
| 1298 | aword 22 |
| 1299 | for t ulong sub get ntk 0 8 |
| 1300 | atok add t 8 |
| 1301 | end |
| 1302 | fi = nullin |
| 1303 | pcache 2 24 |
| 1304 | fo = wopen |
| 1305 | pcache 2 14 |
| 1306 | fe = wopen |
| 1307 | rc = spawn fi fo fe |
| 1308 | s = ulong 1 |
| 1309 | if eq rc 0 |
| 1310 | s = sdump |
| 1311 | end |
| 1312 | ret stash 2 s |
| 1313 | end |
| 1314 | fn emumap rc ulong to ulong |
| 1315 | if eq rc 0 |
| 1316 | ret 3 |
| 1317 | end |
| 1318 | if eq rc 2 |
| 1319 | ret 2 |
| 1320 | end |
| 1321 | ret 1 |
| 1322 | end |
| 1323 | fn semu to ulong |
| 1324 | keybeg 3 |
| 1325 | otool 3 |
| 1326 | onl |
| 1327 | ohb |
| 1328 | onl |
| 1329 | otok 2 |
| 1330 | onl |
| 1331 | otok 6 |
| 1332 | onl |
| 1333 | oword 21 |
| 1334 | onl |
| 1335 | mkkey 3 |
| 1336 | if cached 3 |
| 1337 | ret get ss 3 |
| 1338 | end |
| 1339 | if tokis 6 54 |
| 1340 | ret stash 3 2 |
| 1341 | end |
| 1342 | aclear |
| 1343 | atool 3 |
| 1344 | atok 2 |
| 1345 | pcache 0 6 |
| 1346 | apb |
| 1347 | atok 6 |
| 1348 | aword 21 |
| 1349 | fi = nullin |
| 1350 | pcache 3 10 |
| 1351 | fo = wopen |
| 1352 | pcache 3 14 |
| 1353 | fe = wopen |
| 1354 | rc = spawn fi fo fe |
| 1355 | ret stash 3 emumap rc |
| 1356 | end |
| 1357 | note ---- queue files, receipt, report ----------------------------------------------------------------- |
| 1358 | fn qline id ulong t ulong to void |
| 1359 | oword id |
| 1360 | otok t |
| 1361 | onl |
| 1362 | end |
| 1363 | fn queue k ulong to void |
| 1364 | put on 0 0 |
| 1365 | qline 61 1 |
| 1366 | qline 62 2 |
| 1367 | oword 63 |
| 1368 | pcache 2 8 |
| 1369 | opb |
| 1370 | onl |
| 1371 | if not hashfile |
| 1372 | exit 90 |
| 1373 | end |
| 1374 | oword 64 |
| 1375 | ohexd |
| 1376 | onl |
| 1377 | qline 65 6 |
| 1378 | oword 66 |
| 1379 | oword 21 |
| 1380 | onl |
| 1381 | qline 69 7 |
| 1382 | oword 68 |
| 1383 | for t ulong sub get ntk 0 8 |
| 1384 | otok add t 8 |
| 1385 | obyte 32 |
| 1386 | end |
| 1387 | onl |
| 1388 | oword add 73 sub k 4 |
| 1389 | onl |
| 1390 | oword 67 |
| 1391 | onl |
| 1392 | pclear |
| 1393 | pstate |
| 1394 | pword k |
| 1395 | ptok 1 |
| 1396 | pword 16 |
| 1397 | if not wob |
| 1398 | exit 89 |
| 1399 | end |
| 1400 | end |
| 1401 | fn hitw k ulong to void |
| 1402 | if ne get sh k 0 |
| 1403 | oword 52 |
| 1404 | else |
| 1405 | oword 53 |
| 1406 | end |
| 1407 | end |
| 1408 | fn overall to ulong |
| 1409 | w = ulong 3 |
| 1410 | for k ulong 4 |
| 1411 | s = get ss k |
| 1412 | if eq s 1 |
| 1413 | ret 1 |
| 1414 | end |
| 1415 | if ne s 3 |
| 1416 | w = ulong 2 |
| 1417 | end |
| 1418 | end |
| 1419 | ret w |
| 1420 | end |
| 1421 | fn rline k ulong to void |
| 1422 | oword add 28 k |
| 1423 | oword 90 |
| 1424 | ostat get ss k |
| 1425 | if and lt k 4 ne get ss k 0 |
| 1426 | oword 59 |
| 1427 | hitw k |
| 1428 | oword 60 |
| 1429 | ohex k |
| 1430 | end |
| 1431 | onl |
| 1432 | end |
| 1433 | fn receipt to void |
| 1434 | put on 0 0 |
| 1435 | oword 34 |
| 1436 | oword 90 |
| 1437 | otok 1 |
| 1438 | onl |
| 1439 | if eq get jn 2 1 |
| 1440 | oword 88 |
| 1441 | onl |
| 1442 | end |
| 1443 | if ne get ss 0 0 |
| 1444 | oword 71 |
| 1445 | ohb |
| 1446 | onl |
| 1447 | end |
| 1448 | for k ulong 6 |
| 1449 | rline k |
| 1450 | end |
| 1451 | oword 34 |
| 1452 | oword 90 |
| 1453 | ostat get jn 3 |
| 1454 | onl |
| 1455 | oword 70 |
| 1456 | onl |
| 1457 | pclear |
| 1458 | pstate |
| 1459 | pword 3 |
| 1460 | ptok 1 |
| 1461 | pword 15 |
| 1462 | if not wob |
| 1463 | exit 89 |
| 1464 | end |
| 1465 | end |
| 1466 | fn show to void |
| 1467 | put on 0 0 |
| 1468 | oword 51 |
| 1469 | otok 1 |
| 1470 | for k ulong 6 |
| 1471 | oword 90 |
| 1472 | oword add 28 k |
| 1473 | oword 89 |
| 1474 | ostat get ss k |
| 1475 | if and lt k 4 ne get ss k 0 |
| 1476 | oword 88 |
| 1477 | hitw k |
| 1478 | end |
| 1479 | end |
| 1480 | oword 90 |
| 1481 | oword 34 |
| 1482 | oword 89 |
| 1483 | ostat get jn 3 |
| 1484 | onl |
| 1485 | sob |
| 1486 | end |
| 1487 | fn dojob to void |
| 1488 | for k ulong 8 |
| 1489 | put ss k 0 |
| 1490 | put sh k 0 |
| 1491 | end |
| 1492 | put jn 2 0 |
| 1493 | for i ulong 64 |
| 1494 | put hb i 45 |
| 1495 | end |
| 1496 | if canon |
| 1497 | s = senc |
| 1498 | if ne s 1 |
| 1499 | s = sver |
| 1500 | if ne s 1 |
| 1501 | s = spkg |
| 1502 | if ne s 1 |
| 1503 | s = semu |
| 1504 | end |
| 1505 | end |
| 1506 | end |
| 1507 | if and eq get ss 2 3 ne get ss 3 1 |
| 1508 | queue 4 |
| 1509 | queue 5 |
| 1510 | end |
| 1511 | else |
| 1512 | put jn 2 1 |
| 1513 | put ss 0 1 |
| 1514 | end |
| 1515 | put jn 3 overall |
| 1516 | receipt |
| 1517 | show |
| 1518 | end |
| 1519 | note ---- spec lines ----------------------------------------------------------------------------------- |
| 1520 | fn dtool to bool |
| 1521 | if ne get ntk 0 3 |
| 1522 | ret false |
| 1523 | end |
| 1524 | k = tfind 1 40 5 |
| 1525 | n = get tkl 2 |
| 1526 | if or eq k 5 gt n 255 |
| 1527 | ret false |
| 1528 | end |
| 1529 | o = get tko 2 |
| 1530 | for i ulong n |
| 1531 | put tp add mul k 256 i get spc add o i |
| 1532 | end |
| 1533 | put tpl k n |
| 1534 | pclear |
| 1535 | ptok 2 |
| 1536 | if not hashfile |
| 1537 | ret false |
| 1538 | end |
| 1539 | for i ulong 64 |
| 1540 | put th add mul k 64 i get hexd i |
| 1541 | end |
| 1542 | ret true |
| 1543 | end |
| 1544 | fn djob to bool |
| 1545 | n = get ntk 0 |
| 1546 | if or lt n 8 gt n 40 |
| 1547 | ret false |
| 1548 | end |
| 1549 | if not or tokis 2 83 tokis 2 84 |
| 1550 | ret false |
| 1551 | end |
| 1552 | for k ulong 5 |
| 1553 | if eq get tpl k 0 |
| 1554 | ret false |
| 1555 | end |
| 1556 | end |
| 1557 | dojob |
| 1558 | for k ulong 20 |
| 1559 | put md k 0 |
| 1560 | end |
| 1561 | put cnt 2 add get cnt 2 1 |
| 1562 | ret true |
| 1563 | end |
| 1564 | fn dtsub to bool |
| 1565 | if ne get ntk 0 4 |
| 1566 | ret false |
| 1567 | end |
| 1568 | for k ulong 3 |
| 1569 | put md mul k 2 get tko add k 1 |
| 1570 | put md add mul k 2 1 get tkl add k 1 |
| 1571 | end |
| 1572 | put md 11 1 |
| 1573 | ret true |
| 1574 | end |
| 1575 | fn dlsub to bool |
| 1576 | if ne get ntk 0 3 |
| 1577 | ret false |
| 1578 | end |
| 1579 | for k ulong 2 |
| 1580 | put md add 6 mul k 2 get tko add k 1 |
| 1581 | put md add 7 mul k 2 get tkl add k 1 |
| 1582 | end |
| 1583 | put md 12 1 |
| 1584 | ret true |
| 1585 | end |
| 1586 | fn dexp to bool |
| 1587 | if or ne get ntk 0 3 eq get cnt 2 0 |
| 1588 | ret false |
| 1589 | end |
| 1590 | k = tfind 1 28 7 |
| 1591 | s = tfind 2 35 5 |
| 1592 | if or eq k 7 eq s 5 |
| 1593 | ret false |
| 1594 | end |
| 1595 | g = get jn 3 |
| 1596 | if lt k 6 |
| 1597 | g = get ss k |
| 1598 | end |
| 1599 | if eq g s |
| 1600 | put cnt 0 add get cnt 0 1 |
| 1601 | ret true |
| 1602 | end |
| 1603 | put cnt 1 add get cnt 1 1 |
| 1604 | put on 0 0 |
| 1605 | oword 56 |
| 1606 | onum get jn 1 |
| 1607 | oword 90 |
| 1608 | otok 1 |
| 1609 | oword 75 |
| 1610 | ostat g |
| 1611 | oword 91 |
| 1612 | otok 2 |
| 1613 | onl |
| 1614 | sob |
| 1615 | ret true |
| 1616 | end |
| 1617 | fn sline s ulong e ulong to bool |
| 1618 | toks s e |
| 1619 | if eq get ntk 0 0 |
| 1620 | ret true |
| 1621 | end |
| 1622 | if tokis 0 45 |
| 1623 | ret dtool |
| 1624 | end |
| 1625 | if tokis 0 46 |
| 1626 | ret djob |
| 1627 | end |
| 1628 | if tokis 0 47 |
| 1629 | ret dtsub |
| 1630 | end |
| 1631 | if tokis 0 48 |
| 1632 | ret dlsub |
| 1633 | end |
| 1634 | if tokis 0 49 |
| 1635 | put md 10 1 |
| 1636 | ret eq get ntk 0 1 |
| 1637 | end |
| 1638 | if tokis 0 50 |
| 1639 | ret dexp |
| 1640 | end |
| 1641 | ret false |
| 1642 | end |
| 1643 | fn spec n ulong to bool |
| 1644 | s = ulong 0 |
| 1645 | put jn 1 1 |
| 1646 | for i ulong n |
| 1647 | if eq get spc i 10 |
| 1648 | if not sline s i |
| 1649 | ret false |
| 1650 | end |
| 1651 | s = add i 1 |
| 1652 | put jn 1 add get jn 1 1 |
| 1653 | end |
| 1654 | end |
| 1655 | if lt s n |
| 1656 | ret sline s n |
| 1657 | end |
| 1658 | ret true |
| 1659 | end |
| 1660 | fn main to int |
| 1661 | if ne argcnt 3 |
| 1662 | say 82 |
| 1663 | ret 2 |
| 1664 | end |
| 1665 | if not consts |
| 1666 | say 86 |
| 1667 | ret 2 |
| 1668 | end |
| 1669 | r = argread 2 sth 0 255 |
| 1670 | if lt r 1 |
| 1671 | say 82 |
| 1672 | ret 2 |
| 1673 | end |
| 1674 | put stl 0 ulong r |
| 1675 | r = argread 1 pb 0 4000 |
| 1676 | if lt r 1 |
| 1677 | say 82 |
| 1678 | ret 2 |
| 1679 | end |
| 1680 | put pn 0 ulong r |
| 1681 | n = rds |
| 1682 | if le n 0 |
| 1683 | say 82 |
| 1684 | ret 2 |
| 1685 | end |
| 1686 | mkd 0 |
| 1687 | mkd 77 |
| 1688 | mkd 78 |
| 1689 | mkd 79 |
| 1690 | mkd 23 |
| 1691 | mkd 80 |
| 1692 | mkd 81 |
| 1693 | if not spec ulong n |
| 1694 | put on 0 0 |
| 1695 | oword 55 |
| 1696 | onum get jn 1 |
| 1697 | onl |
| 1698 | sob |
| 1699 | ret 2 |
| 1700 | end |
| 1701 | put on 0 0 |
| 1702 | oword 57 |
| 1703 | onum get cnt 0 |
| 1704 | oword 58 |
| 1705 | onum get cnt 1 |
| 1706 | oword 76 |
| 1707 | onum get cnt 2 |
| 1708 | onl |
| 1709 | sob |
| 1710 | if or ne get cnt 1 0 eq get cnt 0 0 |
| 1711 | ret 1 |
| 1712 | end |
| 1713 | ret 0 |
| 1714 | end |