aien
aien-dev/aien
Brought by drakestapleton
aien / src / goal_microjobs / kernel.om
| 1 | note SPDX-License-Identifier: AGPL-3.0-or-later |
| 2 | note Allen #13: admission and journal replay for one persistent objective compiled into a |
| 3 | note typed microjob DAG. Input on stdin is the plan (header, nodes) then the append-only |
| 4 | note event journal, all whitespace-separated decimal words. Output on stdout is the |
| 5 | note replayed state, the fundable ready set and, when complete, the objective receipt. |
| 6 | note A refused plan or event prints 199 seq code and exits with code; nothing is admitted. |
| 7 | note Local records and codes remain the replay ABI documented in docs/GOAL_MICROJOBS.md. |
| 8 | note canon.om implements the bounded Aienet-0 MJB1/MJR1 adapter; kernel semantics are unchanged. |
| 9 | note This kernel executes no job, calls no model, and writes no memory or authority state. |
| 10 | global Inb uchar 262144 |
| 11 | global Cur ulong 8 |
| 12 | global Hdr ulong 16 |
| 13 | global Nd ulong 1536 |
| 14 | global Dep ulong 512 |
| 15 | global St ulong 1024 |
| 16 | global Ev ulong 16 |
| 17 | global Tot ulong 8 |
| 18 | global Wk ulong 64 |
| 19 | global Ob uchar 65536 |
| 20 | |
| 21 | note ---- output: decimal words, one record per line ---- |
| 22 | fn putb b ulong to void |
| 23 | p = get Cur 2 |
| 24 | put Ob p uchar b |
| 25 | put Cur 2 add p 1 |
| 26 | end |
| 27 | |
| 28 | fn putd v ulong to void |
| 29 | if gt v 9 |
| 30 | putd div v 10 |
| 31 | end |
| 32 | putb add rem v 10 48 |
| 33 | end |
| 34 | |
| 35 | fn putn v ulong to void |
| 36 | putd v |
| 37 | putb 32 |
| 38 | end |
| 39 | |
| 40 | fn endl to void |
| 41 | put Ob sub get Cur 2 1 uchar 10 |
| 42 | end |
| 43 | |
| 44 | fn flush to void |
| 45 | w = write 1 Ob 0 get Cur 2 |
| 46 | put Cur 2 0 |
| 47 | end |
| 48 | |
| 49 | fn fail code ulong to void |
| 50 | put Cur 2 0 |
| 51 | putn 199 |
| 52 | putn get Cur 4 |
| 53 | putn code |
| 54 | endl |
| 55 | flush |
| 56 | exit int code |
| 57 | end |
| 58 | |
| 59 | note ---- input ---- |
| 60 | fn load to void |
| 61 | cap = sub len Inb 1 |
| 62 | t = ulong 0 |
| 63 | k = read 0 Inb 0 cap |
| 64 | while gt k 0 |
| 65 | t = add t ulong k |
| 66 | k = long 0 |
| 67 | if lt t cap |
| 68 | k = read 0 Inb t sub cap t |
| 69 | end |
| 70 | end |
| 71 | if lt k 0 |
| 72 | fail 4 |
| 73 | end |
| 74 | if ge t cap |
| 75 | fail 3 |
| 76 | end |
| 77 | put Inb t 32 |
| 78 | put Cur 1 t |
| 79 | end |
| 80 | |
| 81 | fn isws c ulong to bool |
| 82 | ret or eq c 32 or eq c 10 or eq c 9 eq c 13 |
| 83 | end |
| 84 | |
| 85 | fn more to bool |
| 86 | p = get Cur 0 |
| 87 | n = get Cur 1 |
| 88 | while lt p n |
| 89 | if eq isws ulong get Inb p false |
| 90 | put Cur 0 p |
| 91 | ret true |
| 92 | end |
| 93 | p = add p 1 |
| 94 | end |
| 95 | put Cur 0 p |
| 96 | ret false |
| 97 | end |
| 98 | |
| 99 | fn rd to ulong |
| 100 | if eq more false |
| 101 | fail 2 |
| 102 | end |
| 103 | p = get Cur 0 |
| 104 | v = ulong 0 |
| 105 | while eq isws ulong get Inb p false |
| 106 | c = ulong get Inb p |
| 107 | if or lt c 48 gt c 57 |
| 108 | fail 3 |
| 109 | end |
| 110 | d = sub c 48 |
| 111 | if or gt v 1844674407370955161 and eq v 1844674407370955161 gt d 5 |
| 112 | fail 3 |
| 113 | end |
| 114 | v = add mul v 10 d |
| 115 | p = add p 1 |
| 116 | end |
| 117 | put Cur 0 p |
| 118 | ret v |
| 119 | end |
| 120 | |
| 121 | note ---- record accessors (node index i is the node id minus one) ---- |
| 122 | fn nd i ulong f ulong to ulong |
| 123 | ret get Nd add mul i 24 f |
| 124 | end |
| 125 | |
| 126 | fn sg i ulong f ulong to ulong |
| 127 | ret get St add mul i 16 f |
| 128 | end |
| 129 | |
| 130 | fn ss i ulong f ulong v ulong to void |
| 131 | put St add mul i 16 f v |
| 132 | end |
| 133 | |
| 134 | fn ev f ulong to ulong |
| 135 | ret get Ev f |
| 136 | end |
| 137 | |
| 138 | fn dep i ulong j ulong to ulong |
| 139 | ret sub get Dep add mul i 8 j 1 |
| 140 | end |
| 141 | |
| 142 | note nonzero 4-word digests: objective (header 1..4), operand (node 16..19), event (6..9) |
| 143 | fn nzhdr to bool |
| 144 | v = ulong 0 |
| 145 | for f ulong 4 |
| 146 | v = or v get Hdr add 1 f |
| 147 | end |
| 148 | ret ne v 0 |
| 149 | end |
| 150 | |
| 151 | fn nzop i ulong to bool |
| 152 | v = ulong 0 |
| 153 | for f ulong 4 |
| 154 | v = or v nd i add 16 f |
| 155 | end |
| 156 | ret ne v 0 |
| 157 | end |
| 158 | |
| 159 | fn evdigz to bool |
| 160 | v = ulong 0 |
| 161 | for f ulong 4 |
| 162 | v = or v ev add 6 f |
| 163 | end |
| 164 | ret eq v 0 |
| 165 | end |
| 166 | |
| 167 | note ---- plan: header and nodes ---- |
| 168 | fn header to void |
| 169 | if ne rd 1 |
| 170 | fail 5 |
| 171 | end |
| 172 | for i ulong 16 |
| 173 | put Hdr i rd |
| 174 | end |
| 175 | if ne get Hdr 0 1 |
| 176 | fail 10 |
| 177 | end |
| 178 | n = get Hdr 8 |
| 179 | if or eq n 0 gt n 64 |
| 180 | fail 11 |
| 181 | end |
| 182 | if eq nzhdr false |
| 183 | fail 25 |
| 184 | end |
| 185 | ow = get Hdr 5 |
| 186 | rt = get Hdr 6 |
| 187 | if or eq ow 0 or eq rt 0 eq ow rt |
| 188 | fail 25 |
| 189 | end |
| 190 | t = get Hdr 9 |
| 191 | if or eq t 0 gt t n |
| 192 | fail 21 |
| 193 | end |
| 194 | if eq get Hdr 10 0 |
| 195 | fail 24 |
| 196 | end |
| 197 | if gt get Hdr 7 2 |
| 198 | fail 13 |
| 199 | end |
| 200 | end |
| 201 | |
| 202 | fn readnode i ulong to void |
| 203 | if ne rd 2 |
| 204 | fail 5 |
| 205 | end |
| 206 | if ne rd add i 1 |
| 207 | fail 12 |
| 208 | end |
| 209 | b = mul i 24 |
| 210 | for f ulong 20 |
| 211 | put Nd add b f rd |
| 212 | end |
| 213 | k = rd |
| 214 | if gt k 8 |
| 215 | fail 19 |
| 216 | end |
| 217 | put Nd add b 20 k |
| 218 | for j ulong k |
| 219 | put Dep add mul i 8 j rd |
| 220 | end |
| 221 | end |
| 222 | |
| 223 | fn depsok i ulong to void |
| 224 | n = get Hdr 8 |
| 225 | k = nd i 20 |
| 226 | for j ulong k |
| 227 | d = get Dep add mul i 8 j |
| 228 | if or eq d 0 or gt d n eq d add i 1 |
| 229 | fail 19 |
| 230 | end |
| 231 | for m ulong j |
| 232 | if eq get Dep add mul i 8 m d |
| 233 | fail 19 |
| 234 | end |
| 235 | end |
| 236 | end |
| 237 | end |
| 238 | |
| 239 | note static node rules in the order of aien-protocols-mv#50 draft section 4.4 (subset) |
| 240 | fn nodeok i ulong to void |
| 241 | kind = nd i 0 |
| 242 | op = nd i 1 |
| 243 | if or eq kind 0 gt kind 2 |
| 244 | fail 13 |
| 245 | end |
| 246 | if or eq op 0 gt op sub 8 mul kind 2 |
| 247 | fail 13 |
| 248 | end |
| 249 | if or gt nd i 4 2 or gt nd i 15 1 gt nd i 3 4 |
| 250 | fail 13 |
| 251 | end |
| 252 | vk = nd i 9 |
| 253 | rc = nd i 11 |
| 254 | ma = nd i 12 |
| 255 | if or eq vk 0 or gt vk 3 eq nd i 10 0 |
| 256 | fail 16 |
| 257 | end |
| 258 | if or eq rc 0 or gt rc 3 or eq ma 0 gt ma 8 |
| 259 | fail 13 |
| 260 | end |
| 261 | if ne nd i 13 get Hdr 5 |
| 262 | fail 17 |
| 263 | end |
| 264 | if gt nd i 4 get Hdr 7 |
| 265 | fail 18 |
| 266 | end |
| 267 | tokok i |
| 268 | if and eq rc 1 gt ma 1 |
| 269 | fail 23 |
| 270 | end |
| 271 | if and eq nd i 4 2 eq rc 2 |
| 272 | fail 23 |
| 273 | end |
| 274 | if eq nd i 14 0 |
| 275 | fail 24 |
| 276 | end |
| 277 | if eq nzop i false |
| 278 | fail 22 |
| 279 | end |
| 280 | depsok i |
| 281 | end |
| 282 | |
| 283 | note token profile: COMPUTE is profile ZERO with every token count zero and no route; |
| 284 | note NEURAL names a route class and caps within its profile; needs above caps refuse. |
| 285 | fn tokok i ulong to void |
| 286 | prof = nd i 3 |
| 287 | it = nd i 5 |
| 288 | ot = nd i 6 |
| 289 | if eq nd i 0 1 |
| 290 | if or ne prof 0 or ne it 0 or ne ot 0 ne nd i 2 0 |
| 291 | fail 14 |
| 292 | end |
| 293 | if or ne nd i 7 0 ne nd i 8 0 |
| 294 | fail 14 |
| 295 | end |
| 296 | ret |
| 297 | end |
| 298 | if or eq prof 0 or eq it 0 eq ot 0 |
| 299 | fail 14 |
| 300 | end |
| 301 | if or eq nd i 2 0 gt nd i 2 3 |
| 302 | fail 14 |
| 303 | end |
| 304 | if or gt it shl ulong 32 prof gt ot shl ulong 8 prof |
| 305 | fail 14 |
| 306 | end |
| 307 | if or gt nd i 7 it gt nd i 8 ot |
| 308 | fail 15 |
| 309 | end |
| 310 | end |
| 311 | |
| 312 | note static budget: sums of node caps within the header budgets (input, output, time) |
| 313 | fn budgok to void |
| 314 | n = get Hdr 8 |
| 315 | a = ulong 0 |
| 316 | b = ulong 0 |
| 317 | c = ulong 0 |
| 318 | for i ulong n |
| 319 | if gt or or nd i 5 nd i 6 nd i 14 4294967295 |
| 320 | fail 26 |
| 321 | end |
| 322 | a = add a nd i 5 |
| 323 | b = add b nd i 6 |
| 324 | c = add c nd i 14 |
| 325 | end |
| 326 | if gt a get Hdr 13 |
| 327 | fail 26 |
| 328 | end |
| 329 | if or gt b get Hdr 14 gt c get Hdr 15 |
| 330 | fail 26 |
| 331 | end |
| 332 | end |
| 333 | |
| 334 | fn depsin i ulong to bool |
| 335 | k = nd i 20 |
| 336 | for j ulong k |
| 337 | if eq get Wk dep i j 0 |
| 338 | ret false |
| 339 | end |
| 340 | end |
| 341 | ret true |
| 342 | end |
| 343 | |
| 344 | fn acyclic to bool |
| 345 | n = get Hdr 8 |
| 346 | for i ulong n |
| 347 | put Wk i 0 |
| 348 | end |
| 349 | for r ulong n |
| 350 | f = ulong 0 |
| 351 | for i ulong n |
| 352 | if and eq f 0 and eq get Wk i 0 depsin i |
| 353 | f = add i 1 |
| 354 | end |
| 355 | end |
| 356 | if eq f 0 |
| 357 | ret false |
| 358 | end |
| 359 | put Wk sub f 1 1 |
| 360 | end |
| 361 | ret true |
| 362 | end |
| 363 | |
| 364 | fn plan to void |
| 365 | header |
| 366 | n = get Hdr 8 |
| 367 | for i ulong n |
| 368 | readnode i |
| 369 | end |
| 370 | for i ulong n |
| 371 | nodeok i |
| 372 | end |
| 373 | if eq acyclic false |
| 374 | fail 20 |
| 375 | end |
| 376 | budgok |
| 377 | if eq nd sub get Hdr 9 1 15 0 |
| 378 | fail 21 |
| 379 | end |
| 380 | for i ulong n |
| 381 | ss i 0 1 |
| 382 | ss i 1 1 |
| 383 | end |
| 384 | end |
| 385 | |
| 386 | note ---- replay: node states 1 pending, 2 running, 3 resulted, 4 done, 5 failed, |
| 387 | note 6 cancelled, 7 refused ---- |
| 388 | fn depsdone i ulong to bool |
| 389 | k = nd i 20 |
| 390 | for j ulong k |
| 391 | if ne sg dep i j 0 4 |
| 392 | ret false |
| 393 | end |
| 394 | end |
| 395 | ret true |
| 396 | end |
| 397 | |
| 398 | fn tokcap i ulong to ulong |
| 399 | ret add nd i 5 nd i 6 |
| 400 | end |
| 401 | |
| 402 | fn ismodel i ulong to bool |
| 403 | ret eq nd i 0 2 |
| 404 | end |
| 405 | |
| 406 | fn fundable i ulong to bool |
| 407 | if ge sg i 2 nd i 12 |
| 408 | ret false |
| 409 | end |
| 410 | if ge get Tot 0 get Hdr 10 |
| 411 | ret false |
| 412 | end |
| 413 | if eq ismodel i true |
| 414 | if ge get Tot 1 get Hdr 11 |
| 415 | ret false |
| 416 | end |
| 417 | if gt add get Tot 2 tokcap i get Hdr 12 |
| 418 | ret false |
| 419 | end |
| 420 | end |
| 421 | ret true |
| 422 | end |
| 423 | |
| 424 | fn same i ulong to void |
| 425 | if ne ev 3 sg i 1 |
| 426 | fail 34 |
| 427 | end |
| 428 | if ne ev 2 sg i 3 |
| 429 | fail 35 |
| 430 | end |
| 431 | end |
| 432 | |
| 433 | fn charge i ulong to void |
| 434 | if gt ev 10 tokcap i |
| 435 | fail 42 |
| 436 | end |
| 437 | if gt ev 11 nd i 14 |
| 438 | fail 42 |
| 439 | end |
| 440 | put Tot 6 add get Tot 6 ev 10 |
| 441 | put Tot 4 add get Tot 4 ev 11 |
| 442 | end |
| 443 | |
| 444 | fn retry i ulong to void |
| 445 | ss i 3 0 |
| 446 | if lt sg i 2 nd i 12 |
| 447 | ss i 0 1 |
| 448 | else |
| 449 | ss i 0 5 |
| 450 | end |
| 451 | end |
| 452 | |
| 453 | fn dispatch i ulong to void |
| 454 | if ne sg i 0 1 |
| 455 | fail 33 |
| 456 | end |
| 457 | if ne ev 3 sg i 1 |
| 458 | fail 34 |
| 459 | end |
| 460 | if eq depsdone i false |
| 461 | fail 43 |
| 462 | end |
| 463 | if ne ev 2 add sg i 2 1 |
| 464 | fail 35 |
| 465 | end |
| 466 | w = ev 4 |
| 467 | if or eq w 0 eq w nd i 10 |
| 468 | fail 39 |
| 469 | end |
| 470 | if or eq w get Hdr 5 eq w get Hdr 6 |
| 471 | fail 39 |
| 472 | end |
| 473 | a = sg i 2 |
| 474 | if ge a nd i 12 |
| 475 | fail 36 |
| 476 | end |
| 477 | if ge get Tot 0 get Hdr 10 |
| 478 | fail 36 |
| 479 | end |
| 480 | if eq ismodel i true |
| 481 | if ge get Tot 1 get Hdr 11 |
| 482 | fail 37 |
| 483 | end |
| 484 | if gt add get Tot 2 tokcap i get Hdr 12 |
| 485 | fail 38 |
| 486 | end |
| 487 | put Tot 1 add get Tot 1 1 |
| 488 | put Tot 2 add get Tot 2 tokcap i |
| 489 | end |
| 490 | ss i 0 2 |
| 491 | ss i 2 ev 2 |
| 492 | ss i 3 ev 2 |
| 493 | ss i 4 ev 4 |
| 494 | put Tot 0 add get Tot 0 1 |
| 495 | end |
| 496 | |
| 497 | fn result i ulong to void |
| 498 | if ne sg i 0 2 |
| 499 | fail 33 |
| 500 | end |
| 501 | same i |
| 502 | if ne ev 4 sg i 4 |
| 503 | fail 39 |
| 504 | end |
| 505 | if eq evdigz true |
| 506 | fail 41 |
| 507 | end |
| 508 | if and eq ismodel i false ne ev 10 0 |
| 509 | fail 48 |
| 510 | end |
| 511 | charge i |
| 512 | for f ulong 4 |
| 513 | ss i add 5 f ev add 6 f |
| 514 | end |
| 515 | ss i 0 3 |
| 516 | end |
| 517 | |
| 518 | fn verify i ulong to void |
| 519 | if ne sg i 0 3 |
| 520 | fail 33 |
| 521 | end |
| 522 | same i |
| 523 | if eq ev 4 sg i 4 |
| 524 | fail 40 |
| 525 | end |
| 526 | if ne ev 4 nd i 10 |
| 527 | fail 39 |
| 528 | end |
| 529 | for f ulong 4 |
| 530 | if ne sg i add 5 f ev add 6 f |
| 531 | fail 41 |
| 532 | end |
| 533 | end |
| 534 | if eq ev 5 1 |
| 535 | ss i 0 4 |
| 536 | else |
| 537 | if ne ev 5 0 |
| 538 | fail 49 |
| 539 | end |
| 540 | retry i |
| 541 | end |
| 542 | end |
| 543 | |
| 544 | fn failev i ulong to void |
| 545 | if ne sg i 0 2 |
| 546 | fail 33 |
| 547 | end |
| 548 | same i |
| 549 | if and ne ev 4 sg i 4 ne ev 4 get Hdr 6 |
| 550 | fail 39 |
| 551 | end |
| 552 | charge i |
| 553 | retry i |
| 554 | end |
| 555 | |
| 556 | fn refuse i ulong to void |
| 557 | s = sg i 0 |
| 558 | if eq s 2 |
| 559 | same i |
| 560 | if ne ev 4 sg i 4 |
| 561 | fail 39 |
| 562 | end |
| 563 | else |
| 564 | if ne s 1 |
| 565 | fail 33 |
| 566 | end |
| 567 | if ne ev 3 sg i 1 |
| 568 | fail 34 |
| 569 | end |
| 570 | if ne ev 4 get Hdr 6 |
| 571 | fail 39 |
| 572 | end |
| 573 | end |
| 574 | ss i 3 0 |
| 575 | ss i 0 7 |
| 576 | end |
| 577 | |
| 578 | note mark: Wk[j] = 1 for node k and every node that transitively depends on it |
| 579 | fn mark k ulong to void |
| 580 | n = get Hdr 8 |
| 581 | for i ulong n |
| 582 | put Wk i 0 |
| 583 | end |
| 584 | put Wk k 1 |
| 585 | for r ulong n |
| 586 | for i ulong n |
| 587 | if eq get Wk i 0 |
| 588 | m = nd i 20 |
| 589 | for j ulong m |
| 590 | if eq get Wk dep i j 1 |
| 591 | put Wk i 1 |
| 592 | end |
| 593 | end |
| 594 | end |
| 595 | end |
| 596 | end |
| 597 | end |
| 598 | |
| 599 | fn cancel i ulong to void |
| 600 | if ne ev 4 get Hdr 5 |
| 601 | fail 39 |
| 602 | end |
| 603 | n = get Hdr 8 |
| 604 | if eq i n |
| 605 | put Tot 5 1 |
| 606 | for j ulong n |
| 607 | if ne sg j 0 4 |
| 608 | ss j 0 6 |
| 609 | ss j 3 0 |
| 610 | end |
| 611 | end |
| 612 | ret |
| 613 | end |
| 614 | s = sg i 0 |
| 615 | if or eq s 4 eq s 6 |
| 616 | fail 33 |
| 617 | end |
| 618 | mark i |
| 619 | for j ulong n |
| 620 | if and eq get Wk j 1 ne sg j 0 4 |
| 621 | ss j 0 6 |
| 622 | ss j 3 0 |
| 623 | end |
| 624 | end |
| 625 | end |
| 626 | |
| 627 | fn correct i ulong to void |
| 628 | if ne ev 4 get Hdr 5 |
| 629 | fail 39 |
| 630 | end |
| 631 | if ne ev 3 sg i 1 |
| 632 | fail 34 |
| 633 | end |
| 634 | if eq evdigz true |
| 635 | fail 41 |
| 636 | end |
| 637 | same4 i |
| 638 | for f ulong 4 |
| 639 | put Nd add mul i 24 add 16 f ev add 6 f |
| 640 | end |
| 641 | mark i |
| 642 | n = get Hdr 8 |
| 643 | for j ulong n |
| 644 | if eq get Wk j 1 |
| 645 | ss j 1 add sg j 1 1 |
| 646 | ss j 2 0 |
| 647 | ss j 3 0 |
| 648 | for f ulong 4 |
| 649 | ss j add 5 f 0 |
| 650 | end |
| 651 | if ne sg j 0 6 |
| 652 | ss j 0 1 |
| 653 | end |
| 654 | end |
| 655 | end |
| 656 | end |
| 657 | |
| 658 | fn same4 i ulong to void |
| 659 | for f ulong 4 |
| 660 | if ne nd i add 16 f ev add 6 f |
| 661 | ret |
| 662 | end |
| 663 | end |
| 664 | fail 46 |
| 665 | end |
| 666 | |
| 667 | fn effect i ulong to void |
| 668 | if ne ev 4 get Hdr 6 |
| 669 | fail 39 |
| 670 | end |
| 671 | if or ne sg i 0 4 ne nd i 4 2 |
| 672 | fail 44 |
| 673 | end |
| 674 | if ne ev 3 sg i 1 |
| 675 | fail 34 |
| 676 | end |
| 677 | if eq sg i 9 sg i 1 |
| 678 | fail 45 |
| 679 | end |
| 680 | if eq evdigz true |
| 681 | fail 41 |
| 682 | end |
| 683 | ss i 9 sg i 1 |
| 684 | end |
| 685 | |
| 686 | fn event to void |
| 687 | for f ulong 12 |
| 688 | put Ev f rd |
| 689 | end |
| 690 | t = ev 0 |
| 691 | k = ev 1 |
| 692 | n = get Hdr 8 |
| 693 | if or eq t 0 gt t 8 |
| 694 | fail 32 |
| 695 | end |
| 696 | if eq t 5 |
| 697 | if gt k n |
| 698 | fail 31 |
| 699 | end |
| 700 | if eq k 0 |
| 701 | if eq get Tot 5 1 |
| 702 | fail 47 |
| 703 | end |
| 704 | cancel n |
| 705 | ret |
| 706 | end |
| 707 | end |
| 708 | if or eq k 0 gt k n |
| 709 | fail 31 |
| 710 | end |
| 711 | if eq get Tot 5 1 |
| 712 | fail 47 |
| 713 | end |
| 714 | i = sub k 1 |
| 715 | if eq t 1 |
| 716 | dispatch i |
| 717 | end |
| 718 | if eq t 2 |
| 719 | result i |
| 720 | end |
| 721 | if eq t 3 |
| 722 | verify i |
| 723 | end |
| 724 | if eq t 4 |
| 725 | failev i |
| 726 | end |
| 727 | if eq t 5 |
| 728 | cancel i |
| 729 | end |
| 730 | if eq t 6 |
| 731 | correct i |
| 732 | end |
| 733 | if eq t 7 |
| 734 | refuse i |
| 735 | end |
| 736 | if eq t 8 |
| 737 | effect i |
| 738 | end |
| 739 | end |
| 740 | |
| 741 | fn replay to void |
| 742 | s = ulong 0 |
| 743 | while eq more true |
| 744 | put Cur 4 add s 1 |
| 745 | if ne rd 3 |
| 746 | fail 5 |
| 747 | end |
| 748 | if ne rd add s 1 |
| 749 | fail 30 |
| 750 | end |
| 751 | event |
| 752 | s = add s 1 |
| 753 | end |
| 754 | put Tot 3 s |
| 755 | put Cur 4 0 |
| 756 | end |
| 757 | |
| 758 | note ---- report ---- |
| 759 | fn blocked to void |
| 760 | n = get Hdr 8 |
| 761 | for i ulong n |
| 762 | s = sg i 0 |
| 763 | put Wk i 0 |
| 764 | if or eq s 5 or eq s 6 eq s 7 |
| 765 | put Wk i 1 |
| 766 | end |
| 767 | end |
| 768 | for r ulong n |
| 769 | for i ulong n |
| 770 | if and eq get Wk i 0 ne sg i 0 4 |
| 771 | m = nd i 20 |
| 772 | for j ulong m |
| 773 | if eq get Wk dep i j 1 |
| 774 | put Wk i 1 |
| 775 | end |
| 776 | end |
| 777 | end |
| 778 | end |
| 779 | end |
| 780 | end |
| 781 | |
| 782 | fn ready i ulong to bool |
| 783 | if eq get Tot 5 1 |
| 784 | ret false |
| 785 | end |
| 786 | if or ne sg i 0 1 eq depsdone i false |
| 787 | ret false |
| 788 | end |
| 789 | ret fundable i |
| 790 | end |
| 791 | |
| 792 | fn status to ulong |
| 793 | if eq get Tot 5 1 |
| 794 | ret 4 |
| 795 | end |
| 796 | n = get Hdr 8 |
| 797 | blocked |
| 798 | ok = true |
| 799 | bad = false |
| 800 | blk = false |
| 801 | live = false |
| 802 | for i ulong n |
| 803 | s = sg i 0 |
| 804 | if eq nd i 15 1 |
| 805 | if ne s 4 |
| 806 | ok = false |
| 807 | end |
| 808 | if and eq nd i 4 2 ne sg i 9 sg i 1 |
| 809 | ok = false |
| 810 | if eq s 4 |
| 811 | live = true |
| 812 | end |
| 813 | end |
| 814 | if eq s 5 |
| 815 | bad = true |
| 816 | end |
| 817 | if eq get Wk i 1 |
| 818 | blk = true |
| 819 | end |
| 820 | end |
| 821 | if or or eq s 2 eq s 3 ready i |
| 822 | live = true |
| 823 | end |
| 824 | end |
| 825 | if ok |
| 826 | ret 2 |
| 827 | end |
| 828 | if bad |
| 829 | ret 3 |
| 830 | end |
| 831 | if blk |
| 832 | ret 5 |
| 833 | end |
| 834 | if eq live false |
| 835 | ret 6 |
| 836 | end |
| 837 | ret 1 |
| 838 | end |
| 839 | |
| 840 | fn report to void |
| 841 | n = get Hdr 8 |
| 842 | st = status |
| 843 | done = ulong 0 |
| 844 | for i ulong n |
| 845 | if eq sg i 0 4 |
| 846 | done = add done 1 |
| 847 | end |
| 848 | end |
| 849 | putn 100 |
| 850 | putn st |
| 851 | putn n |
| 852 | putn done |
| 853 | for f ulong 7 |
| 854 | putn get Tot f |
| 855 | end |
| 856 | endl |
| 857 | blocked |
| 858 | for i ulong n |
| 859 | putn 101 |
| 860 | putn add i 1 |
| 861 | putn sg i 0 |
| 862 | putn sg i 1 |
| 863 | putn sg i 2 |
| 864 | putn get Wk i |
| 865 | if ready i |
| 866 | putn 1 |
| 867 | else |
| 868 | putn 0 |
| 869 | end |
| 870 | putn sg i 9 |
| 871 | endl |
| 872 | end |
| 873 | putn 102 |
| 874 | for i ulong n |
| 875 | if ready i |
| 876 | putn add i 1 |
| 877 | end |
| 878 | end |
| 879 | endl |
| 880 | if eq st 2 |
| 881 | t = sub get Hdr 9 1 |
| 882 | putn 103 |
| 883 | for f ulong 4 |
| 884 | putn get Hdr add 1 f |
| 885 | end |
| 886 | for f ulong 4 |
| 887 | putn sg t add 5 f |
| 888 | end |
| 889 | putn sg t 1 |
| 890 | putn get Tot 3 |
| 891 | endl |
| 892 | end |
| 893 | end |
| 894 | |
| 895 | fn main to int |
| 896 | load |
| 897 | plan |
| 898 | replay |
| 899 | report |
| 900 | flush |
| 901 | ret 0 |
| 902 | end |