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 / train / omega-llm / tools / wgate / wgate.om
| 1 | om2 |
| 2 | note SPDX-License-Identifier: AGPL-3.0-only |
| 3 | note wgate.om (DRA-187, lane wsp): the round40 retention gate runner in seeded Omega. It replaces the |
| 4 | note Python glue evidence/OMEGALLM/wsp-dra187-20261107/gates.py, which imported round41 lib.py, |
| 5 | note repair.py, checker.py and check_behavior.py. Composed after wbuild.om (its main renamed wbmain): |
| 6 | note OMC=omc CORE=0 wbuild OUT/wgate tools/omegallm/wdrive/wbuild.om@wbmain tools/omegallm/wgate/wgate.om |
| 7 | note Usage (README.md has the full contract): |
| 8 | note wgate run CANDIDATE.ck OUTDIR |
| 9 | note wgate replay probe|first|jobs DATA.json RECORDED.json OUTDIR [STRIDE] |
| 10 | note wgate replaylog probe|first|jobs DATA.json RECORDED.json LOGDIR LABEL OUTDIR [STRIDE] |
| 11 | note wgate dryrun probe|jobs CK OUTDIR LABEL DATA.json |
| 12 | note Exits: 0 done (run: every task finished or stopped at a failed gate; replay: no mismatch), |
| 13 | note 1 replay mismatch, 2 usage, 3 refused (no SPARK_WINDOW), 4 base checkpoint sha256 mismatch, |
| 14 | note 5 OUTDIR belongs to another candidate, 10 window budget reached, 61 arena or table full, |
| 15 | note 70 host failure, 71 file operation failed, 72 text decode or encode error, 73 native command |
| 16 | note exit status not 0, 74 native command timeout, 75 sampler answer count mismatch, 76 compile or |
| 17 | note test timeout inside compile_test, 77 JSON nesting past the measured Python limit, 78 geval |
| 18 | note output unparsable, 79 unsupported JSON shape, 80 data or recorded file is not JSON. |
| 19 | note |
| 20 | note Every string lives in the arena wga as (offset, length); functions take offsets because a part of |
| 21 | note a global is refused (error 19). wgr carries extra results. Slots (wgsl) name arena strings. |
| 22 | |
| 23 | const WGNO ulong 18446744073709551615 |
| 24 | const WGREC ulong 18446744073709551614 |
| 25 | const WGTMO long -1000000 |
| 26 | const WGABS long -2000000 |
| 27 | const WGMAXA ulong 16777216 |
| 28 | const WGMAXJ ulong 2097152 |
| 29 | const SOUT ulong 0 |
| 30 | const SCAND ulong 1 |
| 31 | const SCK ulong 2 |
| 32 | const SLAB ulong 3 |
| 33 | const SWIN ulong 4 |
| 34 | const SFIX ulong 5 |
| 35 | const SCL ulong 6 |
| 36 | const SJL ulong 7 |
| 37 | const SLOG ulong 8 |
| 38 | const SBLD ulong 9 |
| 39 | const SCB ulong 10 |
| 40 | const SCT ulong 11 |
| 41 | const SJF ulong 12 |
| 42 | const SPL ulong 13 |
| 43 | |
| 44 | global wga uchar 16777216 |
| 45 | global wgan ulong 1 |
| 46 | global wgr ulong 8 |
| 47 | global wgsl ulong 64 |
| 48 | global wgjt uchar 2097152 |
| 49 | global wgjo ulong 2097152 |
| 50 | global wgjl ulong 2097152 |
| 51 | global wgjc ulong 2097152 |
| 52 | global wgjs ulong 2097152 |
| 53 | global wgjn ulong 1 |
| 54 | global wgks ulong 10000 |
| 55 | global wgkl ulong 10000 |
| 56 | global wgps ulong 8 |
| 57 | global wgnd ulong 68 |
| 58 | global wgsb uchar 128 |
| 59 | global wgpo ulong 1024 |
| 60 | global wgpl ulong 1024 |
| 61 | global wgao ulong 1024 |
| 62 | global wgal ulong 1024 |
| 63 | global wgact ulong 1024 |
| 64 | global wgdr ulong 1024 |
| 65 | global wgrr ulong 1024 |
| 66 | global wgok uchar 1024 |
| 67 | global wgx long 4 |
| 68 | global wgxr long 4 |
| 69 | global wgmd ulong 4 |
| 70 | global wgob uchar 65536 |
| 71 | global wgobn ulong 1 |
| 72 | global wgobf int 1 |
| 73 | global wgg uchar 8 |
| 74 | global wgtm long 4 |
| 75 | global wgmis ulong 1 |
| 76 | global wgjst uchar 1024 |
| 77 | global wgjso ulong 1024 |
| 78 | global wgjsn ulong 1024 |
| 79 | global wgjoo ulong 1024 |
| 80 | global wgjon ulong 1024 |
| 81 | global wgjdn uchar 1024 |
| 82 | global wgjps uchar 1024 |
| 83 | global wgjvf uchar 1024 |
| 84 | global wgjhv uchar 1024 |
| 85 | global wgjer uchar 1024 |
| 86 | global wgjtn ulong 1024 |
| 87 | global wgtro ulong 7168 |
| 88 | global wgtrl ulong 7168 |
| 89 | global wgtst uchar 7168 |
| 90 | global wgtto ulong 7168 |
| 91 | global wgttn ulong 7168 |
| 92 | global wgtth uchar 7168 |
| 93 | |
| 94 | text wgtomc "/home/drakestapleton/handoffs/omega-llm-20261101/omega-mv/seed/out/omc" |
| 95 | text wgtgpu "/tmp/gk/r10/ollm-gb10" |
| 96 | text wgtcpu "/home/drakestapleton/handoffs/weight-tuning-20261104/build/ollm" |
| 97 | text wgtmrg "/home/drakestapleton/handoffs/omega-llm-20261101/v1-data/merges4096.bin" |
| 98 | text wgtbs "/home/drakestapleton/handoffs/tool-omega-20261104/build/batch-sample" |
| 99 | text wgtr40d "/home/drakestapleton/handoffs/tool-omega-20261104/round40/data/" |
| 100 | text wgtstok "/home/drakestapleton/handoffs/tool-omega-20261104/round40/data/story-final.tok" |
| 101 | text wgtbase "/home/drakestapleton/.local/share/omega-tool-model/round40/model.ck" |
| 102 | text wgtbsha "7c7b5b5260f2d9453b6076b64e7f23e88341d96498584f2dfaa229c31ad2e346" |
| 103 | text wgtnull "/dev/null" |
| 104 | text wgtnl "\n" |
| 105 | text wgtsp " " |
| 106 | text wgtfull "wgate: arena or table full\n" |
| 107 | text wgtfile "wgate: file operation failed: " |
| 108 | text wgtdec "wgate: text decode or encode error: " |
| 109 | text wgtnoj "wgate: not JSON: " |
| 110 | text wgtshp "wgate: unsupported JSON shape\n" |
| 111 | text wgtrec "wgate: JSON nesting past the Python recursion limit\n" |
| 112 | text wgthost "wgate: host failure\n" |
| 113 | text wgtcmdf "wgate: native command failed: " |
| 114 | text wgtcmdt "wgate: native command timed out: " |
| 115 | text wgtcnt "wgate: sampler answer count mismatch: " |
| 116 | text wgtctt "wgate: compile_test timed out\n" |
| 117 | text wgtgev "wgate: geval output has no single E row for the width\n" |
| 118 | text wgtuse "usage: wgate run CANDIDATE.ck OUTDIR | replay probe|first|jobs DATA REC OUTDIR [STRIDE] | replaylog probe|first|jobs DATA REC LOGDIR LABEL OUTDIR [STRIDE] | dryrun probe|jobs CK OUTDIR LABEL DATA\n" |
| 119 | text wgtrefu "REFUSED: SPARK_WINDOW is not set; run inside a spark window\n" |
| 120 | text wgtbsm "wgate: base checkpoint sha256 mismatch: " |
| 121 | text wgtcsm "wgate: OUTDIR belongs to another candidate\n" |
| 122 | text wgtzero "wgate: latency base time is zero\n" |
| 123 | text wgtsw "SPARK_WINDOW" |
| 124 | text wgtbud "WSP_BUDGET" |
| 125 | text wgtbudb "wgate: WSP_BUDGET is not a decimal number\n" |
| 126 | text wgtdiv "wgate: replay has no recorded answer for this turn\n" |
| 127 | |
| 128 | note ---------------------------------------------------------------- basics |
| 129 | |
| 130 | fn wgdie t view uchar * c int to void |
| 131 | wdoflush 1 |
| 132 | w = write 2 t 0 len t |
| 133 | exit c |
| 134 | end |
| 135 | |
| 136 | fn wgdiep t view uchar * c int to void |
| 137 | wdoflush 1 |
| 138 | w = write 2 t 0 len t |
| 139 | w2 = write 2 wdp 0 get wdpn 0 |
| 140 | w3 = write 2 wgtnl 0 1 |
| 141 | exit c |
| 142 | end |
| 143 | |
| 144 | fn wgac c ulong to void |
| 145 | n = get wgan 0 |
| 146 | if ge n WGMAXA |
| 147 | wgdie wgtfull 61 |
| 148 | end |
| 149 | put wga n uchar c |
| 150 | put wgan 0 add n 1 |
| 151 | end |
| 152 | |
| 153 | fn wgat t view uchar * to void |
| 154 | for i ulong len t |
| 155 | wgac ulong get t i |
| 156 | end |
| 157 | end |
| 158 | |
| 159 | fn wgacp o ulong n ulong to void |
| 160 | i = ulong 0 |
| 161 | while lt i n bound 64 |
| 162 | while lt i n bound 999999 |
| 163 | wgac ulong get wga add o i |
| 164 | i = add i 1 |
| 165 | end |
| 166 | end |
| 167 | end |
| 168 | |
| 169 | fn wgad v ulong to void |
| 170 | k = wddec v |
| 171 | while gt k 0 bound 25 |
| 172 | k = sub k 1 |
| 173 | wgac ulong get wdt k |
| 174 | end |
| 175 | end |
| 176 | |
| 177 | fn wgadl v long to void |
| 178 | if lt v 0 |
| 179 | wgac 45 |
| 180 | wgad ulong neg v |
| 181 | else |
| 182 | wgad ulong v |
| 183 | end |
| 184 | end |
| 185 | |
| 186 | fn wgsset k ulong o ulong n ulong to void |
| 187 | put wgsl mul k 2 o |
| 188 | put wgsl add mul k 2 1 n |
| 189 | end |
| 190 | |
| 191 | fn wgso k ulong to ulong |
| 192 | ret get wgsl mul k 2 |
| 193 | end |
| 194 | |
| 195 | fn wgsn k ulong to ulong |
| 196 | ret get wgsl add mul k 2 1 |
| 197 | end |
| 198 | |
| 199 | note append slot k to the arena |
| 200 | fn wgasl k ulong to void |
| 201 | wgacp wgso k wgsn k |
| 202 | end |
| 203 | |
| 204 | note slot k = text t |
| 205 | fn wgsett k ulong t view uchar * to void |
| 206 | o = get wgan 0 |
| 207 | wgat t |
| 208 | wgsset k o len t |
| 209 | end |
| 210 | |
| 211 | note slot k = the path builder's bytes |
| 212 | fn wgsetp k ulong to void |
| 213 | o = get wgan 0 |
| 214 | for i ulong get wdpn 0 |
| 215 | wgac ulong get wdp i |
| 216 | end |
| 217 | wgsset k o get wdpn 0 |
| 218 | end |
| 219 | |
| 220 | note slot k = the arena from offset o to the top |
| 221 | fn wgsetf k ulong o ulong to void |
| 222 | wgsset k o sub get wgan 0 o |
| 223 | end |
| 224 | |
| 225 | fn wgeqa a ulong b ulong n ulong to bool |
| 226 | i = ulong 0 |
| 227 | while lt i n bound 999999 |
| 228 | if ne get wga add a i get wga add b i |
| 229 | ret false |
| 230 | end |
| 231 | i = add i 1 |
| 232 | end |
| 233 | ret true |
| 234 | end |
| 235 | |
| 236 | fn wgeq2 a ulong an ulong b ulong bn ulong to bool |
| 237 | if ne an bn |
| 238 | ret false |
| 239 | end |
| 240 | ret wgeqa a b an |
| 241 | end |
| 242 | |
| 243 | fn wgeqt o ulong n ulong t view uchar * to bool |
| 244 | if ne n len t |
| 245 | ret false |
| 246 | end |
| 247 | for i ulong n |
| 248 | if ne get wga add o i get t i |
| 249 | ret false |
| 250 | end |
| 251 | end |
| 252 | ret true |
| 253 | end |
| 254 | |
| 255 | fn wgsw o ulong n ulong t view uchar * to bool |
| 256 | if lt n len t |
| 257 | ret false |
| 258 | end |
| 259 | for i ulong len t |
| 260 | if ne get wga add o i get t i |
| 261 | ret false |
| 262 | end |
| 263 | end |
| 264 | ret true |
| 265 | end |
| 266 | |
| 267 | note first index (relative) of arena pattern p in [o, o + n), or WGNO |
| 268 | fn wgfind o ulong n ulong p ulong pn ulong to ulong |
| 269 | if gt pn n |
| 270 | ret WGNO |
| 271 | end |
| 272 | lim = sub n pn |
| 273 | i = ulong 0 |
| 274 | while le i lim bound 999999 |
| 275 | if wgeqa add o i p pn |
| 276 | ret i |
| 277 | end |
| 278 | i = add i 1 |
| 279 | end |
| 280 | ret WGNO |
| 281 | end |
| 282 | |
| 283 | note as wgfind with a text pattern |
| 284 | fn wgfindt o ulong n ulong t view uchar * to ulong |
| 285 | pn = len t |
| 286 | if gt pn n |
| 287 | ret WGNO |
| 288 | end |
| 289 | lim = sub n pn |
| 290 | i = ulong 0 |
| 291 | while le i lim bound 999999 |
| 292 | if wgsw add o i sub n i t |
| 293 | ret i |
| 294 | end |
| 295 | i = add i 1 |
| 296 | end |
| 297 | ret WGNO |
| 298 | end |
| 299 | |
| 300 | note non-overlapping occurrences of arena pattern p (pn > 0), as str.count |
| 301 | fn wgcnt o ulong n ulong p ulong pn ulong to ulong |
| 302 | c = ulong 0 |
| 303 | i = ulong 0 |
| 304 | while le add i pn n bound 999999 |
| 305 | if wgeqa add o i p pn |
| 306 | c = add c 1 |
| 307 | i = add i pn |
| 308 | else |
| 309 | i = add i 1 |
| 310 | end |
| 311 | end |
| 312 | ret c |
| 313 | end |
| 314 | |
| 315 | fn wgcntt o ulong n ulong t view uchar * to ulong |
| 316 | c = ulong 0 |
| 317 | i = ulong 0 |
| 318 | pn = len t |
| 319 | while le add i pn n bound 999999 |
| 320 | if wgsw add o i sub n i t |
| 321 | c = add c 1 |
| 322 | i = add i pn |
| 323 | else |
| 324 | i = add i 1 |
| 325 | end |
| 326 | end |
| 327 | ret c |
| 328 | end |
| 329 | |
| 330 | note ---------------------------------------------------------------- results buffer (wgob to fd wgobf) |
| 331 | |
| 332 | fn wgofl to void |
| 333 | n = get wgobn 0 |
| 334 | t = ulong 0 |
| 335 | while lt t n bound 999999 |
| 336 | w = write get wgobf 0 wgob t sub n t |
| 337 | if le w 0 |
| 338 | wgdie wgthost 70 |
| 339 | end |
| 340 | t = add t ulong w |
| 341 | end |
| 342 | put wgobn 0 0 |
| 343 | end |
| 344 | |
| 345 | fn wgoc c ulong to void |
| 346 | n = get wgobn 0 |
| 347 | if ge n 65536 |
| 348 | wgofl |
| 349 | n = 0 |
| 350 | end |
| 351 | put wgob n uchar c |
| 352 | put wgobn 0 add n 1 |
| 353 | end |
| 354 | |
| 355 | fn wgot t view uchar * to void |
| 356 | for i ulong len t |
| 357 | wgoc ulong get t i |
| 358 | end |
| 359 | end |
| 360 | |
| 361 | fn wgoa o ulong n ulong to void |
| 362 | i = ulong 0 |
| 363 | while lt i n bound 999999 |
| 364 | wgoc ulong get wga add o i |
| 365 | i = add i 1 |
| 366 | end |
| 367 | end |
| 368 | |
| 369 | fn wgod v ulong to void |
| 370 | k = wddec v |
| 371 | while gt k 0 bound 25 |
| 372 | k = sub k 1 |
| 373 | wgoc ulong get wdt k |
| 374 | end |
| 375 | end |
| 376 | |
| 377 | fn wgodl v long to void |
| 378 | if lt v 0 |
| 379 | wgoc 45 |
| 380 | wgod ulong neg v |
| 381 | else |
| 382 | wgod ulong v |
| 383 | end |
| 384 | end |
| 385 | |
| 386 | note stdout helpers over wdo: arena range and signed decimal |
| 387 | fn wgpra o ulong n ulong to void |
| 388 | i = ulong 0 |
| 389 | while lt i n bound 999999 |
| 390 | wdoc ulong get wga add o i |
| 391 | i = add i 1 |
| 392 | end |
| 393 | end |
| 394 | |
| 395 | fn wgprl v long to void |
| 396 | if lt v 0 |
| 397 | wdoc 45 |
| 398 | wdod ulong neg v |
| 399 | else |
| 400 | wdod ulong v |
| 401 | end |
| 402 | end |
| 403 | |
| 404 | note ---------------------------------------------------------------- text (model output is ASCII; wgasc refuses the rest) |
| 405 | |
| 406 | note exit 72 unless every byte of [o, o + n) is ASCII |
| 407 | fn wgasc o ulong n ulong to void |
| 408 | i = ulong 0 |
| 409 | while lt i n bound 64 |
| 410 | while lt i n bound 999999 |
| 411 | if gt get wga add o i 127 |
| 412 | wgdie wgtdec 72 |
| 413 | end |
| 414 | i = add i 1 |
| 415 | end |
| 416 | end |
| 417 | end |
| 418 | |
| 419 | note str.isspace on ASCII: 9..13 and 28..32 |
| 420 | fn wgisws c ulong to bool |
| 421 | if and ge c 9 le c 13 |
| 422 | ret true |
| 423 | end |
| 424 | ret and ge c 28 le c 32 |
| 425 | end |
| 426 | |
| 427 | note str.strip(): result in wgr 0, wgr 1 |
| 428 | fn wgstrip o ulong n ulong to void |
| 429 | a = o |
| 430 | e = add o n |
| 431 | while lt a e bound 999999 |
| 432 | if not wgisws ulong get wga a |
| 433 | break |
| 434 | end |
| 435 | a = add a 1 |
| 436 | end |
| 437 | while gt e a bound 999999 |
| 438 | if not wgisws ulong get wga sub e 1 |
| 439 | break |
| 440 | end |
| 441 | e = sub e 1 |
| 442 | end |
| 443 | put wgr 0 a |
| 444 | put wgr 1 sub e a |
| 445 | end |
| 446 | |
| 447 | note text(raw) = raw.split('\nDone.')[0].strip(): result in wgr 0, wgr 1 |
| 448 | text wgtdone "\nDone." |
| 449 | fn wgtext o ulong n ulong to void |
| 450 | k = wgfindt o n wgtdone |
| 451 | m = n |
| 452 | if ne k WGNO |
| 453 | m = k |
| 454 | end |
| 455 | wgstrip o m |
| 456 | end |
| 457 | |
| 458 | note str.splitlines on ASCII: the line [p, result) ends at \n \r \r\n \v \f \x1c \x1d \x1e; next start in wgr 2 |
| 459 | fn wgeol p ulong e ulong to ulong |
| 460 | q = p |
| 461 | while lt q e bound 999999 |
| 462 | c = get wga q |
| 463 | if or or eq c 10 eq c 11 or eq c 12 eq c 28 |
| 464 | put wgr 2 add q 1 |
| 465 | ret q |
| 466 | end |
| 467 | if or eq c 29 eq c 30 |
| 468 | put wgr 2 add q 1 |
| 469 | ret q |
| 470 | end |
| 471 | if eq c 13 |
| 472 | put wgr 2 add q 1 |
| 473 | if lt add q 1 e |
| 474 | if eq get wga add q 1 10 |
| 475 | put wgr 2 add q 2 |
| 476 | end |
| 477 | end |
| 478 | ret q |
| 479 | end |
| 480 | q = add q 1 |
| 481 | end |
| 482 | put wgr 2 e |
| 483 | ret e |
| 484 | end |
| 485 | |
| 486 | fn wgdig c ulong to bool |
| 487 | ret and ge c 48 le c 57 |
| 488 | end |
| 489 | |
| 490 | note re.fullmatch of one line against a pattern in the wgate mini-language: |
| 491 | note @ = \d{1,3}, % = \d{1,2}, ^ = [1-5], ~ = [1-6], $ = [A-Za-z0-9 ]{0,80}. No literal of the |
| 492 | note patterns is a digit or a class member right after a run, so the greedy run is the regex result. |
| 493 | fn wgmatch o ulong n ulong t view uchar * to bool |
| 494 | i = ulong 0 |
| 495 | j = ulong 0 |
| 496 | while lt j len t bound 4096 |
| 497 | pc = ulong get t j |
| 498 | j = add j 1 |
| 499 | if or eq pc 64 eq pc 37 |
| 500 | k = ulong 0 |
| 501 | while lt add i k n bound 4096 |
| 502 | if not wgdig ulong get wga add o add i k |
| 503 | break |
| 504 | end |
| 505 | k = add k 1 |
| 506 | end |
| 507 | mx = ulong 3 |
| 508 | if eq pc 37 |
| 509 | mx = 2 |
| 510 | end |
| 511 | if or eq k 0 gt k mx |
| 512 | ret false |
| 513 | end |
| 514 | i = add i k |
| 515 | continue |
| 516 | end |
| 517 | if or eq pc 94 eq pc 126 |
| 518 | if ge i n |
| 519 | ret false |
| 520 | end |
| 521 | c = ulong get wga add o i |
| 522 | hi = ulong 53 |
| 523 | if eq pc 126 |
| 524 | hi = 54 |
| 525 | end |
| 526 | if or lt c 49 gt c hi |
| 527 | ret false |
| 528 | end |
| 529 | i = add i 1 |
| 530 | continue |
| 531 | end |
| 532 | if eq pc 36 |
| 533 | k2 = ulong 0 |
| 534 | while lt add i k2 n bound 4096 |
| 535 | if not wgcls ulong get wga add o add i k2 |
| 536 | break |
| 537 | end |
| 538 | k2 = add k2 1 |
| 539 | end |
| 540 | if gt k2 80 |
| 541 | ret false |
| 542 | end |
| 543 | i = add i k2 |
| 544 | continue |
| 545 | end |
| 546 | if ge i n |
| 547 | ret false |
| 548 | end |
| 549 | if ne ulong get wga add o i pc |
| 550 | ret false |
| 551 | end |
| 552 | i = add i 1 |
| 553 | end |
| 554 | ret eq i n |
| 555 | end |
| 556 | |
| 557 | fn wgcls c ulong to bool |
| 558 | if wgdig c |
| 559 | ret true |
| 560 | end |
| 561 | if eq c 32 |
| 562 | ret true |
| 563 | end |
| 564 | if and ge c 65 le c 90 |
| 565 | ret true |
| 566 | end |
| 567 | ret and ge c 97 le c 122 |
| 568 | end |
| 569 | |
| 570 | note checker.patterns (check_behavior.safe_lines + checker additions) |
| 571 | text wgc00 "fn main to int" |
| 572 | text wgc01 "end" |
| 573 | text wgc02 "else" |
| 574 | text wgc03 "ret @" |
| 575 | text wgc04 "ret int @" |
| 576 | text wgc05 "ret add int @ int @" |
| 577 | text wgc06 "if gt int @ int @" |
| 578 | text wgc07 "text msg \"$\\n\"" |
| 579 | text wgc08 "n = write int 1 msg ulong 0 len msg" |
| 580 | text wgc09 "if ne n long len msg" |
| 581 | text wgc10 "fn inc x int to int" |
| 582 | text wgc11 "ret add x int %" |
| 583 | text wgc12 "ret inc int %" |
| 584 | text wgc13 "s = int %" |
| 585 | text wgc14 "for i ulong ^" |
| 586 | text wgc15 "s = add s int ^" |
| 587 | text wgc16 "ret s" |
| 588 | |
| 589 | fn wgckl o ulong n ulong to bool |
| 590 | if or or wgmatch o n wgc00 wgmatch o n wgc01 or wgmatch o n wgc02 wgmatch o n wgc03 |
| 591 | ret true |
| 592 | end |
| 593 | if or or wgmatch o n wgc04 wgmatch o n wgc05 or wgmatch o n wgc06 wgmatch o n wgc07 |
| 594 | ret true |
| 595 | end |
| 596 | if or or wgmatch o n wgc08 wgmatch o n wgc09 or wgmatch o n wgc10 wgmatch o n wgc11 |
| 597 | ret true |
| 598 | end |
| 599 | if or or wgmatch o n wgc12 wgmatch o n wgc13 or wgmatch o n wgc14 wgmatch o n wgc15 |
| 600 | ret true |
| 601 | end |
| 602 | ret wgmatch o n wgc16 |
| 603 | end |
| 604 | |
| 605 | note repair.PATTERNS |
| 606 | text wgr00 "fn calc x int to int" |
| 607 | text wgr01 "ret add x int ~" |
| 608 | text wgr02 "ret mul x int ~" |
| 609 | text wgr03 "ret sub x int ~" |
| 610 | text wgr04 "ret calc int %" |
| 611 | text wgr05 "s = x" |
| 612 | text wgr06 "for i ulong ~" |
| 613 | text wgr07 "s = add s int ~" |
| 614 | |
| 615 | fn wgrpl o ulong n ulong to bool |
| 616 | if or or wgmatch o n wgr00 wgmatch o n wgc00 or wgmatch o n wgc01 wgmatch o n wgr01 |
| 617 | ret true |
| 618 | end |
| 619 | if or or wgmatch o n wgr02 wgmatch o n wgr03 or wgmatch o n wgr04 wgmatch o n wgr05 |
| 620 | ret true |
| 621 | end |
| 622 | if or or wgmatch o n wgr06 wgmatch o n wgr07 wgmatch o n wgc16 |
| 623 | ret true |
| 624 | end |
| 625 | ret false |
| 626 | end |
| 627 | |
| 628 | note every line of text.splitlines() matches: mode 0 checker, 1 repair, 2 the for-loop line only (any) |
| 629 | fn wglines o ulong n ulong md ulong to bool |
| 630 | p = o |
| 631 | e = add o n |
| 632 | hit = false |
| 633 | while lt p e bound 999999 |
| 634 | q = wgeol p e |
| 635 | ln = sub q p |
| 636 | nx = get wgr 2 |
| 637 | if eq md 2 |
| 638 | if wgmatch p ln wgc14 |
| 639 | hit = true |
| 640 | end |
| 641 | else |
| 642 | ok = false |
| 643 | if eq md 0 |
| 644 | ok = wgckl p ln |
| 645 | else |
| 646 | ok = wgrpl p ln |
| 647 | end |
| 648 | if not ok |
| 649 | ret false |
| 650 | end |
| 651 | end |
| 652 | p = nx |
| 653 | end |
| 654 | if eq md 2 |
| 655 | ret hit |
| 656 | end |
| 657 | ret true |
| 658 | end |
| 659 | |
| 660 | note ---------------------------------------------------------------- JSON (CPython 3.12 json.loads on the subset wgate meets) |
| 661 | note Node kinds in wgjt: 1 null, 2 false, 3 true, 4 number, 5 string, 6 array, 7 object. A string's |
| 662 | note decoded bytes are (wgjo, wgjl) in the arena; a number keeps its source text there. Containers: |
| 663 | note first child wgjc, next sibling wgjs, count wgjo. Object children alternate key, value. |
| 664 | note Refused (exit 79): \u escapes naming surrogates, NaN, Infinity, nesting deeper than 512. |
| 665 | note A malformed text gives WGNO (the ValueError of json.loads). |
| 666 | |
| 667 | fn wgjnew t ulong o ulong n ulong to ulong |
| 668 | k = get wgjn 0 |
| 669 | if ge k WGMAXJ |
| 670 | wgdie wgtfull 61 |
| 671 | end |
| 672 | put wgjt k uchar t |
| 673 | put wgjo k o |
| 674 | put wgjl k n |
| 675 | put wgjc k 0 |
| 676 | put wgjs k 0 |
| 677 | put wgjn 0 add k 1 |
| 678 | ret k |
| 679 | end |
| 680 | |
| 681 | fn wgjws p ulong e ulong to ulong |
| 682 | q = p |
| 683 | while lt q e bound 999999 |
| 684 | c = get wga q |
| 685 | if and and ne c 32 ne c 9 and ne c 10 ne c 13 |
| 686 | ret q |
| 687 | end |
| 688 | q = add q 1 |
| 689 | end |
| 690 | ret q |
| 691 | end |
| 692 | |
| 693 | fn wghex4 p ulong to ulong |
| 694 | v = ulong 0 |
| 695 | for i ulong 4 |
| 696 | c = ulong get wga add p i |
| 697 | d = WGNO |
| 698 | if and ge c 48 le c 57 |
| 699 | d = sub c 48 |
| 700 | end |
| 701 | if and ge c 97 le c 102 |
| 702 | d = sub c 87 |
| 703 | end |
| 704 | if and ge c 65 le c 70 |
| 705 | d = sub c 55 |
| 706 | end |
| 707 | if eq d WGNO |
| 708 | ret WGNO |
| 709 | end |
| 710 | v = or shl v 4 d |
| 711 | end |
| 712 | ret v |
| 713 | end |
| 714 | |
| 715 | fn wgenc v ulong to void |
| 716 | if lt v 128 |
| 717 | wgac v |
| 718 | ret |
| 719 | end |
| 720 | if lt v 2048 |
| 721 | wgac or 192 shr v 6 |
| 722 | wgac or 128 and v 63 |
| 723 | ret |
| 724 | end |
| 725 | wgac or 224 shr v 12 |
| 726 | wgac or 128 and shr v 6 63 |
| 727 | wgac or 128 and v 63 |
| 728 | end |
| 729 | |
| 730 | note one escape; q is the byte after the backslash. New position or WGNO. |
| 731 | fn wgjesc q ulong e ulong to ulong |
| 732 | if ge q e |
| 733 | ret WGNO |
| 734 | end |
| 735 | d = ulong get wga q |
| 736 | if ne d 117 |
| 737 | c = ulong 0 |
| 738 | if or or eq d 34 eq d 92 eq d 47 |
| 739 | c = d |
| 740 | end |
| 741 | if eq d 98 |
| 742 | c = 8 |
| 743 | end |
| 744 | if eq d 102 |
| 745 | c = 12 |
| 746 | end |
| 747 | if eq d 110 |
| 748 | c = 10 |
| 749 | end |
| 750 | if eq d 114 |
| 751 | c = 13 |
| 752 | end |
| 753 | if eq d 116 |
| 754 | c = 9 |
| 755 | end |
| 756 | if eq c 0 |
| 757 | ret WGNO |
| 758 | end |
| 759 | wgac c |
| 760 | ret add q 1 |
| 761 | end |
| 762 | h = add q 1 |
| 763 | if ge add h 4 e |
| 764 | ret WGNO |
| 765 | end |
| 766 | v = wghex4 h |
| 767 | if eq v WGNO |
| 768 | ret WGNO |
| 769 | end |
| 770 | if and ge v 55296 le v 57343 |
| 771 | wgdie wgtshp 79 |
| 772 | end |
| 773 | wgenc v |
| 774 | ret add h 4 |
| 775 | end |
| 776 | |
| 777 | note string body from p (after the quote); decoded into the arena top (wgr 3, wgr 4); returns the index after the closing quote |
| 778 | fn wgjstr p ulong e ulong to ulong |
| 779 | o = get wgan 0 |
| 780 | q = p |
| 781 | while lt q e bound 999999 |
| 782 | c = ulong get wga q |
| 783 | if eq c 34 |
| 784 | put wgr 3 o |
| 785 | put wgr 4 sub get wgan 0 o |
| 786 | ret add q 1 |
| 787 | end |
| 788 | if lt c 32 |
| 789 | ret WGNO |
| 790 | end |
| 791 | if eq c 92 |
| 792 | q = wgjesc add q 1 e |
| 793 | if eq q WGNO |
| 794 | ret WGNO |
| 795 | end |
| 796 | else |
| 797 | wgac c |
| 798 | q = add q 1 |
| 799 | end |
| 800 | end |
| 801 | ret WGNO |
| 802 | end |
| 803 | |
| 804 | fn wgdgs i ulong e ulong to ulong |
| 805 | q = i |
| 806 | while lt q e bound 999999 |
| 807 | if not wgdig ulong get wga q |
| 808 | ret q |
| 809 | end |
| 810 | q = add q 1 |
| 811 | end |
| 812 | ret q |
| 813 | end |
| 814 | |
| 815 | note _match_number_unicode: returns the end index or WGNO |
| 816 | fn wgjnum p ulong e ulong to ulong |
| 817 | ed = sub e 1 |
| 818 | i = p |
| 819 | if eq get wga i 45 |
| 820 | i = add i 1 |
| 821 | if gt i ed |
| 822 | ret WGNO |
| 823 | end |
| 824 | end |
| 825 | c = ulong get wga i |
| 826 | if and ge c 49 le c 57 |
| 827 | i = wgdgs add i 1 e |
| 828 | else |
| 829 | if ne c 48 |
| 830 | ret WGNO |
| 831 | end |
| 832 | i = add i 1 |
| 833 | end |
| 834 | nd = sub i p |
| 835 | if eq get wga p 45 |
| 836 | nd = sub nd 1 |
| 837 | end |
| 838 | isf = false |
| 839 | if lt i ed |
| 840 | if eq get wga i 46 |
| 841 | if wgdig ulong get wga add i 1 |
| 842 | isf = true |
| 843 | i = wgdgs add i 2 e |
| 844 | end |
| 845 | end |
| 846 | end |
| 847 | if lt i ed |
| 848 | c3 = get wga i |
| 849 | if or eq c3 101 eq c3 69 |
| 850 | es = i |
| 851 | i = add i 1 |
| 852 | if lt i ed |
| 853 | c4 = get wga i |
| 854 | if or eq c4 45 eq c4 43 |
| 855 | i = add i 1 |
| 856 | end |
| 857 | end |
| 858 | i = wgdgs i e |
| 859 | if wgdig ulong get wga sub i 1 |
| 860 | isf = true |
| 861 | else |
| 862 | i = es |
| 863 | end |
| 864 | end |
| 865 | end |
| 866 | if not isf |
| 867 | if gt nd 4300 |
| 868 | ret WGNO |
| 869 | end |
| 870 | end |
| 871 | ret i |
| 872 | end |
| 873 | |
| 874 | note literal t at p (all of its bytes must exist) |
| 875 | fn wglit p ulong e ulong t view uchar * to bool |
| 876 | if gt add p len t e |
| 877 | ret false |
| 878 | end |
| 879 | ret wgsw p sub e p t |
| 880 | end |
| 881 | |
| 882 | note attach node k to the open container (or make it the root) |
| 883 | fn wgjatt k ulong to void |
| 884 | d = get wgps 2 |
| 885 | if eq d 0 |
| 886 | put wgps 3 k |
| 887 | ret |
| 888 | end |
| 889 | top = get wgks sub d 1 |
| 890 | last = get wgkl sub d 1 |
| 891 | if eq last 0 |
| 892 | put wgjc top k |
| 893 | else |
| 894 | put wgjs last k |
| 895 | end |
| 896 | put wgkl sub d 1 k |
| 897 | put wgjo top add get wgjo top 1 |
| 898 | end |
| 899 | |
| 900 | text wgtnul "null" |
| 901 | text wgttru "true" |
| 902 | text wgtfal "false" |
| 903 | |
| 904 | note scalar value at p: returns the index after it or WGNO |
| 905 | fn wgjscal p ulong e ulong to ulong |
| 906 | c = get wga p |
| 907 | if eq c 34 |
| 908 | q = wgjstr add p 1 e |
| 909 | if ne q WGNO |
| 910 | wgjatt wgjnew 5 get wgr 3 get wgr 4 |
| 911 | end |
| 912 | ret q |
| 913 | end |
| 914 | if eq c 110 |
| 915 | if wglit p e wgtnul |
| 916 | wgjatt wgjnew 1 0 0 |
| 917 | ret add p 4 |
| 918 | end |
| 919 | end |
| 920 | if eq c 116 |
| 921 | if wglit p e wgttru |
| 922 | wgjatt wgjnew 3 0 0 |
| 923 | ret add p 4 |
| 924 | end |
| 925 | end |
| 926 | if eq c 102 |
| 927 | if wglit p e wgtfal |
| 928 | wgjatt wgjnew 2 0 0 |
| 929 | ret add p 5 |
| 930 | end |
| 931 | end |
| 932 | if or eq c 78 eq c 73 |
| 933 | wgdie wgtshp 79 |
| 934 | end |
| 935 | q2 = wgjnum p e |
| 936 | if ne q2 WGNO |
| 937 | wgjatt wgjnew 4 p sub q2 p |
| 938 | end |
| 939 | ret q2 |
| 940 | end |
| 941 | |
| 942 | note state 0: a value is expected at wgps 0. Returns 0 go on (state in wgps 4), 2 error |
| 943 | fn wgjval to ulong |
| 944 | p = get wgps 0 |
| 945 | e = get wgps 1 |
| 946 | if ge p e |
| 947 | ret 2 |
| 948 | end |
| 949 | c = get wga p |
| 950 | if or eq c 123 eq c 91 |
| 951 | d = get wgps 2 |
| 952 | if ge d 512 |
| 953 | wgdie wgtrec 77 |
| 954 | end |
| 955 | kd = ulong 6 |
| 956 | cl = uchar 93 |
| 957 | if eq c 123 |
| 958 | kd = 7 |
| 959 | cl = 125 |
| 960 | end |
| 961 | k = wgjnew kd 0 0 |
| 962 | wgjatt k |
| 963 | put wgks d k |
| 964 | put wgkl d 0 |
| 965 | put wgps 2 add d 1 |
| 966 | p = wgjws add p 1 e |
| 967 | put wgps 0 p |
| 968 | if lt p e |
| 969 | if eq get wga p cl |
| 970 | put wgps 0 add p 1 |
| 971 | put wgps 2 d |
| 972 | put wgps 4 1 |
| 973 | ret 0 |
| 974 | end |
| 975 | end |
| 976 | put wgps 4 0 |
| 977 | if eq kd 7 |
| 978 | put wgps 4 2 |
| 979 | end |
| 980 | ret 0 |
| 981 | end |
| 982 | q = wgjscal p e |
| 983 | if eq q WGNO |
| 984 | ret 2 |
| 985 | end |
| 986 | put wgps 0 q |
| 987 | put wgps 4 1 |
| 988 | ret 0 |
| 989 | end |
| 990 | |
| 991 | note state 1: after a value. Returns 0 go on, 1 done, 2 error |
| 992 | fn wgjaft to ulong |
| 993 | e = get wgps 1 |
| 994 | p = wgjws get wgps 0 e |
| 995 | d = get wgps 2 |
| 996 | if eq d 0 |
| 997 | if ne p e |
| 998 | ret 2 |
| 999 | end |
| 1000 | ret 1 |
| 1001 | end |
| 1002 | top = get wgks sub d 1 |
| 1003 | cl = uchar 93 |
| 1004 | if eq get wgjt top 7 |
| 1005 | cl = 125 |
| 1006 | end |
| 1007 | if ge p e |
| 1008 | ret 2 |
| 1009 | end |
| 1010 | c = get wga p |
| 1011 | if eq c cl |
| 1012 | put wgps 0 add p 1 |
| 1013 | put wgps 2 sub d 1 |
| 1014 | ret 0 |
| 1015 | end |
| 1016 | if ne c 44 |
| 1017 | ret 2 |
| 1018 | end |
| 1019 | put wgps 0 wgjws add p 1 e |
| 1020 | put wgps 4 0 |
| 1021 | if eq cl 125 |
| 1022 | put wgps 4 2 |
| 1023 | end |
| 1024 | ret 0 |
| 1025 | end |
| 1026 | |
| 1027 | note state 2: an object key is expected. Returns 0 go on, 2 error |
| 1028 | fn wgjkey to ulong |
| 1029 | p = get wgps 0 |
| 1030 | e = get wgps 1 |
| 1031 | if ge p e |
| 1032 | ret 2 |
| 1033 | end |
| 1034 | if ne get wga p 34 |
| 1035 | ret 2 |
| 1036 | end |
| 1037 | q = wgjstr add p 1 e |
| 1038 | if eq q WGNO |
| 1039 | ret 2 |
| 1040 | end |
| 1041 | wgjatt wgjnew 5 get wgr 3 get wgr 4 |
| 1042 | q = wgjws q e |
| 1043 | if ge q e |
| 1044 | ret 2 |
| 1045 | end |
| 1046 | if ne get wga q 58 |
| 1047 | ret 2 |
| 1048 | end |
| 1049 | put wgps 0 wgjws add q 1 e |
| 1050 | put wgps 4 0 |
| 1051 | ret 0 |
| 1052 | end |
| 1053 | |
| 1054 | note json.loads of [o, o + n): the root node, or WGNO |
| 1055 | fn wgbom o ulong n ulong to bool |
| 1056 | if lt n 3 |
| 1057 | ret false |
| 1058 | end |
| 1059 | if ne get wga o 239 |
| 1060 | ret false |
| 1061 | end |
| 1062 | if ne get wga add o 1 187 |
| 1063 | ret false |
| 1064 | end |
| 1065 | ret eq get wga add o 2 191 |
| 1066 | end |
| 1067 | |
| 1068 | fn wgjparse o ulong n ulong to ulong |
| 1069 | e = add o n |
| 1070 | if wgbom o n |
| 1071 | ret WGNO |
| 1072 | end |
| 1073 | put wgps 0 wgjws o e |
| 1074 | put wgps 1 e |
| 1075 | put wgps 2 0 |
| 1076 | put wgps 3 0 |
| 1077 | put wgps 4 0 |
| 1078 | while true bound 64 |
| 1079 | while true bound 999999 |
| 1080 | st = get wgps 4 |
| 1081 | r = ulong 0 |
| 1082 | if eq st 0 |
| 1083 | r = wgjval |
| 1084 | else |
| 1085 | if eq st 1 |
| 1086 | r = wgjaft |
| 1087 | else |
| 1088 | r = wgjkey |
| 1089 | end |
| 1090 | end |
| 1091 | if eq r 2 |
| 1092 | ret WGNO |
| 1093 | end |
| 1094 | if eq r 1 |
| 1095 | ret get wgps 3 |
| 1096 | end |
| 1097 | end |
| 1098 | end |
| 1099 | ret WGNO |
| 1100 | end |
| 1101 | |
| 1102 | note load the file named by wdp into the arena and parse it; exit 80 when it is not JSON |
| 1103 | fn wgjfile to ulong |
| 1104 | o = wgload |
| 1105 | k = wgjparse o sub get wgan 0 o |
| 1106 | if eq k WGNO |
| 1107 | wgdiep wgtnoj 80 |
| 1108 | end |
| 1109 | ret k |
| 1110 | end |
| 1111 | |
| 1112 | note last value under key t in object k, or 0 |
| 1113 | fn wgjget k ulong t view uchar * to ulong |
| 1114 | c = get wgjc k |
| 1115 | r = ulong 0 |
| 1116 | while ne c 0 bound 999999 |
| 1117 | v = get wgjs c |
| 1118 | if wgeqt get wgjo c get wgjl c t |
| 1119 | r = v |
| 1120 | end |
| 1121 | c = get wgjs v |
| 1122 | end |
| 1123 | ret r |
| 1124 | end |
| 1125 | |
| 1126 | note last value under the arena key (o, n), or 0 |
| 1127 | fn wgjgeta k ulong o ulong n ulong to ulong |
| 1128 | c = get wgjc k |
| 1129 | r = ulong 0 |
| 1130 | while ne c 0 bound 999999 |
| 1131 | v = get wgjs c |
| 1132 | if wgeq2 get wgjo c get wgjl c o n |
| 1133 | r = v |
| 1134 | end |
| 1135 | c = get wgjs v |
| 1136 | end |
| 1137 | ret r |
| 1138 | end |
| 1139 | |
| 1140 | note an integer number node as long (exit 79 for any other node) |
| 1141 | fn wgjint k ulong to long |
| 1142 | if ne get wgjt k 4 |
| 1143 | wgdie wgtshp 79 |
| 1144 | end |
| 1145 | o = get wgjo k |
| 1146 | n = get wgjl k |
| 1147 | ng = false |
| 1148 | i = ulong 0 |
| 1149 | if eq get wga o 45 |
| 1150 | ng = true |
| 1151 | i = 1 |
| 1152 | end |
| 1153 | v = long 0 |
| 1154 | if gt sub n i 15 |
| 1155 | wgdie wgtshp 79 |
| 1156 | end |
| 1157 | while lt i n bound 32 |
| 1158 | c = ulong get wga add o i |
| 1159 | if not wgdig c |
| 1160 | wgdie wgtshp 79 |
| 1161 | end |
| 1162 | v = add mul v 10 long sub c 48 |
| 1163 | i = add i 1 |
| 1164 | end |
| 1165 | if ng |
| 1166 | ret neg v |
| 1167 | end |
| 1168 | ret v |
| 1169 | end |
| 1170 | |
| 1171 | note the string under key t of object k: (wgr 3, wgr 4); exit 79 when absent or not a string |
| 1172 | fn wgjsget k ulong t view uchar * to void |
| 1173 | v = wgjget k t |
| 1174 | if eq v 0 |
| 1175 | wgdie wgtshp 79 |
| 1176 | end |
| 1177 | if ne get wgjt v 5 |
| 1178 | wgdie wgtshp 79 |
| 1179 | end |
| 1180 | put wgr 3 get wgjo v |
| 1181 | put wgr 4 get wgjl v |
| 1182 | end |
| 1183 | |
| 1184 | note does the string under key t of object k equal text u (absent or non-string: false) |
| 1185 | fn wgjis k ulong t view uchar * u view uchar * to bool |
| 1186 | v = wgjget k t |
| 1187 | if eq v 0 |
| 1188 | ret false |
| 1189 | end |
| 1190 | if ne get wgjt v 5 |
| 1191 | ret false |
| 1192 | end |
| 1193 | ret wgeqt get wgjo v get wgjl v u |
| 1194 | end |
| 1195 | |
| 1196 | note number of distinct keys of object k |
| 1197 | fn wgjnkey k ulong to ulong |
| 1198 | c = get wgjc k |
| 1199 | r = ulong 0 |
| 1200 | while ne c 0 bound 999999 |
| 1201 | v = get wgjs c |
| 1202 | if eq wgjgeta k get wgjo c get wgjl c v |
| 1203 | r = add r 1 |
| 1204 | end |
| 1205 | c = get wgjs v |
| 1206 | end |
| 1207 | ret r |
| 1208 | end |
| 1209 | |
| 1210 | note exit 79 unless k is an object whose values are all strings (the expected answers) |
| 1211 | fn wgjflat k ulong to void |
| 1212 | if ne get wgjt k 7 |
| 1213 | wgdie wgtshp 79 |
| 1214 | end |
| 1215 | c = get wgjc k |
| 1216 | while ne c 0 bound 999999 |
| 1217 | v = get wgjs c |
| 1218 | if ne get wgjt v 5 |
| 1219 | wgdie wgtshp 79 |
| 1220 | end |
| 1221 | c = get wgjs v |
| 1222 | end |
| 1223 | end |
| 1224 | |
| 1225 | note text of nodes a and b equal |
| 1226 | fn wgjeqn a ulong b ulong to bool |
| 1227 | ao = get wgjo a |
| 1228 | an = get wgjl a |
| 1229 | ret wgeq2 ao an get wgjo b get wgjl b |
| 1230 | end |
| 1231 | |
| 1232 | note Python ==: model value d against flat expected object x |
| 1233 | fn wgjeqx d ulong x ulong to bool |
| 1234 | if ne get wgjt d 7 |
| 1235 | ret false |
| 1236 | end |
| 1237 | if ne wgjnkey d wgjnkey x |
| 1238 | ret false |
| 1239 | end |
| 1240 | c = get wgjc x |
| 1241 | while ne c 0 bound 999999 |
| 1242 | xv = wgjgeta x get wgjo c get wgjl c |
| 1243 | dv = wgjgeta d get wgjo c get wgjl c |
| 1244 | if eq dv 0 |
| 1245 | ret false |
| 1246 | end |
| 1247 | if ne get wgjt dv 5 |
| 1248 | ret false |
| 1249 | end |
| 1250 | if not wgjeqn dv xv |
| 1251 | ret false |
| 1252 | end |
| 1253 | c = get wgjs get wgjs c |
| 1254 | end |
| 1255 | ret true |
| 1256 | end |
| 1257 | |
| 1258 | note array k into wgdr (data rows) with a stride; returns the count |
| 1259 | fn wgjrows k ulong st ulong to ulong |
| 1260 | if ne get wgjt k 6 |
| 1261 | wgdie wgtshp 79 |
| 1262 | end |
| 1263 | c = get wgjc k |
| 1264 | i = ulong 0 |
| 1265 | m = ulong 0 |
| 1266 | while ne c 0 bound 999999 |
| 1267 | if eq rem i st 0 |
| 1268 | if ge m 1024 |
| 1269 | wgdie wgtfull 61 |
| 1270 | end |
| 1271 | put wgdr m c |
| 1272 | m = add m 1 |
| 1273 | end |
| 1274 | i = add i 1 |
| 1275 | c = get wgjs c |
| 1276 | end |
| 1277 | ret m |
| 1278 | end |
| 1279 | |
| 1280 | note array k into wgrr (recorded rows); returns the count |
| 1281 | fn wgjrec k ulong to ulong |
| 1282 | if ne get wgjt k 6 |
| 1283 | wgdie wgtshp 79 |
| 1284 | end |
| 1285 | c = get wgjc k |
| 1286 | m = ulong 0 |
| 1287 | while ne c 0 bound 999999 |
| 1288 | if ge m 1024 |
| 1289 | wgdie wgtfull 61 |
| 1290 | end |
| 1291 | put wgrr m c |
| 1292 | m = add m 1 |
| 1293 | c = get wgjs c |
| 1294 | end |
| 1295 | ret m |
| 1296 | end |
| 1297 | |
| 1298 | note element i of array k, or 0 |
| 1299 | fn wgjat k ulong i ulong to ulong |
| 1300 | c = get wgjc k |
| 1301 | j = ulong 0 |
| 1302 | while ne c 0 bound 999999 |
| 1303 | if eq j i |
| 1304 | ret c |
| 1305 | end |
| 1306 | j = add j 1 |
| 1307 | c = get wgjs c |
| 1308 | end |
| 1309 | ret 0 |
| 1310 | end |
| 1311 | |
| 1312 | note ---------------------------------------------------------------- paths, files, processes |
| 1313 | |
| 1314 | note append slot k / arena range / OUT/t to the path builder |
| 1315 | fn wgpsl k ulong to void |
| 1316 | o = wgso k |
| 1317 | n = wgsn k |
| 1318 | for j ulong n |
| 1319 | wdpc ulong get wga add o j |
| 1320 | end |
| 1321 | end |
| 1322 | |
| 1323 | fn wgpar o ulong n ulong to void |
| 1324 | for j ulong n |
| 1325 | wdpc ulong get wga add o j |
| 1326 | end |
| 1327 | end |
| 1328 | |
| 1329 | fn wgpout t view uchar * to void |
| 1330 | wdpclr |
| 1331 | wgpsl SOUT |
| 1332 | wdpc 47 |
| 1333 | wdpt t |
| 1334 | end |
| 1335 | |
| 1336 | note the whole file named by wdp onto the arena top; returns its offset (exit 71 when unreadable) |
| 1337 | fn wgload to ulong |
| 1338 | fd = wdopen 0 0 |
| 1339 | if lt fd 0 |
| 1340 | wgdiep wgtfile 71 |
| 1341 | end |
| 1342 | o = get wgan 0 |
| 1343 | fin = false |
| 1344 | while not fin bound 999999 |
| 1345 | t = get wgan 0 |
| 1346 | if ge t WGMAXA |
| 1347 | wgdie wgtfull 61 |
| 1348 | end |
| 1349 | r = read fd wga t sub WGMAXA t |
| 1350 | if lt r 0 |
| 1351 | wgdiep wgtfile 71 |
| 1352 | end |
| 1353 | if eq r 0 |
| 1354 | fin = true |
| 1355 | else |
| 1356 | put wgan 0 add t ulong r |
| 1357 | end |
| 1358 | end |
| 1359 | c = fclose fd |
| 1360 | ret o |
| 1361 | end |
| 1362 | |
| 1363 | fn wgwr fd int o ulong n ulong to void |
| 1364 | t = ulong 0 |
| 1365 | while lt t n bound 999999 |
| 1366 | w = write fd wga add o t sub n t |
| 1367 | if le w 0 |
| 1368 | wgdie wgthost 70 |
| 1369 | end |
| 1370 | t = add t ulong w |
| 1371 | end |
| 1372 | end |
| 1373 | |
| 1374 | fn wgwrt fd int t view uchar * to void |
| 1375 | w = write fd t 0 len t |
| 1376 | if ne w long len t |
| 1377 | wgdie wgthost 70 |
| 1378 | end |
| 1379 | end |
| 1380 | |
| 1381 | note open wdp for writing: truncate (ap false) or append (ap true); exit 71 on failure |
| 1382 | fn wgcreat ap bool to int |
| 1383 | fl = int 577 |
| 1384 | if ap |
| 1385 | fl = 1089 |
| 1386 | end |
| 1387 | fd = wdopen fl 438 |
| 1388 | if lt fd 0 |
| 1389 | wgdiep wgtfile 71 |
| 1390 | end |
| 1391 | ret fd |
| 1392 | end |
| 1393 | |
| 1394 | note write [o, o + n) to the file wdp (Path.write_text / write_bytes) |
| 1395 | fn wgwfile o ulong n ulong to void |
| 1396 | fd = wgcreat false |
| 1397 | wgwr fd o n |
| 1398 | c = fclose fd |
| 1399 | end |
| 1400 | |
| 1401 | fn wgisdir to bool |
| 1402 | r = stat wdp 0 get wdpn 0 wgsb 0 128 |
| 1403 | if ne r 0 |
| 1404 | ret false |
| 1405 | end |
| 1406 | m = or ulong get wgsb 16 shl ulong get wgsb 17 8 |
| 1407 | ret eq and m 61440 16384 |
| 1408 | end |
| 1409 | |
| 1410 | fn wgexist to bool |
| 1411 | r = stat wdp 0 get wdpn 0 wgsb 0 128 |
| 1412 | ret eq r 0 |
| 1413 | end |
| 1414 | |
| 1415 | note mkdir of the first n bytes of wdp, exist_ok |
| 1416 | fn wgmk1 n ulong to void |
| 1417 | r = makedir wdp 0 n 511 |
| 1418 | if eq r 0 |
| 1419 | ret |
| 1420 | end |
| 1421 | if ne r -17 |
| 1422 | wgdiep wgtfile 71 |
| 1423 | end |
| 1424 | s = stat wdp 0 n wgsb 0 128 |
| 1425 | if ne s 0 |
| 1426 | wgdiep wgtfile 71 |
| 1427 | end |
| 1428 | m = or ulong get wgsb 16 shl ulong get wgsb 17 8 |
| 1429 | if ne and m 61440 16384 |
| 1430 | wgdiep wgtfile 71 |
| 1431 | end |
| 1432 | end |
| 1433 | |
| 1434 | note mkdir -p of the whole path builder (parents=True, exist_ok=True) |
| 1435 | fn wgmkp to void |
| 1436 | n = get wdpn 0 |
| 1437 | i = ulong 1 |
| 1438 | while lt i n bound 4096 |
| 1439 | if eq get wdp i 47 |
| 1440 | wgmk1 i |
| 1441 | end |
| 1442 | i = add i 1 |
| 1443 | end |
| 1444 | if gt n 0 |
| 1445 | wgmk1 n |
| 1446 | end |
| 1447 | end |
| 1448 | |
| 1449 | note fork; the child changes to slot cw (WGNO: stay), takes fi/fo/fe as 0/1/2 when not negative and |
| 1450 | note runs the packed list wdk with an empty environment. Returns the pid. |
| 1451 | fn wgspawn fi int fo int fe int cw ulong to long |
| 1452 | pn = wdkfin |
| 1453 | pid = fork |
| 1454 | if lt pid 0 |
| 1455 | wgdie wgthost 70 |
| 1456 | end |
| 1457 | if eq pid 0 |
| 1458 | if ne cw WGNO |
| 1459 | o = wgso cw |
| 1460 | r = chdir wga o wgsn cw |
| 1461 | if ne r 0 |
| 1462 | exit 127 |
| 1463 | end |
| 1464 | end |
| 1465 | if ge fi 0 |
| 1466 | d0 = dupfd fi 0 0 |
| 1467 | end |
| 1468 | if ge fo 0 |
| 1469 | d1 = dupfd fo 1 0 |
| 1470 | end |
| 1471 | if ge fe 0 |
| 1472 | d2 = dupfd fe 2 0 |
| 1473 | end |
| 1474 | x = execprog wdk 0 pn |
| 1475 | exit 127 |
| 1476 | end |
| 1477 | ret pid |
| 1478 | end |
| 1479 | |
| 1480 | fn wgstat to long |
| 1481 | s = or ulong get wdst 0 shl ulong get wdst 1 8 |
| 1482 | if eq and s 127 0 |
| 1483 | ret long and shr s 8 255 |
| 1484 | end |
| 1485 | ret neg long and s 127 |
| 1486 | end |
| 1487 | |
| 1488 | note wait for pid at most ns nanoseconds: its returncode (minus the signal), or WGTMO after a kill |
| 1489 | fn wgreap pid long ns long to long |
| 1490 | dl = add monons ns |
| 1491 | while true bound 999 |
| 1492 | while true bound 999999 |
| 1493 | r = waitpid int pid wdst 0 4 1 |
| 1494 | if eq r pid |
| 1495 | ret wgstat |
| 1496 | end |
| 1497 | if eq r 0 |
| 1498 | if gt monons dl |
| 1499 | k = killpid int pid 9 |
| 1500 | r2 = waitpid int pid wdst 0 4 0 |
| 1501 | while eq r2 -4 bound 1000 |
| 1502 | r2 = waitpid int pid wdst 0 4 0 |
| 1503 | end |
| 1504 | ret WGTMO |
| 1505 | end |
| 1506 | z = sleepns 200000 |
| 1507 | else |
| 1508 | if ne r -4 |
| 1509 | wgdie wgthost 70 |
| 1510 | end |
| 1511 | end |
| 1512 | end |
| 1513 | end |
| 1514 | ret WGTMO |
| 1515 | end |
| 1516 | |
| 1517 | fn wgopen to int |
| 1518 | fd = wdopen 0 0 |
| 1519 | if lt fd 0 |
| 1520 | wgdiep wgtfile 71 |
| 1521 | end |
| 1522 | ret fd |
| 1523 | end |
| 1524 | |
| 1525 | fn wgdevn to int |
| 1526 | wdpclr |
| 1527 | wdpt wgtnull |
| 1528 | fd = wdopen 1 0 |
| 1529 | if lt fd 0 |
| 1530 | wgdiep wgtfile 71 |
| 1531 | end |
| 1532 | ret fd |
| 1533 | end |
| 1534 | |
| 1535 | note omc with stdin from file OUT/build/si, stdout to OUT/build/so, stderr to OUT/build/se (fresh |
| 1536 | note files); 10 s. Returns the returncode or WGTMO. |
| 1537 | text wgtbld "build/" |
| 1538 | fn wgomc si view uchar * so view uchar * se view uchar * to long |
| 1539 | wgpout wgtbld |
| 1540 | wdpt si |
| 1541 | fi = wgopen |
| 1542 | wgpout wgtbld |
| 1543 | wdpt so |
| 1544 | fo = wgcreat false |
| 1545 | wgpout wgtbld |
| 1546 | wdpt se |
| 1547 | fe = wgcreat false |
| 1548 | wdkclr |
| 1549 | wdkt wgtomc |
| 1550 | pid = wgspawn fi fo fe WGNO |
| 1551 | r = wgreap pid 10000000000 |
| 1552 | c1 = fclose fi |
| 1553 | c2 = fclose fo |
| 1554 | c3 = fclose fe |
| 1555 | ret r |
| 1556 | end |
| 1557 | |
| 1558 | note load OUT/build/t onto the arena: offset in wgr 5, length in wgr 6 |
| 1559 | fn wgbload t view uchar * to void |
| 1560 | wgpout wgtbld |
| 1561 | wdpt t |
| 1562 | o = wgload |
| 1563 | put wgr 5 o |
| 1564 | put wgr 6 sub get wgan 0 o |
| 1565 | end |
| 1566 | |
| 1567 | note run the program named by slot SPL in OUT/fixtures, stdout to OUT/build/t, stderr /dev/null, 2 s |
| 1568 | fn wgrunx t view uchar * to long |
| 1569 | fe = wgdevn |
| 1570 | wgpout wgtbld |
| 1571 | wdpt t |
| 1572 | fo = wgcreat false |
| 1573 | wdkclr |
| 1574 | wdpclr |
| 1575 | wgpsl SPL |
| 1576 | wdkp |
| 1577 | pid = wgspawn -1 fo fe SFIX |
| 1578 | r = wgreap pid 2000000000 |
| 1579 | c1 = fclose fo |
| 1580 | c2 = fclose fe |
| 1581 | ret r |
| 1582 | end |
| 1583 | |
| 1584 | note ---------------------------------------------------------------- checker.py / check_behavior.py / repair.check_answer |
| 1585 | |
| 1586 | text wgtrcp "receipts/" |
| 1587 | text wgtdom ".om" |
| 1588 | text wgtomo "omc.out" |
| 1589 | text wgtome "omc.err" |
| 1590 | text wgtrun "run.out" |
| 1591 | |
| 1592 | note rename OUT/build/f to the path in slot SPL and chmod it 0700 |
| 1593 | fn wgplace f view uchar * to void |
| 1594 | wdkclr |
| 1595 | wgpout wgtbld |
| 1596 | wdpt f |
| 1597 | wdkp |
| 1598 | wdpclr |
| 1599 | wgpsl SPL |
| 1600 | wdkp |
| 1601 | wdrename |
| 1602 | wdpclr |
| 1603 | wgpsl SPL |
| 1604 | r = chmod wdp 0 get wdpn 0 448 |
| 1605 | if ne r 0 |
| 1606 | wgdiep wgtfile 71 |
| 1607 | end |
| 1608 | end |
| 1609 | |
| 1610 | note checker.execute(text, expected, stdout, label=slot SCL); compile_rc and run_rc into wgx 0, 1 |
| 1611 | fn wgexec o ulong n ulong ex long so ulong sn ulong to bool |
| 1612 | put wgx 0 WGABS |
| 1613 | put wgx 1 WGABS |
| 1614 | if eq n 0 |
| 1615 | ret false |
| 1616 | end |
| 1617 | if not wglines o n 0 |
| 1618 | ret false |
| 1619 | end |
| 1620 | wgpout wgtrcp |
| 1621 | wgpsl SCL |
| 1622 | wdpt wgtdom |
| 1623 | fd = wgcreat false |
| 1624 | wgwr fd o n |
| 1625 | wgwrt fd wgtnl |
| 1626 | c = fclose fd |
| 1627 | wgpout wgtrcp |
| 1628 | wgpsl SCL |
| 1629 | wdpt wgtdom |
| 1630 | wgsetp SPL |
| 1631 | r = wgomcp |
| 1632 | if eq r WGTMO |
| 1633 | ret false |
| 1634 | end |
| 1635 | if ne r 0 |
| 1636 | put wgx 0 r |
| 1637 | ret false |
| 1638 | end |
| 1639 | wgpout wgtbld |
| 1640 | wgpsl SCL |
| 1641 | wgsetp SPL |
| 1642 | wgplace wgtomo |
| 1643 | q = wgrunx wgtrun |
| 1644 | if eq q WGTMO |
| 1645 | ret false |
| 1646 | end |
| 1647 | put wgx 0 0 |
| 1648 | put wgx 1 q |
| 1649 | wgbload wgtrun |
| 1650 | wgasc get wgr 5 get wgr 6 |
| 1651 | if ne q ex |
| 1652 | ret false |
| 1653 | end |
| 1654 | ret wgeq2 get wgr 5 get wgr 6 so sn |
| 1655 | end |
| 1656 | |
| 1657 | note omc with stdin from the file in slot SPL, stdout OUT/build/omc.out, stderr OUT/build/omc.err |
| 1658 | fn wgomcp to long |
| 1659 | wdpclr |
| 1660 | wgpsl SPL |
| 1661 | fi = wgopen |
| 1662 | wgpout wgtbld |
| 1663 | wdpt wgtomo |
| 1664 | fo = wgcreat false |
| 1665 | wgpout wgtbld |
| 1666 | wdpt wgtome |
| 1667 | fe = wgcreat false |
| 1668 | wdkclr |
| 1669 | wdkt wgtomc |
| 1670 | pid = wgspawn fi fo fe WGNO |
| 1671 | r = wgreap pid 10000000000 |
| 1672 | c1 = fclose fi |
| 1673 | c2 = fclose fo |
| 1674 | c3 = fclose fe |
| 1675 | ret r |
| 1676 | end |
| 1677 | |
| 1678 | text wgtxex "expected_exit" |
| 1679 | text wgtxso "expected_stdout" |
| 1680 | text wgtkind "kind" |
| 1681 | text wgthelp "helper" |
| 1682 | text wgtloop "loop" |
| 1683 | text wgtinc "increment" |
| 1684 | text wgtans "answer" |
| 1685 | text wgtfinc "fn inc x int to int" |
| 1686 | text wgtfmain "fn main to int" |
| 1687 | text wgtrinc "ret inc int " |
| 1688 | text wgtarg "-arg" |
| 1689 | text wgtmend "fn main to int\nret inc int " |
| 1690 | text wgtend "\nend" |
| 1691 | |
| 1692 | note checker.check(raw, row, label=slot SCB); compile_rc/run_rc into wgxr 0, 1 |
| 1693 | fn wgcheck ro ulong rn ulong row ulong to bool |
| 1694 | put wgxr 0 WGABS |
| 1695 | put wgxr 1 WGABS |
| 1696 | wgtext ro rn |
| 1697 | tx = get wgr 0 |
| 1698 | tn = get wgr 1 |
| 1699 | xe = wgjget row wgtxex |
| 1700 | if eq xe 0 |
| 1701 | ret wgprior tx tn row |
| 1702 | end |
| 1703 | hp = wgjis row wgtkind wgthelp |
| 1704 | if hp |
| 1705 | if or ne wgcntt tx tn wgtfinc 1 ne wgcntt tx tn wgtfmain 1 |
| 1706 | ret false |
| 1707 | end |
| 1708 | if eq wgfindt tx tn wgtrinc WGNO |
| 1709 | ret false |
| 1710 | end |
| 1711 | end |
| 1712 | if wgjis row wgtkind wgtloop |
| 1713 | if not wglines tx tn 2 |
| 1714 | ret false |
| 1715 | end |
| 1716 | end |
| 1717 | ex = wgjint xe |
| 1718 | so = ulong 0 |
| 1719 | sn = ulong 0 |
| 1720 | xs = wgjget row wgtxso |
| 1721 | if ne xs 0 |
| 1722 | if ne get wgjt xs 5 |
| 1723 | wgdie wgtshp 79 |
| 1724 | end |
| 1725 | so = get wgjo xs |
| 1726 | sn = get wgjl xs |
| 1727 | end |
| 1728 | o = get wgan 0 |
| 1729 | wgasl SCB |
| 1730 | wgsetf SCL o |
| 1731 | ok = wgexec tx tn ex so sn |
| 1732 | put wgxr 0 get wgx 0 |
| 1733 | put wgxr 1 get wgx 1 |
| 1734 | if and ok hp |
| 1735 | ret wghelp tx tn row |
| 1736 | end |
| 1737 | ret ok |
| 1738 | end |
| 1739 | |
| 1740 | note the three additional inputs of a helper row (every one runs, as the list comprehension does) |
| 1741 | fn wghelp tx ulong tn ulong row ulong to bool |
| 1742 | inc = wgjint wgjget row wgtinc |
| 1743 | k = wgfindt tx tn wgtfmain |
| 1744 | alp = true |
| 1745 | a = long 0 |
| 1746 | while le a 10 bound 4 |
| 1747 | po = get wgan 0 |
| 1748 | wgacp tx k |
| 1749 | wgat wgtmend |
| 1750 | wgadl a |
| 1751 | wgat wgtend |
| 1752 | pn = sub get wgan 0 po |
| 1753 | o = get wgan 0 |
| 1754 | wgasl SCB |
| 1755 | wgat wgtarg |
| 1756 | wgadl a |
| 1757 | wgsetf SCL o |
| 1758 | if not wgexec po pn add a inc 0 0 |
| 1759 | alp = false |
| 1760 | end |
| 1761 | a = add a 5 |
| 1762 | end |
| 1763 | ret alp |
| 1764 | end |
| 1765 | |
| 1766 | text wgtread "read" |
| 1767 | text wgtlist "list" |
| 1768 | text wgtchk "check" |
| 1769 | |
| 1770 | note check_behavior.check for rows without expected_exit |
| 1771 | fn wgprior tx ulong tn ulong row ulong to bool |
| 1772 | if or or wgjis row wgtkind wgtread wgjis row wgtkind wgtlist wgjis row wgtkind wgtchk |
| 1773 | ret wgdisp tx tn row |
| 1774 | end |
| 1775 | wgjsget row wgtans |
| 1776 | ret wgeq2 tx tn get wgr 3 get wgr 4 |
| 1777 | end |
| 1778 | |
| 1779 | text wgttool "tool" |
| 1780 | text wgtpath "path" |
| 1781 | text wgtrdf "read_file" |
| 1782 | text wgtlsf "list_files" |
| 1783 | text wgtomck "omega_check" |
| 1784 | text wgtfixc "fixture contents\n" |
| 1785 | text wgtone "/one.txt" |
| 1786 | text wgtonev "one" |
| 1787 | text wgtprog "fn main to int\nret 0\nend\n" |
| 1788 | text wgtfix "fixtures" |
| 1789 | |
| 1790 | note check_behavior.dispatch, including its fixture side effects |
| 1791 | fn wgdisp tx ulong tn ulong row ulong to bool |
| 1792 | mk = get wgjn 0 |
| 1793 | d = wgjparse tx tn |
| 1794 | if eq d WGNO |
| 1795 | ret false |
| 1796 | end |
| 1797 | wgjsget row wgtans |
| 1798 | x = wgjparse get wgr 3 get wgr 4 |
| 1799 | if eq x WGNO |
| 1800 | wgdie wgtnoj 80 |
| 1801 | end |
| 1802 | wgjflat x |
| 1803 | if not wgjeqx d x |
| 1804 | put wgjn 0 mk |
| 1805 | ret false |
| 1806 | end |
| 1807 | wgjsget x wgtpath |
| 1808 | po = get wgr 3 |
| 1809 | pn = get wgr 4 |
| 1810 | wdpclr |
| 1811 | if or eq pn 0 ne get wga po 47 |
| 1812 | wgpsl SOUT |
| 1813 | wdpc 47 |
| 1814 | wdpt wgtfix |
| 1815 | wdpc 47 |
| 1816 | end |
| 1817 | wgpar po pn |
| 1818 | wgsetp SPL |
| 1819 | sl = WGNO |
| 1820 | i = ulong 0 |
| 1821 | while lt i get wdpn 0 bound 4096 |
| 1822 | if eq get wdp i 47 |
| 1823 | sl = i |
| 1824 | end |
| 1825 | i = add i 1 |
| 1826 | end |
| 1827 | if ne sl WGNO |
| 1828 | put wdpn 0 sl |
| 1829 | wgmkp |
| 1830 | end |
| 1831 | if wgjis x wgttool wgtrdf |
| 1832 | wdpclr |
| 1833 | wgpsl SPL |
| 1834 | fd = wgcreat false |
| 1835 | wgwrt fd wgtfixc |
| 1836 | c = fclose fd |
| 1837 | o = wgload |
| 1838 | put wgjn 0 mk |
| 1839 | ret true |
| 1840 | end |
| 1841 | if wgjis x wgttool wgtlsf |
| 1842 | wdpclr |
| 1843 | wgpsl SPL |
| 1844 | wgmk1 get wdpn 0 |
| 1845 | wdpt wgtone |
| 1846 | fd2 = wgcreat false |
| 1847 | wgwrt fd2 wgtonev |
| 1848 | c2 = fclose fd2 |
| 1849 | put wgjn 0 mk |
| 1850 | ret true |
| 1851 | end |
| 1852 | if wgjis x wgttool wgtomck |
| 1853 | wdpclr |
| 1854 | wgpsl SPL |
| 1855 | fd3 = wgcreat false |
| 1856 | wgwrt fd3 wgtprog |
| 1857 | c3 = fclose fd3 |
| 1858 | r = wgomcp |
| 1859 | if eq r WGTMO |
| 1860 | wgdie wgtcmdt 74 |
| 1861 | end |
| 1862 | if ne r 0 |
| 1863 | wgdie wgtcmdf 73 |
| 1864 | end |
| 1865 | put wgjn 0 mk |
| 1866 | ret true |
| 1867 | end |
| 1868 | wgdie wgtshp 79 |
| 1869 | ret false |
| 1870 | end |
| 1871 | |
| 1872 | note repair.check_answer |
| 1873 | fn wgfirst ro ulong rn ulong row ulong to bool |
| 1874 | wgtext ro rn |
| 1875 | tx = get wgr 0 |
| 1876 | tn = get wgr 1 |
| 1877 | mk = get wgjn 0 |
| 1878 | wgjsget row wgtans |
| 1879 | ao = get wgr 3 |
| 1880 | an = get wgr 4 |
| 1881 | d = wgjparse tx tn |
| 1882 | if eq d WGNO |
| 1883 | ret wgeq2 tx tn ao an |
| 1884 | end |
| 1885 | x = wgjparse ao an |
| 1886 | if eq x WGNO |
| 1887 | ret wgeq2 tx tn ao an |
| 1888 | end |
| 1889 | wgjflat x |
| 1890 | r = wgjeqx d x |
| 1891 | put wgjn 0 mk |
| 1892 | ret r |
| 1893 | end |
| 1894 | text wgy00 "Repair this Omega file and verify it." |
| 1895 | text wgy01 "Use tools to fix this Omega program, then test it." |
| 1896 | text wgy02 "Check this Omega file, correct any fault and confirm the result." |
| 1897 | text wgy03 "Please get this Omega file working according to its goal and check your work." |
| 1898 | text wgy04 "Investigate this Omega file and make its behavior match the goal." |
| 1899 | text wgy05 "Diagnose this Omega file, repair it as needed, and verify the result." |
| 1900 | text wgy06 "Repair the calculation in this Omega file and verify the result." |
| 1901 | text wgy07 "Find and repair the mistake in this Omega file, then confirm its behavior." |
| 1902 | text wgy08 "Make this Omega file satisfy its stated goal and verify the repaired result." |
| 1903 | text wgy09 "Fix this Omega file." |
| 1904 | text wgy10 "Check and repair the Omega program." |
| 1905 | text wgy11 "Make the program match its goal and test it." |
| 1906 | text wgy12 "Use tools to repair the file and check it." |
| 1907 | text wgy13 "Find the wrong calculation, fix it, and test it." |
| 1908 | text wgy14 "Inspect this program and fix the error." |
| 1909 | text wgy15 "Read the file, check it, repair it, and test again." |
| 1910 | text wgy16 "Please correct the Omega calculation and verify it." |
| 1911 | text wgy17 "Repair this file to meet the stated goal." |
| 1912 | text wgy18 "Work through this Omega repair and check the result." |
| 1913 | text wgy19 "Check this Omega file, find the error, repair it and verify the result." |
| 1914 | text wgy20 "Please inspect this Omega program to repair the calculation and verify the result." |
| 1915 | text wgy21 "Use the goal to fix this Omega file and verify the changes." |
| 1916 | text wgy22 "Please repair this Omega program to do what the goal asks." |
| 1917 | text wgy23 "Get this Omega file to match the goal, then check the result." |
| 1918 | text wgy24 "Please carefully repair the calculation using tools and confirm that the tests pass." |
| 1919 | text wgy25 "Please carefully examine this Omega file and repair any calculation that does not match its goal." |
| 1920 | text wgy26 "Find the incorrect behavior in this Omega file, fix it, and test the result." |
| 1921 | text wgy27 "Inspect and repair this Omega file, then verify it." |
| 1922 | text wgy28 "Correct this Omega program according to its goal." |
| 1923 | text wgy29 "Fix the error in this Omega program and check the result." |
| 1924 | text wgy30 "Check this file and repair it to meet its goal." |
| 1925 | text wgy31 "Please fix this program to match its goal." |
| 1926 | text wgy32 "Correct the calculation in this Omega file." |
| 1927 | text wgy33 "Read this program and repair its calculation." |
| 1928 | text wgy34 "Please check the code and fix the mistake." |
| 1929 | text wgy35 "Repair the program according to the stated goal." |
| 1930 | text wgy36 "Use the goal to correct this Omega calculation." |
| 1931 | text wgy37 "Fix the calculation and test the corrected program." |
| 1932 | text wgy38 "Please inspect the file and correct the error." |
| 1933 | text wgy39 "Check the calculation, make the repair, and verify it." |
| 1934 | text wgy40 "Make this file behave as the goal describes." |
| 1935 | text wgy41 "Please correct this program and check your work." |
| 1936 | text wgy42 "Repair this calculation, then confirm the result." |
| 1937 | text wgy43 "Repair this file and confirm it meets the goal." |
| 1938 | text wgy44 "Check the Omega program and correct its calculation." |
| 1939 | text wgy45 "Inspect this file, fix its calculation, and verify it." |
| 1940 | text wgy46 "Make this Omega program meet the goal, then test it." |
| 1941 | text wgy47 "Repair the file and verify its goal." |
| 1942 | text wgy48 "Check the code, repair its fault, and test it." |
| 1943 | text wgy49 "Fix the error in this file and confirm its goal." |
| 1944 | text wgy50 "Inspect the code and repair it to satisfy the goal." |
| 1945 | |
| 1946 | note STYLES[i] onto the arena (repair.STYLES, 51 entries, copied mechanically) |
| 1947 | fn wgsty i ulong to void |
| 1948 | if eq i 0 |
| 1949 | wgat wgy00 |
| 1950 | ret |
| 1951 | end |
| 1952 | if eq i 1 |
| 1953 | wgat wgy01 |
| 1954 | ret |
| 1955 | end |
| 1956 | if eq i 2 |
| 1957 | wgat wgy02 |
| 1958 | ret |
| 1959 | end |
| 1960 | if eq i 3 |
| 1961 | wgat wgy03 |
| 1962 | ret |
| 1963 | end |
| 1964 | if eq i 4 |
| 1965 | wgat wgy04 |
| 1966 | ret |
| 1967 | end |
| 1968 | if eq i 5 |
| 1969 | wgat wgy05 |
| 1970 | ret |
| 1971 | end |
| 1972 | if eq i 6 |
| 1973 | wgat wgy06 |
| 1974 | ret |
| 1975 | end |
| 1976 | if eq i 7 |
| 1977 | wgat wgy07 |
| 1978 | ret |
| 1979 | end |
| 1980 | if eq i 8 |
| 1981 | wgat wgy08 |
| 1982 | ret |
| 1983 | end |
| 1984 | if eq i 9 |
| 1985 | wgat wgy09 |
| 1986 | ret |
| 1987 | end |
| 1988 | if eq i 10 |
| 1989 | wgat wgy10 |
| 1990 | ret |
| 1991 | end |
| 1992 | if eq i 11 |
| 1993 | wgat wgy11 |
| 1994 | ret |
| 1995 | end |
| 1996 | if eq i 12 |
| 1997 | wgat wgy12 |
| 1998 | ret |
| 1999 | end |
| 2000 | if eq i 13 |
| 2001 | wgat wgy13 |
| 2002 | ret |
| 2003 | end |
| 2004 | if eq i 14 |
| 2005 | wgat wgy14 |
| 2006 | ret |
| 2007 | end |
| 2008 | if eq i 15 |
| 2009 | wgat wgy15 |
| 2010 | ret |
| 2011 | end |
| 2012 | if eq i 16 |
| 2013 | wgat wgy16 |
| 2014 | ret |
| 2015 | end |
| 2016 | if eq i 17 |
| 2017 | wgat wgy17 |
| 2018 | ret |
| 2019 | end |
| 2020 | if eq i 18 |
| 2021 | wgat wgy18 |
| 2022 | ret |
| 2023 | end |
| 2024 | if eq i 19 |
| 2025 | wgat wgy19 |
| 2026 | ret |
| 2027 | end |
| 2028 | if eq i 20 |
| 2029 | wgat wgy20 |
| 2030 | ret |
| 2031 | end |
| 2032 | if eq i 21 |
| 2033 | wgat wgy21 |
| 2034 | ret |
| 2035 | end |
| 2036 | if eq i 22 |
| 2037 | wgat wgy22 |
| 2038 | ret |
| 2039 | end |
| 2040 | if eq i 23 |
| 2041 | wgat wgy23 |
| 2042 | ret |
| 2043 | end |
| 2044 | if eq i 24 |
| 2045 | wgat wgy24 |
| 2046 | ret |
| 2047 | end |
| 2048 | if eq i 25 |
| 2049 | wgat wgy25 |
| 2050 | ret |
| 2051 | end |
| 2052 | if eq i 26 |
| 2053 | wgat wgy26 |
| 2054 | ret |
| 2055 | end |
| 2056 | if eq i 27 |
| 2057 | wgat wgy27 |
| 2058 | ret |
| 2059 | end |
| 2060 | if eq i 28 |
| 2061 | wgat wgy28 |
| 2062 | ret |
| 2063 | end |
| 2064 | if eq i 29 |
| 2065 | wgat wgy29 |
| 2066 | ret |
| 2067 | end |
| 2068 | if eq i 30 |
| 2069 | wgat wgy30 |
| 2070 | ret |
| 2071 | end |
| 2072 | if eq i 31 |
| 2073 | wgat wgy31 |
| 2074 | ret |
| 2075 | end |
| 2076 | if eq i 32 |
| 2077 | wgat wgy32 |
| 2078 | ret |
| 2079 | end |
| 2080 | if eq i 33 |
| 2081 | wgat wgy33 |
| 2082 | ret |
| 2083 | end |
| 2084 | if eq i 34 |
| 2085 | wgat wgy34 |
| 2086 | ret |
| 2087 | end |
| 2088 | if eq i 35 |
| 2089 | wgat wgy35 |
| 2090 | ret |
| 2091 | end |
| 2092 | if eq i 36 |
| 2093 | wgat wgy36 |
| 2094 | ret |
| 2095 | end |
| 2096 | if eq i 37 |
| 2097 | wgat wgy37 |
| 2098 | ret |
| 2099 | end |
| 2100 | if eq i 38 |
| 2101 | wgat wgy38 |
| 2102 | ret |
| 2103 | end |
| 2104 | if eq i 39 |
| 2105 | wgat wgy39 |
| 2106 | ret |
| 2107 | end |
| 2108 | if eq i 40 |
| 2109 | wgat wgy40 |
| 2110 | ret |
| 2111 | end |
| 2112 | if eq i 41 |
| 2113 | wgat wgy41 |
| 2114 | ret |
| 2115 | end |
| 2116 | if eq i 42 |
| 2117 | wgat wgy42 |
| 2118 | ret |
| 2119 | end |
| 2120 | if eq i 43 |
| 2121 | wgat wgy43 |
| 2122 | ret |
| 2123 | end |
| 2124 | if eq i 44 |
| 2125 | wgat wgy44 |
| 2126 | ret |
| 2127 | end |
| 2128 | if eq i 45 |
| 2129 | wgat wgy45 |
| 2130 | ret |
| 2131 | end |
| 2132 | if eq i 46 |
| 2133 | wgat wgy46 |
| 2134 | ret |
| 2135 | end |
| 2136 | if eq i 47 |
| 2137 | wgat wgy47 |
| 2138 | ret |
| 2139 | end |
| 2140 | if eq i 48 |
| 2141 | wgat wgy48 |
| 2142 | ret |
| 2143 | end |
| 2144 | if eq i 49 |
| 2145 | wgat wgy49 |
| 2146 | ret |
| 2147 | end |
| 2148 | if eq i 50 |
| 2149 | wgat wgy50 |
| 2150 | ret |
| 2151 | end |
| 2152 | wgdie wgtshp 79 |
| 2153 | end |
| 2154 | |
| 2155 | fn wgb b bool to uchar |
| 2156 | if b |
| 2157 | ret 1 |
| 2158 | end |
| 2159 | ret 0 |
| 2160 | end |
| 2161 | |
| 2162 | note ---------------------------------------------------------------- repair.jobs_run |
| 2163 | note job states: 1 unread, 2 read, 3 missing, 4 checked, 5 failed, 6 edited |
| 2164 | |
| 2165 | text wgts1 "unread" |
| 2166 | text wgts2 "read" |
| 2167 | text wgts3 "missing" |
| 2168 | text wgts4 "checked" |
| 2169 | text wgts5 "failed" |
| 2170 | text wgts6 "edited" |
| 2171 | |
| 2172 | fn wgstn s ulong to void |
| 2173 | if eq s 1 |
| 2174 | wgat wgts1 |
| 2175 | end |
| 2176 | if eq s 2 |
| 2177 | wgat wgts2 |
| 2178 | end |
| 2179 | if eq s 3 |
| 2180 | wgat wgts3 |
| 2181 | end |
| 2182 | if eq s 4 |
| 2183 | wgat wgts4 |
| 2184 | end |
| 2185 | if eq s 5 |
| 2186 | wgat wgts5 |
| 2187 | end |
| 2188 | if eq s 6 |
| 2189 | wgat wgts6 |
| 2190 | end |
| 2191 | end |
| 2192 | |
| 2193 | note state name of s equals the arena text (o, n) |
| 2194 | fn wgsteq s ulong o ulong n ulong to bool |
| 2195 | m = get wgan 0 |
| 2196 | wgstn s |
| 2197 | r = wgeq2 m sub get wgan 0 m o n |
| 2198 | put wgan 0 m |
| 2199 | ret r |
| 2200 | end |
| 2201 | |
| 2202 | text wgtid "id" |
| 2203 | text wgtstyl "style" |
| 2204 | text wgtfault "fault" |
| 2205 | text wgtbrok "broken" |
| 2206 | text wgtka "a" |
| 2207 | text wgtkk "k" |
| 2208 | text wgtkn "n" |
| 2209 | text wgtadd "add" |
| 2210 | text wgtmul "mul" |
| 2211 | |
| 2212 | fn wgjv ji ulong t view uchar * to long |
| 2213 | ret wgjint wgjget get wgdr ji t |
| 2214 | end |
| 2215 | |
| 2216 | note OUT/fixtures/JL/id/program.om into wdp (dir only when pf is false) |
| 2217 | text wgtfixs "/fixtures/" |
| 2218 | text wgtprg "/program.om" |
| 2219 | fn wgpjob ji ulong pf bool to void |
| 2220 | wdpclr |
| 2221 | wgpsl SOUT |
| 2222 | wdpt wgtfixs |
| 2223 | wgpsl SJL |
| 2224 | wdpc 47 |
| 2225 | wgjsget get wgdr ji wgtid |
| 2226 | wgpar get wgr 3 get wgr 4 |
| 2227 | if pf |
| 2228 | wdpt wgtprg |
| 2229 | end |
| 2230 | end |
| 2231 | |
| 2232 | text wgtg1 "calc starts with x and adds " |
| 2233 | text wgtg2 " exactly " |
| 2234 | text wgtg3 " times in a for loop. main calls calc with " |
| 2235 | text wgtg4 "calc returns x " |
| 2236 | text wgtplus "plus " |
| 2237 | text wgttimes "times " |
| 2238 | text wgtg5 ". main calls calc with " |
| 2239 | text wgtp1 "Task: " |
| 2240 | text wgtp2 "\nFile: " |
| 2241 | text wgtp3 "\nGoal: " |
| 2242 | text wgtp4 "\nState: " |
| 2243 | text wgtp5 "Source:\n" |
| 2244 | text wgtp6 "Tool result: " |
| 2245 | text wgtp7 "Answer:\n" |
| 2246 | text wgtdot "." |
| 2247 | |
| 2248 | fn wggoal ji ulong to void |
| 2249 | j = get wgdr ji |
| 2250 | if wgjis j wgtkind wgtloop |
| 2251 | wgat wgtg1 |
| 2252 | wgadl wgjv ji wgtkk |
| 2253 | wgat wgtg2 |
| 2254 | wgadl wgjv ji wgtkn |
| 2255 | wgat wgtg3 |
| 2256 | wgadl wgjv ji wgtka |
| 2257 | wgat wgtdot |
| 2258 | ret |
| 2259 | end |
| 2260 | wgat wgtg4 |
| 2261 | if wgjis j wgtkind wgtadd |
| 2262 | wgat wgtplus |
| 2263 | else |
| 2264 | wgat wgttimes |
| 2265 | end |
| 2266 | wgadl wgjv ji wgtkk |
| 2267 | wgat wgtg5 |
| 2268 | wgadl wgjv ji wgtka |
| 2269 | wgat wgtdot |
| 2270 | end |
| 2271 | |
| 2272 | note repair.prompt for job ji in its current state, onto the arena; returns the offset |
| 2273 | fn wgprm ji ulong to ulong |
| 2274 | j = get wgdr ji |
| 2275 | o = get wgan 0 |
| 2276 | wgat wgtp1 |
| 2277 | st = wgjv ji wgtstyl |
| 2278 | if or lt st 0 gt st 50 |
| 2279 | wgdie wgtshp 79 |
| 2280 | end |
| 2281 | wgsty ulong st |
| 2282 | wgat wgtp2 |
| 2283 | wgjsget j wgtpath |
| 2284 | wgacp get wgr 3 get wgr 4 |
| 2285 | wgat wgtp3 |
| 2286 | wggoal ji |
| 2287 | wgat wgtp4 |
| 2288 | wgstn ulong get wgjst ji |
| 2289 | wgat wgtnl |
| 2290 | if gt get wgjsn ji 0 |
| 2291 | wgat wgtp5 |
| 2292 | wgacp get wgjso ji get wgjsn ji |
| 2293 | end |
| 2294 | if gt get wgjon ji 0 |
| 2295 | wgat wgtp6 |
| 2296 | wgacp get wgjoo ji get wgjon ji |
| 2297 | wgat wgtnl |
| 2298 | end |
| 2299 | wgat wgtp7 |
| 2300 | ret o |
| 2301 | end |
| 2302 | |
| 2303 | fn wgobs ji ulong t view uchar * to void |
| 2304 | o = get wgan 0 |
| 2305 | wgat t |
| 2306 | put wgjoo ji o |
| 2307 | put wgjon ji len t |
| 2308 | end |
| 2309 | |
| 2310 | text wgtrok "Read succeeded." |
| 2311 | text wgtfnf "File not found." |
| 2312 | text wgttp "Tests passed." |
| 2313 | text wgtes "Edit saved." |
| 2314 | text wgtref "Refused unsupported source." |
| 2315 | text wgtrfm "Required functions missing." |
| 2316 | text wgtmpi "main must preserve the requested input." |
| 2317 | text wgtrlm "Required loop missing." |
| 2318 | text wgtfci "fn calc x int to int" |
| 2319 | text wgtrci "ret calc int " |
| 2320 | text wgtfiu "for i ulong " |
| 2321 | text wgttf1 "Test failed: calc(" |
| 2322 | text wgttf2 ") expected " |
| 2323 | text wgttf3 ", got " |
| 2324 | text wgtcto "ct.om" |
| 2325 | text wgtcte "ct.err" |
| 2326 | text wgtctr "ct.run" |
| 2327 | text wgtchk2 "check-" |
| 2328 | |
| 2329 | note Path.read_text() of the file named by wdp: ASCII (exit 72 otherwise), universal newlines |
| 2330 | fn wgrtext to ulong |
| 2331 | o = wgload |
| 2332 | n = sub get wgan 0 o |
| 2333 | wgasc o n |
| 2334 | i = ulong 0 |
| 2335 | w = ulong 0 |
| 2336 | while lt i n bound 999999 |
| 2337 | c = get wga add o i |
| 2338 | if eq c 13 |
| 2339 | c = 10 |
| 2340 | if lt add i 1 n |
| 2341 | if eq get wga add o add i 1 10 |
| 2342 | i = add i 1 |
| 2343 | end |
| 2344 | end |
| 2345 | end |
| 2346 | put wga add o w c |
| 2347 | w = add w 1 |
| 2348 | i = add i 1 |
| 2349 | end |
| 2350 | put wgan 0 add o w |
| 2351 | ret o |
| 2352 | end |
| 2353 | |
| 2354 | note the main-preserve check: the stripped lines starting with "ret calc int " are exactly one, "ret calc int {a}" |
| 2355 | fn wgmainok so ulong sn ulong a long to bool |
| 2356 | wgstrip so sn |
| 2357 | p = get wgr 0 |
| 2358 | e = add p get wgr 1 |
| 2359 | want = get wgan 0 |
| 2360 | wgat wgtrci |
| 2361 | wgadl a |
| 2362 | wn = sub get wgan 0 want |
| 2363 | cnt = ulong 0 |
| 2364 | ok = false |
| 2365 | while lt p e bound 999999 |
| 2366 | q = wgeol p e |
| 2367 | nx = get wgr 2 |
| 2368 | if wgsw p sub q p wgtrci |
| 2369 | cnt = add cnt 1 |
| 2370 | ok = wgeq2 p sub q p want wn |
| 2371 | end |
| 2372 | p = nx |
| 2373 | end |
| 2374 | put wgan 0 want |
| 2375 | ret and eq cnt 1 ok |
| 2376 | end |
| 2377 | |
| 2378 | note expected(j, x) |
| 2379 | fn wgwant ji ulong x long to long |
| 2380 | j = get wgdr ji |
| 2381 | k = wgjv ji wgtkk |
| 2382 | if wgjis j wgtkind wgtadd |
| 2383 | ret add x k |
| 2384 | end |
| 2385 | if wgjis j wgtkind wgtmul |
| 2386 | ret mul x k |
| 2387 | end |
| 2388 | ret add x mul k wgjv ji wgtkn |
| 2389 | end |
| 2390 | |
| 2391 | note the stripped lines of [so, so + sn) all match repair.PATTERNS |
| 2392 | fn wgrgram so ulong sn ulong to bool |
| 2393 | wgstrip so sn |
| 2394 | ret wglines get wgr 0 get wgr 1 1 |
| 2395 | end |
| 2396 | |
| 2397 | note observation = stripped omc stderr (OUT/build/ct.err); ASCII or exit 72 |
| 2398 | fn wgcterr ji ulong to void |
| 2399 | wgbload wgtcte |
| 2400 | wgasc get wgr 5 get wgr 6 |
| 2401 | wgstrip get wgr 5 get wgr 6 |
| 2402 | put wgjoo ji get wgr 0 |
| 2403 | put wgjon ji get wgr 1 |
| 2404 | end |
| 2405 | |
| 2406 | note one test of compile_test: 0 pass, 1 fail (observation set) |
| 2407 | fn wgct1 so ulong sn ulong ji ulong a long to ulong |
| 2408 | co = get wgan 0 |
| 2409 | i = ulong 0 |
| 2410 | while lt i sn bound 999999 |
| 2411 | if wgsw add so i sub sn i wgtrci |
| 2412 | d = add i 13 |
| 2413 | if lt d sn |
| 2414 | if wgdig ulong get wga add so d |
| 2415 | wgat wgtrci |
| 2416 | wgadl a |
| 2417 | d = add d 1 |
| 2418 | if lt d sn |
| 2419 | if wgdig ulong get wga add so d |
| 2420 | d = add d 1 |
| 2421 | end |
| 2422 | end |
| 2423 | i = d |
| 2424 | continue |
| 2425 | end |
| 2426 | end |
| 2427 | end |
| 2428 | wgac ulong get wga add so i |
| 2429 | i = add i 1 |
| 2430 | end |
| 2431 | cn = sub get wgan 0 co |
| 2432 | wgpout wgtbld |
| 2433 | wdpt wgtcto |
| 2434 | wgwfile co cn |
| 2435 | r = wgomc wgtcto wgtomo wgtcte |
| 2436 | if eq r WGTMO |
| 2437 | wgdie wgtctt 76 |
| 2438 | end |
| 2439 | if ne r 0 |
| 2440 | wgcterr ji |
| 2441 | ret 1 |
| 2442 | end |
| 2443 | wgpout wgtbld |
| 2444 | wdpt wgtchk2 |
| 2445 | wghash a |
| 2446 | wgsetp SPL |
| 2447 | wgplace wgtomo |
| 2448 | v = wgrunx wgtctr |
| 2449 | if eq v WGTMO |
| 2450 | wgdie wgtctt 76 |
| 2451 | end |
| 2452 | ret wgct2 ji a v |
| 2453 | end |
| 2454 | |
| 2455 | note compile_test tail: read the run output, compare with the wanted value |
| 2456 | fn wgct2 ji ulong a long v long to ulong |
| 2457 | wdpclr |
| 2458 | wgpsl SPL |
| 2459 | u = unlink wdp 0 get wdpn 0 |
| 2460 | wgbload wgtctr |
| 2461 | so2 = get wgr 5 |
| 2462 | sn2 = get wgr 6 |
| 2463 | wgasc so2 sn2 |
| 2464 | want = wgwant ji a |
| 2465 | if or ne v want gt sn2 0 |
| 2466 | o = get wgan 0 |
| 2467 | wgat wgttf1 |
| 2468 | wgadl a |
| 2469 | wgat wgttf2 |
| 2470 | wgadl want |
| 2471 | wgat wgttf3 |
| 2472 | wgadl v |
| 2473 | wgat wgtdot |
| 2474 | put wgjoo ji o |
| 2475 | put wgjon ji sub get wgan 0 o |
| 2476 | ret 1 |
| 2477 | end |
| 2478 | ret 0 |
| 2479 | end |
| 2480 | |
| 2481 | note sha256(slot SCT + str(a)) hex[:20] onto wdp |
| 2482 | fn wghash a long to void |
| 2483 | b = new uchar 4096 0 |
| 2484 | h = new uchar 32 0 |
| 2485 | o = get wgan 0 |
| 2486 | wgasl SCT |
| 2487 | wgadl a |
| 2488 | n = sub get wgan 0 o |
| 2489 | if gt n 4096 |
| 2490 | wgdie wgtfull 61 |
| 2491 | end |
| 2492 | for i ulong n |
| 2493 | put b i get wga add o i |
| 2494 | end |
| 2495 | put wgan 0 o |
| 2496 | sha256_hash part b 0 n h |
| 2497 | for k ulong 10 |
| 2498 | v = ulong get h k |
| 2499 | wdpc ulong get wdhex shr v 4 |
| 2500 | wdpc ulong get wdhex and v 15 |
| 2501 | end |
| 2502 | end |
| 2503 | |
| 2504 | note repair.compile_test(src, j, label=slot SCT): 0 ok, 1 not ok; observation into the job's obs |
| 2505 | fn wgct so ulong sn ulong ji ulong to ulong |
| 2506 | j = get wgdr ji |
| 2507 | g = and gt sn 0 le sn 600 |
| 2508 | if g |
| 2509 | g = wgrgram so sn |
| 2510 | end |
| 2511 | if not g |
| 2512 | wgjsget j wgtbrok |
| 2513 | if not wgeq2 so sn get wgr 3 get wgr 4 |
| 2514 | wgobs ji wgtref |
| 2515 | ret 1 |
| 2516 | end |
| 2517 | end |
| 2518 | wgpout wgtbld |
| 2519 | wdpt wgtcto |
| 2520 | wgwfile so sn |
| 2521 | r = wgomc wgtcto wgtomo wgtcte |
| 2522 | if eq r WGTMO |
| 2523 | wgdie wgtctt 76 |
| 2524 | end |
| 2525 | if ne r 0 |
| 2526 | wgcterr ji |
| 2527 | ret 1 |
| 2528 | end |
| 2529 | if not wgrgram so sn |
| 2530 | wgobs ji wgtref |
| 2531 | ret 1 |
| 2532 | end |
| 2533 | if or ne wgcntt so sn wgtfci 1 ne wgcntt so sn wgtfmain 1 |
| 2534 | wgobs ji wgtrfm |
| 2535 | ret 1 |
| 2536 | end |
| 2537 | a0 = wgjv ji wgtka |
| 2538 | if not wgmainok so sn a0 |
| 2539 | wgobs ji wgtmpi |
| 2540 | ret 1 |
| 2541 | end |
| 2542 | if wgjis j wgtkind wgtloop |
| 2543 | if eq wgfindt so sn wgtfiu WGNO |
| 2544 | wgobs ji wgtrlm |
| 2545 | ret 1 |
| 2546 | end |
| 2547 | end |
| 2548 | if ne wgct1 so sn ji a0 0 |
| 2549 | ret 1 |
| 2550 | end |
| 2551 | for t ulong 3 |
| 2552 | av = wgtav t |
| 2553 | if ne av a0 |
| 2554 | if ne wgct1 so sn ji av 0 |
| 2555 | ret 1 |
| 2556 | end |
| 2557 | end |
| 2558 | end |
| 2559 | wgobs ji wgttp |
| 2560 | ret 0 |
| 2561 | end |
| 2562 | |
| 2563 | note the dedup order [a, 0, 3, 7]: test t of 0, 3, 7 |
| 2564 | fn wgtav t ulong to long |
| 2565 | if eq t 0 |
| 2566 | ret 0 |
| 2567 | end |
| 2568 | if eq t 1 |
| 2569 | ret 3 |
| 2570 | end |
| 2571 | ret 7 |
| 2572 | end |
| 2573 | |
| 2574 | text wgtold "old" |
| 2575 | text wgtnew "new" |
| 2576 | text wgtrpl "replace_text" |
| 2577 | |
| 2578 | note repair.patch: the fixed source onto the arena (wgr 5, wgr 6), or false (ValueError) |
| 2579 | fn wgpatch ji ulong d ulong to bool |
| 2580 | if ne wgjnkey d 4 |
| 2581 | ret false |
| 2582 | end |
| 2583 | ov = wgjget d wgtold |
| 2584 | nv = wgjget d wgtnew |
| 2585 | if or eq ov 0 eq nv 0 |
| 2586 | ret false |
| 2587 | end |
| 2588 | if or ne get wgjt ov 5 ne get wgjt nv 5 |
| 2589 | ret false |
| 2590 | end |
| 2591 | oo = get wgjo ov |
| 2592 | onn = get wgjl ov |
| 2593 | if or eq onn 0 or gt wgcpl oo onn 40 gt wgcpl get wgjo nv get wgjl nv 40 |
| 2594 | ret false |
| 2595 | end |
| 2596 | so = get wgjso ji |
| 2597 | sn = get wgjsn ji |
| 2598 | if ne wgcnt so sn oo onn 1 |
| 2599 | ret false |
| 2600 | end |
| 2601 | i = wgfind so sn oo onn |
| 2602 | r = get wgan 0 |
| 2603 | wgacp so i |
| 2604 | wgacp get wgjo nv get wgjl nv |
| 2605 | wgacp add so add i onn sub sn add i onn |
| 2606 | rn = sub get wgan 0 r |
| 2607 | if not wgrgram r rn |
| 2608 | ret false |
| 2609 | end |
| 2610 | put wgr 5 r |
| 2611 | put wgr 6 rn |
| 2612 | ret true |
| 2613 | end |
| 2614 | |
| 2615 | note code points of UTF-8 text (bytes that are not continuation bytes) |
| 2616 | fn wgcpl o ulong n ulong to ulong |
| 2617 | c = ulong 0 |
| 2618 | for i ulong n |
| 2619 | if ne and get wga add o i 192 128 |
| 2620 | c = add c 1 |
| 2621 | end |
| 2622 | end |
| 2623 | ret c |
| 2624 | end |
| 2625 | |
| 2626 | note one action; 0 ok, 1 error (ValueError/TypeError/KeyError) |
| 2627 | fn wgact1 ji ulong d ulong t ulong to ulong |
| 2628 | if eq d WGNO |
| 2629 | ret 1 |
| 2630 | end |
| 2631 | if ne get wgjt d 7 |
| 2632 | ret 1 |
| 2633 | end |
| 2634 | j = get wgdr ji |
| 2635 | pv = wgjget d wgtpath |
| 2636 | if eq pv 0 |
| 2637 | ret 1 |
| 2638 | end |
| 2639 | if ne get wgjt pv 5 |
| 2640 | ret 1 |
| 2641 | end |
| 2642 | wgjsget j wgtpath |
| 2643 | if not wgeq2 get wgjo pv get wgjl pv get wgr 3 get wgr 4 |
| 2644 | ret 1 |
| 2645 | end |
| 2646 | st = get wgjst ji |
| 2647 | nk = wgjnkey d |
| 2648 | if and and eq nk 2 eq st 1 wgjis d wgttool wgtrdf |
| 2649 | ret wgactr ji |
| 2650 | end |
| 2651 | if and and eq nk 2 or eq st 2 eq st 6 wgjis d wgttool wgtomck |
| 2652 | ret wgactc ji t |
| 2653 | end |
| 2654 | if and eq st 5 wgjis d wgttool wgtrpl |
| 2655 | ret wgactp ji d |
| 2656 | end |
| 2657 | ret 1 |
| 2658 | end |
| 2659 | |
| 2660 | note read_file action |
| 2661 | fn wgactr ji ulong to ulong |
| 2662 | wgpjob ji true |
| 2663 | if wgexist |
| 2664 | o = wgrtext |
| 2665 | put wgjso ji o |
| 2666 | put wgjsn ji sub get wgan 0 o |
| 2667 | put wgjst ji 2 |
| 2668 | wgobs ji wgtrok |
| 2669 | else |
| 2670 | put wgjst ji 3 |
| 2671 | wgobs ji wgtfnf |
| 2672 | end |
| 2673 | ret 0 |
| 2674 | end |
| 2675 | |
| 2676 | note omc_check action |
| 2677 | fn wgactc ji ulong t ulong to ulong |
| 2678 | wgpjob ji true |
| 2679 | o2 = wgrtext |
| 2680 | n2 = sub get wgan 0 o2 |
| 2681 | o3 = get wgan 0 |
| 2682 | wgasl SJL |
| 2683 | wgjsget get wgdr ji wgtid |
| 2684 | wgacp get wgr 3 get wgr 4 |
| 2685 | wgad t |
| 2686 | wgsetf SCT o3 |
| 2687 | v = wgct o2 n2 ji |
| 2688 | wgactt ji t v |
| 2689 | ret 0 |
| 2690 | end |
| 2691 | |
| 2692 | note record the compile_test outcome of job ji at turn t |
| 2693 | fn wgactt ji ulong t ulong v ulong to void |
| 2694 | k = add mul ji 7 t |
| 2695 | put wgtth k uchar sub 2 v |
| 2696 | put wgtto k get wgjoo ji |
| 2697 | put wgttn k get wgjon ji |
| 2698 | put wgjst ji uchar add 4 v |
| 2699 | put wgjvf ji wgb eq v 0 |
| 2700 | put wgjhv ji 1 |
| 2701 | end |
| 2702 | |
| 2703 | note replace action |
| 2704 | fn wgactp ji ulong d ulong to ulong |
| 2705 | if not wgpatch ji d |
| 2706 | ret 1 |
| 2707 | end |
| 2708 | fo = get wgr 5 |
| 2709 | fn2 = get wgr 6 |
| 2710 | wgpjob ji true |
| 2711 | wgwfile fo fn2 |
| 2712 | put wgjst ji 6 |
| 2713 | put wgjso ji fo |
| 2714 | put wgjsn ji fn2 |
| 2715 | wgobs ji wgtes |
| 2716 | put wgjvf ji 0 |
| 2717 | put wgjhv ji 1 |
| 2718 | ret 0 |
| 2719 | end |
| 2720 | |
| 2721 | note one answer for job ji at turn t |
| 2722 | fn wgstep ji ulong ro ulong rn ulong t ulong to void |
| 2723 | wgasc ro rn |
| 2724 | wgturn ji ro rn t |
| 2725 | wgtext ro rn |
| 2726 | so = get wgr 0 |
| 2727 | sn = get wgr 1 |
| 2728 | if wgeqt so sn wgttp |
| 2729 | wgjtp ji |
| 2730 | ret |
| 2731 | end |
| 2732 | if wgeqt so sn wgtfnf |
| 2733 | put wgjps ji wgb eq get wgjst ji 3 |
| 2734 | put wgjdn ji 1 |
| 2735 | ret |
| 2736 | end |
| 2737 | wgstp2 ji so sn t |
| 2738 | end |
| 2739 | |
| 2740 | note record turn t of job ji (raw answer and state) |
| 2741 | fn wgturn ji ulong ro ulong rn ulong t ulong to void |
| 2742 | k = add mul ji 7 t |
| 2743 | put wgtro k ro |
| 2744 | put wgtrl k rn |
| 2745 | put wgtst k get wgjst ji |
| 2746 | put wgtth k 0 |
| 2747 | put wgjtn ji add t 1 |
| 2748 | end |
| 2749 | |
| 2750 | note TASK_PASSED: pass iff state is verified-done with a passing verification |
| 2751 | fn wgjtp ji ulong to void |
| 2752 | st = get wgjst ji |
| 2753 | hv = eq get wgjhv ji 1 |
| 2754 | put wgjps ji wgb and eq st 4 and hv eq get wgjvf ji 1 |
| 2755 | put wgjdn ji 1 |
| 2756 | end |
| 2757 | |
| 2758 | note any other answer: parse and act |
| 2759 | fn wgstp2 ji ulong so ulong sn ulong t ulong to void |
| 2760 | mk = get wgjn 0 |
| 2761 | d = wgjparse so sn |
| 2762 | r = wgact1 ji d t |
| 2763 | put wgjn 0 mk |
| 2764 | if ne r 0 |
| 2765 | put wgjdn ji 1 |
| 2766 | put wgjer ji 1 |
| 2767 | end |
| 2768 | end |
| 2769 | |
| 2770 | note set up nj jobs (wgdr) under label slot SJL: fixtures and initial state |
| 2771 | fn wgjinit nj ulong to void |
| 2772 | for i ulong nj |
| 2773 | wgpjob i false |
| 2774 | wgmkp |
| 2775 | wgjzero i |
| 2776 | wgjzer2 i |
| 2777 | j = get wgdr i |
| 2778 | if not wgjis j wgtfault wgts3 |
| 2779 | wgpjob i true |
| 2780 | wgjsget j wgtbrok |
| 2781 | wgwfile get wgr 3 get wgr 4 |
| 2782 | end |
| 2783 | end |
| 2784 | end |
| 2785 | |
| 2786 | text wgtturn "-turn" |
| 2787 | |
| 2788 | note jobs_run over nj jobs; answers come from wgsamp |
| 2789 | fn wgjobs nj ulong to void |
| 2790 | wgjinit nj |
| 2791 | for t ulong 7 |
| 2792 | na = ulong 0 |
| 2793 | for i ulong nj |
| 2794 | if eq get wgjdn i 0 |
| 2795 | put wgact na i |
| 2796 | put wgpo na wgprm i |
| 2797 | put wgpl na sub get wgan 0 get wgpo na |
| 2798 | na = add na 1 |
| 2799 | end |
| 2800 | end |
| 2801 | if eq na 0 |
| 2802 | break |
| 2803 | end |
| 2804 | o = get wgan 0 |
| 2805 | wgasl SJL |
| 2806 | wgat wgtturn |
| 2807 | wgad t |
| 2808 | wgsetf SLAB o |
| 2809 | put wgmd 1 t |
| 2810 | wgsamp na |
| 2811 | for q ulong na |
| 2812 | wgstep get wgact q get wgao q get wgal q t |
| 2813 | end |
| 2814 | end |
| 2815 | end |
| 2816 | |
| 2817 | fn wgjzero i ulong to void |
| 2818 | put wgjst i 1 |
| 2819 | put wgjso i 0 |
| 2820 | put wgjsn i 0 |
| 2821 | put wgjoo i 0 |
| 2822 | put wgjon i 0 |
| 2823 | put wgjdn i 0 |
| 2824 | end |
| 2825 | |
| 2826 | fn wgjzer2 i ulong to void |
| 2827 | put wgjps i 0 |
| 2828 | put wgjvf i 0 |
| 2829 | put wgjhv i 0 |
| 2830 | put wgjer i 0 |
| 2831 | put wgjtn i 0 |
| 2832 | end |
| 2833 | |
| 2834 | note ---------------------------------------------------------------- lib.run / sample / score |
| 2835 | note wgmd: 0 mode (1 live, 2 replay, 3 replaylog), 1 current turn, 2 kind (0 probe, 1 first, 2 jobs) |
| 2836 | |
| 2837 | text wgtrcps "/receipts/" |
| 2838 | text wgtlog ".log" |
| 2839 | text wgtcmds "/commands.txt" |
| 2840 | text wgtrcw " rc=" |
| 2841 | text wgtwin " window=" |
| 2842 | text wgtargv " argv" |
| 2843 | text wgtdats "/data/s" |
| 2844 | text wgtdats2 "/data/s/" |
| 2845 | text wgtbin ".bin" |
| 2846 | text wgttok ".tok" |
| 2847 | text wgtenc "-encode" |
| 2848 | text wgtsmp "-sample" |
| 2849 | text wgtbat "-batch" |
| 2850 | text wgtbpe "bpeenc" |
| 2851 | text wgt4096 "4096" |
| 2852 | text wgt160 "160" |
| 2853 | text wgtgev2 "geval" |
| 2854 | text wgt256 "256" |
| 2855 | text wgtraw "raw_output" |
| 2856 | text wgtturns "turns" |
| 2857 | text wgtprom "prompt" |
| 2858 | text wgtrawk "raw" |
| 2859 | text wgtstk "state" |
| 2860 | |
| 2861 | note the packed argv list wdk joined by spaces onto the arena |
| 2862 | fn wgkargs to void |
| 2863 | c = get wdkn 0 |
| 2864 | p = ulong 2 |
| 2865 | for i ulong c |
| 2866 | n = or ulong get wdk p shl ulong get wdk add p 1 8 |
| 2867 | if gt i 0 |
| 2868 | wgac 32 |
| 2869 | end |
| 2870 | for j ulong n |
| 2871 | wgac ulong get wdk add add p 2 j |
| 2872 | end |
| 2873 | p = add add p 2 n |
| 2874 | end |
| 2875 | end |
| 2876 | |
| 2877 | note lib.run: argv in wdk, label in slot SLOG; stdout and stderr to OUT/receipts/LABEL.log; the |
| 2878 | note command line goes to OUT/commands.txt after it ends (not on timeout). Returns the log offset |
| 2879 | note (length in wgr 6) after universal newline translation; exit 73 when rc is not 0, 74 on timeout. |
| 2880 | fn wgrun ns long to ulong |
| 2881 | wdpclr |
| 2882 | wgpsl SOUT |
| 2883 | wdpt wgtrcps |
| 2884 | wgpsl SLOG |
| 2885 | wdpt wgtlog |
| 2886 | wgsetp SPL |
| 2887 | fd = wgcreat false |
| 2888 | pid = wgspawn -1 fd fd WGNO |
| 2889 | r = wgreap pid ns |
| 2890 | c = fclose fd |
| 2891 | if eq r WGTMO |
| 2892 | wdpclr |
| 2893 | wgpsl SLOG |
| 2894 | wgdiep wgtcmdt 74 |
| 2895 | end |
| 2896 | m = get wgan 0 |
| 2897 | wgasl SLOG |
| 2898 | wgat wgtrcw |
| 2899 | wgadl r |
| 2900 | wgat wgtwin |
| 2901 | wgasl SWIN |
| 2902 | wgat wgtargv |
| 2903 | wgac 32 |
| 2904 | wgkargs |
| 2905 | wgac 10 |
| 2906 | wdpclr |
| 2907 | wgpsl SOUT |
| 2908 | wdpt wgtcmds |
| 2909 | fd2 = wgcreat true |
| 2910 | wgwr fd2 m sub get wgan 0 m |
| 2911 | c2 = fclose fd2 |
| 2912 | put wgan 0 m |
| 2913 | if ne r 0 |
| 2914 | wdpclr |
| 2915 | wgpsl SLOG |
| 2916 | wgdiep wgtcmdf 73 |
| 2917 | end |
| 2918 | wdpclr |
| 2919 | wgpsl SPL |
| 2920 | o = wgrtext |
| 2921 | put wgr 6 sub get wgan 0 o |
| 2922 | ret o |
| 2923 | end |
| 2924 | |
| 2925 | note OUT/data/s/SBLD + suffix into wdp |
| 2926 | fn wgpbld t view uchar * to void |
| 2927 | wdpclr |
| 2928 | wgpsl SOUT |
| 2929 | wdpt wgtdats2 |
| 2930 | wgpsl SBLD |
| 2931 | wdpt t |
| 2932 | end |
| 2933 | |
| 2934 | note the log (o, n) split on NUL into wgao/wgal from index b0 for cnt answers (exit 75 otherwise) |
| 2935 | fn wgsplit o ulong n ulong b0 ulong cnt ulong to void |
| 2936 | k = ulong 0 |
| 2937 | s = o |
| 2938 | e = add o n |
| 2939 | i = o |
| 2940 | while lt i e bound 999999 |
| 2941 | if eq get wga i 0 |
| 2942 | if ge k cnt |
| 2943 | wgdie wgtcnt 75 |
| 2944 | end |
| 2945 | put wgao add b0 k s |
| 2946 | put wgal add b0 k sub i s |
| 2947 | k = add k 1 |
| 2948 | s = add i 1 |
| 2949 | end |
| 2950 | i = add i 1 |
| 2951 | end |
| 2952 | if or ne k cnt ne s e |
| 2953 | wgdie wgtcnt 75 |
| 2954 | end |
| 2955 | end |
| 2956 | |
| 2957 | note one live batch: prompts [b0, b0 + cnt) of wgpo/wgpl under the batch label in slot SBLD |
| 2958 | fn wglive b0 ulong cnt ulong to void |
| 2959 | z = new uchar 1 0 |
| 2960 | wdpclr |
| 2961 | wgpsl SOUT |
| 2962 | wdpt wgtdats |
| 2963 | wgmkp |
| 2964 | wgpbld wgtbin |
| 2965 | fd = wgcreat false |
| 2966 | for q ulong cnt |
| 2967 | wgwr fd get wgpo add b0 q get wgpl add b0 q |
| 2968 | w = write fd z 0 1 |
| 2969 | end |
| 2970 | c = fclose fd |
| 2971 | m = get wgan 0 |
| 2972 | wgasl SBLD |
| 2973 | wgat wgtenc |
| 2974 | wgsetf SLOG m |
| 2975 | wgkenc |
| 2976 | lo = wgrun 1800000000000 |
| 2977 | m2 = get wgan 0 |
| 2978 | wgasl SBLD |
| 2979 | wgat wgtsmp |
| 2980 | wgsetf SLOG m2 |
| 2981 | wgksmp |
| 2982 | lo2 = wgrun 900000000000 |
| 2983 | wgsplit lo2 get wgr 6 b0 cnt |
| 2984 | wgpbld wgtbin |
| 2985 | u = unlink wdp 0 get wdpn 0 |
| 2986 | wgpbld wgttok |
| 2987 | u2 = unlink wdp 0 get wdpn 0 |
| 2988 | end |
| 2989 | |
| 2990 | note encode argv [CPU, bpeenc, MERGES, 4096, pf, tf] into wdk |
| 2991 | fn wgkenc to void |
| 2992 | wdkclr |
| 2993 | wdkt wgtcpu |
| 2994 | wdkt wgtbpe |
| 2995 | wdkt wgtmrg |
| 2996 | wdkt wgt4096 |
| 2997 | wgpbld wgtbin |
| 2998 | wdkp |
| 2999 | wgpbld wgttok |
| 3000 | wdkp |
| 3001 | end |
| 3002 | |
| 3003 | note sample argv [batch-sample, ck, tf, MERGES, 160] into wdk |
| 3004 | fn wgksmp to void |
| 3005 | wdkclr |
| 3006 | wdkt wgtbs |
| 3007 | wdpclr |
| 3008 | wgpsl SCK |
| 3009 | wdkp |
| 3010 | wgpbld wgttok |
| 3011 | wdkp |
| 3012 | wdkt wgtmrg |
| 3013 | wdkt wgt160 |
| 3014 | end |
| 3015 | |
| 3016 | note geval argv [GPU, geval, ck, story-final.tok, 256, MERGES] into wdk |
| 3017 | fn wgkgev to void |
| 3018 | wdkclr |
| 3019 | wdkt wgtgpu |
| 3020 | wdkt wgtgev2 |
| 3021 | wdpclr |
| 3022 | wgpsl SCK |
| 3023 | wdkp |
| 3024 | wdkt wgtstok |
| 3025 | wdkt wgt256 |
| 3026 | wdkt wgtmrg |
| 3027 | end |
| 3028 | |
| 3029 | note one replaylog batch: LOGDIR/SBLD-sample.log |
| 3030 | fn wglogb b0 ulong cnt ulong to void |
| 3031 | wdpclr |
| 3032 | wgpsl SLOG |
| 3033 | wdpc 47 |
| 3034 | wgpsl SBLD |
| 3035 | wdpt wgtsmp |
| 3036 | wdpt wgtlog |
| 3037 | o = wgrtext |
| 3038 | wgsplit o sub get wgan 0 o b0 cnt |
| 3039 | end |
| 3040 | |
| 3041 | note the recorded raw for active answer q (probe row q, or turn of job wgact q); 0 when absent |
| 3042 | fn wgrecraw q ulong to ulong |
| 3043 | if ne get wgmd 2 2 |
| 3044 | v = wgjget get wgrr q wgtraw |
| 3045 | ret v |
| 3046 | end |
| 3047 | ji = get wgact q |
| 3048 | ts = wgjget get wgrr ji wgtturns |
| 3049 | if eq ts 0 |
| 3050 | ret 0 |
| 3051 | end |
| 3052 | tr = wgjat ts get wgmd 1 |
| 3053 | if eq tr 0 |
| 3054 | ret 0 |
| 3055 | end |
| 3056 | ret tr |
| 3057 | end |
| 3058 | |
| 3059 | note sample(label=slot SLAB, prompts wgpo/wgpl[0..na)) into wgao/wgal[0..na) |
| 3060 | fn wgsamp na ulong to void |
| 3061 | md = get wgmd 0 |
| 3062 | if eq md 2 |
| 3063 | wgsrep na |
| 3064 | ret |
| 3065 | end |
| 3066 | b = ulong 0 |
| 3067 | b0 = ulong 0 |
| 3068 | while lt b0 na bound 1024 |
| 3069 | cnt = sub na b0 |
| 3070 | if gt cnt 128 |
| 3071 | cnt = 128 |
| 3072 | end |
| 3073 | o = get wgan 0 |
| 3074 | wgasl SLAB |
| 3075 | wgat wgtbat |
| 3076 | wgad b |
| 3077 | wgsetf SBLD o |
| 3078 | if eq md 1 |
| 3079 | wglive b0 cnt |
| 3080 | else |
| 3081 | wglogb b0 cnt |
| 3082 | end |
| 3083 | b0 = add b0 cnt |
| 3084 | b = add b 1 |
| 3085 | end |
| 3086 | if eq md 3 |
| 3087 | wgsrec na |
| 3088 | end |
| 3089 | end |
| 3090 | |
| 3091 | note replay: answers are the recorded raws; prompts are compared with the recorded ones (jobs) |
| 3092 | fn wgsrep na ulong to void |
| 3093 | for q ulong na |
| 3094 | r = wgrecraw q |
| 3095 | if eq r 0 |
| 3096 | wgdie wgtdiv 81 |
| 3097 | end |
| 3098 | v = r |
| 3099 | if eq get wgmd 2 2 |
| 3100 | wgcprom q r |
| 3101 | v = wgjget r wgtrawk |
| 3102 | end |
| 3103 | if eq v 0 |
| 3104 | wgdie wgtshp 79 |
| 3105 | end |
| 3106 | if ne get wgjt v 5 |
| 3107 | wgdie wgtshp 79 |
| 3108 | end |
| 3109 | put wgao q get wgjo v |
| 3110 | put wgal q get wgjl v |
| 3111 | end |
| 3112 | end |
| 3113 | |
| 3114 | note replaylog: the log answers are compared with the recorded raws |
| 3115 | fn wgsrec na ulong to void |
| 3116 | for q ulong na |
| 3117 | r = wgrecraw q |
| 3118 | if eq r 0 |
| 3119 | wgmism q wgtrawk |
| 3120 | continue |
| 3121 | end |
| 3122 | v = r |
| 3123 | if eq get wgmd 2 2 |
| 3124 | wgcprom q r |
| 3125 | v = wgjget r wgtrawk |
| 3126 | end |
| 3127 | if eq v 0 |
| 3128 | wgmism q wgtrawk |
| 3129 | continue |
| 3130 | end |
| 3131 | if not wgeq2 get wgao q get wgal q get wgjo v get wgjl v |
| 3132 | wgmism q wgtrawk |
| 3133 | end |
| 3134 | end |
| 3135 | end |
| 3136 | |
| 3137 | note compare prompt q with the recorded turn r |
| 3138 | fn wgcprom q ulong r ulong to void |
| 3139 | v = wgjget r wgtprom |
| 3140 | if eq v 0 |
| 3141 | wgmism q wgtprom |
| 3142 | ret |
| 3143 | end |
| 3144 | if not wgeq2 get wgpo q get wgpl q get wgjo v get wgjl v |
| 3145 | wgmism q wgtprom |
| 3146 | end |
| 3147 | end |
| 3148 | |
| 3149 | text wgtmis "MISMATCH row=" |
| 3150 | text wgtfld " field=" |
| 3151 | text wgttrn " turn=" |
| 3152 | |
| 3153 | fn wgmism q ulong t view uchar * to void |
| 3154 | put wgmis 0 add get wgmis 0 1 |
| 3155 | wdot wgtmis |
| 3156 | r = q |
| 3157 | if eq get wgmd 2 2 |
| 3158 | r = get wgact q |
| 3159 | end |
| 3160 | wdod r |
| 3161 | if eq get wgmd 2 2 |
| 3162 | wdot wgttrn |
| 3163 | wdod get wgmd 1 |
| 3164 | end |
| 3165 | wdot wgtfld |
| 3166 | wdot t |
| 3167 | wdoc 10 |
| 3168 | end |
| 3169 | |
| 3170 | note lib.score: geval on slot SCK with label slot SLOG; the third number of the one E row |
| 3171 | fn wgscore to ulong |
| 3172 | wgkgev |
| 3173 | lo = wgrun 1800000000000 |
| 3174 | n = get wgr 6 |
| 3175 | e = add lo n |
| 3176 | p = lo |
| 3177 | found = ulong 0 |
| 3178 | val = ulong 0 |
| 3179 | while lt p e bound 999999 |
| 3180 | q = wgeol p e |
| 3181 | nx = get wgr 2 |
| 3182 | if wgerow p sub q p |
| 3183 | found = add found 1 |
| 3184 | val = ulong get wgtm 2 |
| 3185 | if ne get wgtm 1 256 |
| 3186 | found = 99 |
| 3187 | end |
| 3188 | end |
| 3189 | p = nx |
| 3190 | end |
| 3191 | if ne found 1 |
| 3192 | wgdie wgtgev 78 |
| 3193 | end |
| 3194 | ret val |
| 3195 | end |
| 3196 | |
| 3197 | note line is "E d+ d+ d+ d+": the four numbers into wgtm |
| 3198 | fn wgerow o ulong n ulong to bool |
| 3199 | if lt n 9 |
| 3200 | ret false |
| 3201 | end |
| 3202 | if or ne get wga o 69 ne get wga add o 1 32 |
| 3203 | ret false |
| 3204 | end |
| 3205 | i = ulong 2 |
| 3206 | for f ulong 4 |
| 3207 | if gt f 0 |
| 3208 | if ge i n |
| 3209 | ret false |
| 3210 | end |
| 3211 | if ne get wga add o i 32 |
| 3212 | ret false |
| 3213 | end |
| 3214 | i = add i 1 |
| 3215 | end |
| 3216 | s = i |
| 3217 | v = long 0 |
| 3218 | while lt i n bound 4096 |
| 3219 | if not wgdig ulong get wga add o i |
| 3220 | break |
| 3221 | end |
| 3222 | if lt i add s 18 |
| 3223 | v = add mul v 10 long sub ulong get wga add o i 48 |
| 3224 | end |
| 3225 | i = add i 1 |
| 3226 | end |
| 3227 | if eq i s |
| 3228 | ret false |
| 3229 | end |
| 3230 | put wgtm f v |
| 3231 | end |
| 3232 | ret eq i n |
| 3233 | end |
| 3234 | |
| 3235 | note ---------------------------------------------------------------- probes, results, replay comparison |
| 3236 | |
| 3237 | text wgtpass "pass" |
| 3238 | text wgtcrc "compile_rc" |
| 3239 | text wgtrrc "run_rc" |
| 3240 | text wgtPASS "PASS" |
| 3241 | text wgtFAIL "FAIL" |
| 3242 | text wgtres "/results/" |
| 3243 | text wgttxt ".txt" |
| 3244 | text wgttmp ".tmp" |
| 3245 | text wgtcr " compile_rc=" |
| 3246 | text wgtrr " run_rc=" |
| 3247 | text wgtsts " state=" |
| 3248 | text wgttns " turns=" |
| 3249 | text wgterr " error" |
| 3250 | text wgtver "verified" |
| 3251 | text wgterrk "error" |
| 3252 | text wgtsrc "src" |
| 3253 | text wgtobs "obs" |
| 3254 | text wgttres "tool_result" |
| 3255 | text wgtobsk "observation" |
| 3256 | text wgtok "ok" |
| 3257 | |
| 3258 | note gates.py probes(): prompts of rows wgdr[0..nr), label slot SLAB; kind wgmd 2 (0 checker, 1 first) |
| 3259 | fn wgprobes nr ulong to ulong |
| 3260 | for i ulong nr |
| 3261 | wgjsget get wgdr i wgtprom |
| 3262 | put wgpo i get wgr 3 |
| 3263 | put wgpl i get wgr 4 |
| 3264 | end |
| 3265 | wgsamp nr |
| 3266 | cnt = ulong 0 |
| 3267 | for q ulong nr |
| 3268 | ok = false |
| 3269 | if eq get wgmd 2 1 |
| 3270 | put wgxr 0 WGABS |
| 3271 | put wgxr 1 WGABS |
| 3272 | ok = wgfirst get wgao q get wgal q get wgdr q |
| 3273 | else |
| 3274 | o = get wgan 0 |
| 3275 | wgasl SLAB |
| 3276 | wgac 45 |
| 3277 | wgad q |
| 3278 | wgsetf SCB o |
| 3279 | ok = wgcheck get wgao q get wgal q get wgdr q |
| 3280 | end |
| 3281 | put wgok q wgb ok |
| 3282 | if ok |
| 3283 | cnt = add cnt 1 |
| 3284 | end |
| 3285 | wgrline q |
| 3286 | if ge get wgmd 0 2 |
| 3287 | wgpcmp q ok |
| 3288 | end |
| 3289 | end |
| 3290 | wgresfin |
| 3291 | ret cnt |
| 3292 | end |
| 3293 | |
| 3294 | note results buffer to OUT/results/SLAB.txt.tmp, opened by wgresop |
| 3295 | fn wgresop to void |
| 3296 | wdpclr |
| 3297 | wgpsl SOUT |
| 3298 | wdpt wgtres |
| 3299 | wgpsl SLAB |
| 3300 | wdpt wgttxt |
| 3301 | wdpt wgttmp |
| 3302 | fd = wgcreat false |
| 3303 | put wgobf 0 fd |
| 3304 | put wgobn 0 0 |
| 3305 | end |
| 3306 | |
| 3307 | fn wgresfin to void |
| 3308 | wgofl |
| 3309 | c = fclose get wgobf 0 |
| 3310 | wdkclr |
| 3311 | wdpclr |
| 3312 | wgpsl SOUT |
| 3313 | wdpt wgtres |
| 3314 | wgpsl SLAB |
| 3315 | wdpt wgttxt |
| 3316 | wdpt wgttmp |
| 3317 | wdkp |
| 3318 | put wdpn 0 sub get wdpn 0 4 |
| 3319 | wdkp |
| 3320 | wdrename |
| 3321 | end |
| 3322 | |
| 3323 | fn wgpf ok bool to void |
| 3324 | if ok |
| 3325 | wgot wgtPASS |
| 3326 | else |
| 3327 | wgot wgtFAIL |
| 3328 | end |
| 3329 | end |
| 3330 | |
| 3331 | fn wgrline q ulong to void |
| 3332 | if eq q 0 |
| 3333 | wgresop |
| 3334 | end |
| 3335 | wgod q |
| 3336 | wgoc 32 |
| 3337 | wgpf eq get wgok q 1 |
| 3338 | if ne get wgxr 0 WGABS |
| 3339 | wgot wgtcr |
| 3340 | wgodl get wgxr 0 |
| 3341 | end |
| 3342 | if ne get wgxr 1 WGABS |
| 3343 | wgot wgtrr |
| 3344 | wgodl get wgxr 1 |
| 3345 | end |
| 3346 | wgoc 10 |
| 3347 | end |
| 3348 | |
| 3349 | note recorded boolean under t equals b (absent: mismatch) |
| 3350 | fn wgcbool q ulong r ulong t view uchar * b bool to void |
| 3351 | v = wgjget r t |
| 3352 | if eq v 0 |
| 3353 | wgmism q t |
| 3354 | ret |
| 3355 | end |
| 3356 | ty = get wgjt v |
| 3357 | if and ne ty 3 ne ty 2 |
| 3358 | wgmism q t |
| 3359 | ret |
| 3360 | end |
| 3361 | if ne wgb eq ty 3 wgb b |
| 3362 | wgmism q t |
| 3363 | end |
| 3364 | end |
| 3365 | |
| 3366 | note recorded integer under t (absent when x is WGABS) |
| 3367 | fn wgcint q ulong r ulong t view uchar * x long to void |
| 3368 | v = wgjget r t |
| 3369 | if eq v 0 |
| 3370 | if ne x WGABS |
| 3371 | wgmism q t |
| 3372 | end |
| 3373 | ret |
| 3374 | end |
| 3375 | if eq x WGABS |
| 3376 | wgmism q t |
| 3377 | ret |
| 3378 | end |
| 3379 | if ne wgjint v x |
| 3380 | wgmism q t |
| 3381 | end |
| 3382 | end |
| 3383 | |
| 3384 | fn wgpcmp q ulong ok bool to void |
| 3385 | r = get wgrr q |
| 3386 | wgcbool q r wgtpass ok |
| 3387 | if eq get wgmd 2 0 |
| 3388 | wgcint q r wgtcrc get wgxr 0 |
| 3389 | wgcint q r wgtrrc get wgxr 1 |
| 3390 | end |
| 3391 | end |
| 3392 | |
| 3393 | note recorded string under t equals (o, n); absent counts as empty when em is true |
| 3394 | fn wgcstr q ulong r ulong t view uchar * o ulong n ulong to void |
| 3395 | v = wgjget r t |
| 3396 | if eq v 0 |
| 3397 | wgmism q t |
| 3398 | ret |
| 3399 | end |
| 3400 | if ne get wgjt v 5 |
| 3401 | wgmism q t |
| 3402 | ret |
| 3403 | end |
| 3404 | if not wgeq2 get wgjo v get wgjl v o n |
| 3405 | wgmism q t |
| 3406 | end |
| 3407 | end |
| 3408 | |
| 3409 | note compare job ji with recorded row wgrr ji (mismatch rows are job indexes) |
| 3410 | fn wgjcmp ji ulong to void |
| 3411 | r = get wgrr ji |
| 3412 | put wgmd 1 0 |
| 3413 | wgcbool ji r wgtpass eq get wgjps ji 1 |
| 3414 | m = get wgan 0 |
| 3415 | wgstn ulong get wgjst ji |
| 3416 | wgcstr ji r wgtstk m sub get wgan 0 m |
| 3417 | put wgan 0 m |
| 3418 | wgcstr ji r wgtsrc get wgjso ji get wgjsn ji |
| 3419 | wgcstr ji r wgtobs get wgjoo ji get wgjon ji |
| 3420 | vv = wgjget r wgtver |
| 3421 | if ne eq vv 0 eq get wgjhv ji 0 |
| 3422 | wgmism ji wgtver |
| 3423 | else |
| 3424 | if ne vv 0 |
| 3425 | wgcbool ji r wgtver eq get wgjvf ji 1 |
| 3426 | end |
| 3427 | end |
| 3428 | if ne eq wgjget r wgterrk 0 eq get wgjer ji 0 |
| 3429 | wgmism ji wgterrk |
| 3430 | end |
| 3431 | ts = wgjget r wgtturns |
| 3432 | if eq ts 0 |
| 3433 | wgmism ji wgtturns |
| 3434 | ret |
| 3435 | end |
| 3436 | if ne get wgjo ts get wgjtn ji |
| 3437 | wgmism ji wgtturns |
| 3438 | ret |
| 3439 | end |
| 3440 | for t ulong get wgjtn ji |
| 3441 | wgtcmp ji wgjat ts t t |
| 3442 | end |
| 3443 | end |
| 3444 | |
| 3445 | fn wgtcmp ji ulong tr ulong t ulong to void |
| 3446 | k = add mul ji 7 t |
| 3447 | m = get wgan 0 |
| 3448 | wgstn ulong get wgtst k |
| 3449 | wgcstr ji tr wgtstk m sub get wgan 0 m |
| 3450 | put wgan 0 m |
| 3451 | tv = wgjget tr wgttres |
| 3452 | if ne eq tv 0 eq get wgtth k 0 |
| 3453 | wgmism ji wgttres |
| 3454 | ret |
| 3455 | end |
| 3456 | if ne tv 0 |
| 3457 | wgcbool ji tv wgtok eq get wgtth k 2 |
| 3458 | wgcstr ji tv wgtobsk get wgtto k get wgttn k |
| 3459 | end |
| 3460 | end |
| 3461 | |
| 3462 | note jobs results file: id PASS|FAIL state=S turns=T [error] |
| 3463 | fn wgjres nj ulong to void |
| 3464 | wgresop |
| 3465 | for i ulong nj |
| 3466 | wgjsget get wgdr i wgtid |
| 3467 | wgoa get wgr 3 get wgr 4 |
| 3468 | wgoc 32 |
| 3469 | wgpf eq get wgjps i 1 |
| 3470 | wgot wgtsts |
| 3471 | m = get wgan 0 |
| 3472 | wgstn ulong get wgjst i |
| 3473 | wgoa m sub get wgan 0 m |
| 3474 | put wgan 0 m |
| 3475 | wgot wgttns |
| 3476 | wgod get wgjtn i |
| 3477 | if eq get wgjer i 1 |
| 3478 | wgot wgterr |
| 3479 | end |
| 3480 | wgoc 10 |
| 3481 | end |
| 3482 | wgresfin |
| 3483 | end |
| 3484 | |
| 3485 | fn wgjpass nj ulong to ulong |
| 3486 | c = ulong 0 |
| 3487 | for i ulong nj |
| 3488 | if eq get wgjps i 1 |
| 3489 | c = add c 1 |
| 3490 | end |
| 3491 | end |
| 3492 | ret c |
| 3493 | end |
| 3494 | |
| 3495 | note ---------------------------------------------------------------- paths and arguments |
| 3496 | |
| 3497 | note argument i into slot k |
| 3498 | fn wgargs i ulong k ulong to void |
| 3499 | n = wdarg i |
| 3500 | o = get wgan 0 |
| 3501 | for j ulong n |
| 3502 | wgac ulong get wdab j |
| 3503 | end |
| 3504 | wgsset k o n |
| 3505 | end |
| 3506 | |
| 3507 | text wgtpwd "PWD" |
| 3508 | text wgtnopwd "wgate: relative path and no PWD\n" |
| 3509 | |
| 3510 | note Path.resolve() made lexical: argument i, absolute (PWD prefix), with "." and ".." folded; slot k |
| 3511 | fn wgresolv i ulong k ulong to void |
| 3512 | n = wdarg i |
| 3513 | o = get wgan 0 |
| 3514 | if or eq n 0 ne get wdab 0 47 |
| 3515 | if not wdenv wgtpwd |
| 3516 | wgdie wgtnopwd 2 |
| 3517 | end |
| 3518 | for j ulong get wdvn 0 |
| 3519 | wgac ulong get wdv j |
| 3520 | end |
| 3521 | wgac 47 |
| 3522 | end |
| 3523 | for j2 ulong n |
| 3524 | wgac ulong get wdab j2 |
| 3525 | end |
| 3526 | e = get wgan 0 |
| 3527 | wgnorm o e |
| 3528 | end |
| 3529 | |
| 3530 | note fold the absolute path [o, e) into a fresh slot k copy at the arena top (written by wgnorm) |
| 3531 | fn wgnorm o ulong e ulong to void |
| 3532 | r = get wgan 0 |
| 3533 | p = o |
| 3534 | while lt p e bound 4096 |
| 3535 | while lt p e bound 4096 |
| 3536 | if ne get wga p 47 |
| 3537 | break |
| 3538 | end |
| 3539 | p = add p 1 |
| 3540 | end |
| 3541 | if ge p e |
| 3542 | break |
| 3543 | end |
| 3544 | q = p |
| 3545 | while lt q e bound 4096 |
| 3546 | if eq get wga q 47 |
| 3547 | break |
| 3548 | end |
| 3549 | q = add q 1 |
| 3550 | end |
| 3551 | wgncmp r p sub q p |
| 3552 | p = q |
| 3553 | end |
| 3554 | if eq get wgan 0 r |
| 3555 | wgac 47 |
| 3556 | end |
| 3557 | put wgr 7 r |
| 3558 | end |
| 3559 | |
| 3560 | note one path component [p, p + sl): "." is dropped, ".." pops, others are appended |
| 3561 | fn wgncmp r ulong p ulong sl ulong to void |
| 3562 | if wgisdot p sl 1 |
| 3563 | ret |
| 3564 | end |
| 3565 | if wgisdot p sl 2 |
| 3566 | wgpop r |
| 3567 | ret |
| 3568 | end |
| 3569 | wgac 47 |
| 3570 | wgacp p sl |
| 3571 | end |
| 3572 | |
| 3573 | note component is k dots |
| 3574 | fn wgisdot p ulong sl ulong k ulong to bool |
| 3575 | if ne sl k |
| 3576 | ret false |
| 3577 | end |
| 3578 | for i ulong k |
| 3579 | if ne get wga add p i 46 |
| 3580 | ret false |
| 3581 | end |
| 3582 | end |
| 3583 | ret true |
| 3584 | end |
| 3585 | |
| 3586 | note drop the last component of the path at r |
| 3587 | fn wgpop r ulong to void |
| 3588 | t = get wgan 0 |
| 3589 | while gt t r bound 4096 |
| 3590 | t = sub t 1 |
| 3591 | if eq get wga t 47 |
| 3592 | break |
| 3593 | end |
| 3594 | end |
| 3595 | put wgan 0 t |
| 3596 | end |
| 3597 | |
| 3598 | fn wgresk i ulong k ulong to void |
| 3599 | wgresolv i k |
| 3600 | r = get wgr 7 |
| 3601 | wgsetf k r |
| 3602 | end |
| 3603 | |
| 3604 | note OUT subdirectories |
| 3605 | text wgtsfix "/fixtures" |
| 3606 | text wgtsrcp "/receipts" |
| 3607 | text wgtsres "/results" |
| 3608 | text wgtsdat "/data" |
| 3609 | text wgtsbld "/build" |
| 3610 | |
| 3611 | fn wgmkd t view uchar * to void |
| 3612 | wdpclr |
| 3613 | wgpsl SOUT |
| 3614 | wdpt t |
| 3615 | wgmkp |
| 3616 | end |
| 3617 | |
| 3618 | fn wgmkout to void |
| 3619 | wdpclr |
| 3620 | wgpsl SOUT |
| 3621 | wgmkp |
| 3622 | wgmkd wgtsfix |
| 3623 | wgmkd wgtsrcp |
| 3624 | wgmkd wgtsres |
| 3625 | wgmkd wgtsdat |
| 3626 | wgmkd wgtsbld |
| 3627 | wdpclr |
| 3628 | wgpsl SOUT |
| 3629 | wdpt wgtsfix |
| 3630 | wgsetp SFIX |
| 3631 | end |
| 3632 | |
| 3633 | note decimal argument i (absent: d) |
| 3634 | fn wgargn i ulong d ulong to ulong |
| 3635 | if ge i ulong argcnt |
| 3636 | ret d |
| 3637 | end |
| 3638 | n = wdarg i |
| 3639 | v = ulong 0 |
| 3640 | if eq n 0 |
| 3641 | wgdie wgtuse 2 |
| 3642 | end |
| 3643 | for j ulong n |
| 3644 | c = ulong get wdab j |
| 3645 | if not wgdig c |
| 3646 | wgdie wgtuse 2 |
| 3647 | end |
| 3648 | v = add mul v 10 sub c 48 |
| 3649 | end |
| 3650 | if eq v 0 |
| 3651 | wgdie wgtuse 2 |
| 3652 | end |
| 3653 | ret v |
| 3654 | end |
| 3655 | |
| 3656 | note ---------------------------------------------------------------- replay and dryrun |
| 3657 | |
| 3658 | text wgtprobe "probe" |
| 3659 | text wgtfirst "first" |
| 3660 | text wgtjobs "jobs" |
| 3661 | text wgtrply "replay" |
| 3662 | text wgtREP "REPLAY mode=" |
| 3663 | text wgtrows " rows=" |
| 3664 | text wgtpas " pass=" |
| 3665 | text wgtrpas " recorded_pass=" |
| 3666 | text wgtmms " mismatches=" |
| 3667 | |
| 3668 | note kind argument i: 0 probe, 1 first, 2 jobs |
| 3669 | fn wgkind i ulong to ulong |
| 3670 | n = wdarg i |
| 3671 | o = get wgan 0 |
| 3672 | for j ulong n |
| 3673 | wgac ulong get wdab j |
| 3674 | end |
| 3675 | put wgan 0 o |
| 3676 | if wgeqt o n wgtprobe |
| 3677 | ret 0 |
| 3678 | end |
| 3679 | if wgeqt o n wgtfirst |
| 3680 | ret 1 |
| 3681 | end |
| 3682 | if wgeqt o n wgtjobs |
| 3683 | ret 2 |
| 3684 | end |
| 3685 | wgdie wgtuse 2 |
| 3686 | ret 0 |
| 3687 | end |
| 3688 | |
| 3689 | note recorded passes of wgrr[0..n) |
| 3690 | fn wgrpass n ulong to ulong |
| 3691 | c = ulong 0 |
| 3692 | for i ulong n |
| 3693 | v = wgjget get wgrr i wgtpass |
| 3694 | if ne v 0 |
| 3695 | if eq get wgjt v 3 |
| 3696 | c = add c 1 |
| 3697 | end |
| 3698 | end |
| 3699 | end |
| 3700 | ret c |
| 3701 | end |
| 3702 | |
| 3703 | note replay or replaylog (lg) with the argument layout of wgtuse |
| 3704 | fn wgreplay lg bool to int |
| 3705 | kd = wgkind 2 |
| 3706 | put wgmd 2 kd |
| 3707 | oi = ulong 5 |
| 3708 | if lg |
| 3709 | oi = 7 |
| 3710 | end |
| 3711 | if lt ulong argcnt add oi 1 |
| 3712 | wgdie wgtuse 2 |
| 3713 | end |
| 3714 | wgresk oi SOUT |
| 3715 | wgmkout |
| 3716 | if lg |
| 3717 | wgresk 5 SLOG |
| 3718 | wgargs 6 SLAB |
| 3719 | put wgmd 0 3 |
| 3720 | else |
| 3721 | wgsett SLAB wgtrply |
| 3722 | put wgmd 0 2 |
| 3723 | end |
| 3724 | st = wgargn add oi 1 1 |
| 3725 | wdpclr |
| 3726 | wdpa 3 |
| 3727 | dk = wgjfile |
| 3728 | nd = wgjrows dk st |
| 3729 | wdpclr |
| 3730 | wdpa 4 |
| 3731 | rk = wgjfile |
| 3732 | nr = wgjrec rk |
| 3733 | if ne nd nr |
| 3734 | wdoclr |
| 3735 | wdot wgtcnt |
| 3736 | wdod nd |
| 3737 | wdoc 32 |
| 3738 | wdod nr |
| 3739 | wdoc 10 |
| 3740 | wdoflush 1 |
| 3741 | ret 1 |
| 3742 | end |
| 3743 | p = ulong 0 |
| 3744 | if eq kd 2 |
| 3745 | wgsset SJL wgso SLAB wgsn SLAB |
| 3746 | wgjobs nd |
| 3747 | wgsset SLAB wgso SJL wgsn SJL |
| 3748 | wgjres nd |
| 3749 | for i ulong nd |
| 3750 | wgjcmp i |
| 3751 | end |
| 3752 | p = wgjpass nd |
| 3753 | else |
| 3754 | p = wgprobes nd |
| 3755 | end |
| 3756 | wdot wgtREP |
| 3757 | if eq kd 0 |
| 3758 | wdot wgtprobe |
| 3759 | end |
| 3760 | if eq kd 1 |
| 3761 | wdot wgtfirst |
| 3762 | end |
| 3763 | if eq kd 2 |
| 3764 | wdot wgtjobs |
| 3765 | end |
| 3766 | wdot wgtrows |
| 3767 | wdod nd |
| 3768 | wdot wgtpas |
| 3769 | wdod p |
| 3770 | wdot wgtrpas |
| 3771 | wdod wgrpass nr |
| 3772 | wdot wgtmms |
| 3773 | wdod get wgmis 0 |
| 3774 | wdoc 10 |
| 3775 | wdoflush 1 |
| 3776 | if gt get wgmis 0 0 |
| 3777 | ret 1 |
| 3778 | end |
| 3779 | ret 0 |
| 3780 | end |
| 3781 | |
| 3782 | text wgtdry "DRYRUN NOT_RUN " |
| 3783 | text wgtdenc "encode argv: " |
| 3784 | text wgtdsmp "sample argv: " |
| 3785 | text wgtdgev "geval argv: " |
| 3786 | text wgtdpr "prompts=" |
| 3787 | text wgtdbt " batches=" |
| 3788 | text wgtdby " batch0_bytes=" |
| 3789 | text wgtdsh " batch0_sha256=" |
| 3790 | text wgtdnw "DRYRUN nothing was executed or written\n" |
| 3791 | |
| 3792 | note SHA-256 of arena [o, o + n) into wdd |
| 3793 | fn wgsha o ulong n ulong to void |
| 3794 | b = new uchar 65536 0 |
| 3795 | c = new uchar 104 0 |
| 3796 | d = new uchar 32 0 |
| 3797 | sha256_init c |
| 3798 | t = ulong 0 |
| 3799 | while lt t n bound 999999 |
| 3800 | k = sub n t |
| 3801 | if gt k 65536 |
| 3802 | k = 65536 |
| 3803 | end |
| 3804 | for i ulong k |
| 3805 | put b i get wga add o add t i |
| 3806 | end |
| 3807 | sha256_update c part b 0 k |
| 3808 | t = add t k |
| 3809 | end |
| 3810 | sha256_final c d |
| 3811 | for j ulong 32 |
| 3812 | put wdd j get d j |
| 3813 | end |
| 3814 | end |
| 3815 | |
| 3816 | fn wgdline t view uchar * to void |
| 3817 | wdot wgtdry |
| 3818 | wdot t |
| 3819 | o = get wgan 0 |
| 3820 | wgkargs |
| 3821 | wgpra o sub get wgan 0 o |
| 3822 | put wgan 0 o |
| 3823 | wdoc 10 |
| 3824 | end |
| 3825 | |
| 3826 | note dryrun probe|jobs CK OUTDIR LABEL DATA: print what live mode would run for batch 0, run nothing |
| 3827 | fn wgdry to int |
| 3828 | if ne ulong argcnt 7 |
| 3829 | wgdie wgtuse 2 |
| 3830 | end |
| 3831 | kd = wgkind 2 |
| 3832 | if eq kd 1 |
| 3833 | kd = 0 |
| 3834 | end |
| 3835 | wgresk 3 SCK |
| 3836 | wgresk 4 SOUT |
| 3837 | wdpclr |
| 3838 | wdpa 6 |
| 3839 | dk = wgjfile |
| 3840 | nd = wgjrows dk 1 |
| 3841 | o = get wgan 0 |
| 3842 | for j ulong wdarg 5 |
| 3843 | wgac ulong get wdab j |
| 3844 | end |
| 3845 | if eq kd 2 |
| 3846 | wgsetf SJL o |
| 3847 | o2 = get wgan 0 |
| 3848 | wgasl SJL |
| 3849 | wgat wgtturn |
| 3850 | wgac 48 |
| 3851 | wgsetf SLAB o2 |
| 3852 | for i ulong nd |
| 3853 | put wgjst i 1 |
| 3854 | put wgjsn i 0 |
| 3855 | put wgjon i 0 |
| 3856 | put wgpo i wgprm i |
| 3857 | put wgpl i sub get wgan 0 get wgpo i |
| 3858 | end |
| 3859 | else |
| 3860 | wgsetf SLAB o |
| 3861 | for i2 ulong nd |
| 3862 | wgjsget get wgdr i2 wgtprom |
| 3863 | put wgpo i2 get wgr 3 |
| 3864 | put wgpl i2 get wgr 4 |
| 3865 | end |
| 3866 | end |
| 3867 | o3 = get wgan 0 |
| 3868 | wgasl SLAB |
| 3869 | wgat wgtbat |
| 3870 | wgac 48 |
| 3871 | wgsetf SBLD o3 |
| 3872 | cnt = nd |
| 3873 | if gt cnt 128 |
| 3874 | cnt = 128 |
| 3875 | end |
| 3876 | bo = get wgan 0 |
| 3877 | for q ulong cnt |
| 3878 | wgacp get wgpo q get wgpl q |
| 3879 | wgac 0 |
| 3880 | end |
| 3881 | bn = sub get wgan 0 bo |
| 3882 | wgsha bo bn |
| 3883 | wgkenc |
| 3884 | wgdline wgtdenc |
| 3885 | wgksmp |
| 3886 | wgdline wgtdsmp |
| 3887 | wdot wgtdry |
| 3888 | wdot wgtdpr |
| 3889 | wdod nd |
| 3890 | wdot wgtdbt |
| 3891 | wdod div add nd 127 128 |
| 3892 | wdot wgtdby |
| 3893 | wdod bn |
| 3894 | wdot wgtdsh |
| 3895 | wdohex |
| 3896 | wdoc 10 |
| 3897 | wgkgev |
| 3898 | wgdline wgtdgev |
| 3899 | wdot wgtdnw |
| 3900 | wdoflush 1 |
| 3901 | ret 0 |
| 3902 | end |
| 3903 | |
| 3904 | note ---------------------------------------------------------------- run mode (gates.py main) |
| 3905 | |
| 3906 | text wgtgst "/gates.txt" |
| 3907 | text wgtcand "candidate " |
| 3908 | text wgtcsha "candidate_sha256 " |
| 3909 | text wgtstart "start " |
| 3910 | text wgtwinl "window " |
| 3911 | text wgtaux "aux " |
| 3912 | text wgtgate "gate " |
| 3913 | text wgtendl "end " |
| 3914 | text wgtallp "GATES_PASS" |
| 3915 | text wgtnall "GATES_NOT_ALL_PASS" |
| 3916 | text wgtbudr "WINDOW_BUDGET_REACHED " |
| 3917 | text wgtg0 "latency" |
| 3918 | text wggn1 "copies" |
| 3919 | text wggn2 "screen" |
| 3920 | text wggn3 "dev_jobs" |
| 3921 | text wggn4 "regression" |
| 3922 | text wggn5 "story_w256" |
| 3923 | text wgtg6 "retention" |
| 3924 | text wgtdcopy "copy-final.json" |
| 3925 | text wgtdreg "regression.json" |
| 3926 | text wgtddev "dev-jobs.json" |
| 3927 | text wgtdret "retention-jobs.json" |
| 3928 | text wgtdscr "localization-screen.json" |
| 3929 | text wgtlb "latency-base-copy" |
| 3930 | text wgtlc "latency-candidate-copy" |
| 3931 | text wgtlbs "latency_base_s" |
| 3932 | text wgtlcs "latency_candidate_s" |
| 3933 | text wgtlbp "latency_base_copy_pass" |
| 3934 | text wgtlcp "latency_candidate_copy_pass" |
| 3935 | text wgtlscr "screen" |
| 3936 | text wgtlreg "regression" |
| 3937 | text wgtldev "dev-jobs" |
| 3938 | text wgtlret "retention-jobs" |
| 3939 | text wgtlsty "story-w256" |
| 3940 | text wgtvlog "logic=" |
| 3941 | text wgtvctl ",controls=" |
| 3942 | text wgtvpr ",pairs=" |
| 3943 | text wgtlogic "logic" |
| 3944 | text wgtpair "pair" |
| 3945 | text wgtfltk "fault" |
| 3946 | |
| 3947 | note gate names by index |
| 3948 | fn wggname g ulong to void |
| 3949 | if eq g 0 |
| 3950 | wgat wgtg0 |
| 3951 | end |
| 3952 | if eq g 1 |
| 3953 | wgat wggn1 |
| 3954 | end |
| 3955 | if eq g 2 |
| 3956 | wgat wggn2 |
| 3957 | end |
| 3958 | if eq g 3 |
| 3959 | wgat wggn3 |
| 3960 | end |
| 3961 | if eq g 4 |
| 3962 | wgat wggn4 |
| 3963 | end |
| 3964 | if eq g 5 |
| 3965 | wgat wggn5 |
| 3966 | end |
| 3967 | if eq g 6 |
| 3968 | wgat wgtg6 |
| 3969 | end |
| 3970 | end |
| 3971 | |
| 3972 | note two decimal digits of v onto the arena |
| 3973 | fn wga2 v long to void |
| 3974 | wgac add 48 ulong div v 10 |
| 3975 | wgac add 48 ulong rem v 10 |
| 3976 | end |
| 3977 | |
| 3978 | note days since 1970-01-01 to civil y, m, d in wgtm 0..2 (proleptic Gregorian) |
| 3979 | fn wgcivil days long to void |
| 3980 | z = add days 719468 |
| 3981 | era = div z 146097 |
| 3982 | doe = sub z mul era 146097 |
| 3983 | yoe = div sub add sub doe div doe 1460 div doe 36524 div doe 146096 365 |
| 3984 | y = add yoe mul era 400 |
| 3985 | doy = sub doe sub add mul 365 yoe div yoe 4 div yoe 100 |
| 3986 | mp = div add mul 5 doy 2 153 |
| 3987 | d = add sub doy div add mul 153 mp 2 5 1 |
| 3988 | m = add mp 3 |
| 3989 | if ge mp 10 |
| 3990 | m = sub mp 9 |
| 3991 | end |
| 3992 | if le m 2 |
| 3993 | y = add y 1 |
| 3994 | end |
| 3995 | put wgtm 0 y |
| 3996 | put wgtm 1 m |
| 3997 | put wgtm 2 d |
| 3998 | end |
| 3999 | |
| 4000 | note UTC now as YYYY-MM-DDTHH:MM:SSZ onto the arena |
| 4001 | fn wgutc to void |
| 4002 | s = div realns 1000000000 |
| 4003 | r = rem s 86400 |
| 4004 | wgcivil div s 86400 |
| 4005 | wgadl get wgtm 0 |
| 4006 | wgac 45 |
| 4007 | wga2 get wgtm 1 |
| 4008 | wgac 45 |
| 4009 | wga2 get wgtm 2 |
| 4010 | wgac 84 |
| 4011 | wga2 div r 3600 |
| 4012 | wgac 58 |
| 4013 | wga2 div rem r 3600 60 |
| 4014 | wgac 58 |
| 4015 | wga2 rem r 60 |
| 4016 | wgac 90 |
| 4017 | end |
| 4018 | |
| 4019 | note wdd as lowercase hex onto the arena |
| 4020 | fn wgahex to void |
| 4021 | for i ulong 32 |
| 4022 | b = ulong get wdd i |
| 4023 | h = shr b 4 |
| 4024 | l = and b 15 |
| 4025 | if lt h 10 |
| 4026 | wgac add 48 h |
| 4027 | else |
| 4028 | wgac add 87 h |
| 4029 | end |
| 4030 | if lt l 10 |
| 4031 | wgac add 48 l |
| 4032 | else |
| 4033 | wgac add 87 l |
| 4034 | end |
| 4035 | end |
| 4036 | end |
| 4037 | |
| 4038 | note append arena [o, top) to OUT/gates.txt and drop it from the arena |
| 4039 | fn wgstapp o ulong to void |
| 4040 | wdpclr |
| 4041 | wgpsl SOUT |
| 4042 | wdpt wgtgst |
| 4043 | fd = wgcreat true |
| 4044 | wgwr fd o sub get wgan 0 o |
| 4045 | c = fclose fd |
| 4046 | put wgan 0 o |
| 4047 | end |
| 4048 | |
| 4049 | note "aux KEY VALUE" with an integer value v |
| 4050 | fn wgaux t view uchar * v ulong to void |
| 4051 | o = get wgan 0 |
| 4052 | wgat wgtaux |
| 4053 | wgat t |
| 4054 | wgac 32 |
| 4055 | wgad v |
| 4056 | wgac 10 |
| 4057 | wgstapp o |
| 4058 | end |
| 4059 | |
| 4060 | note centiseconds as Python round(x, 2) repr (X.Y or X.YZ) |
| 4061 | fn wgacs cs ulong to void |
| 4062 | wgad div cs 100 |
| 4063 | wgac 46 |
| 4064 | f = rem cs 100 |
| 4065 | wgac add 48 div f 10 |
| 4066 | if ne rem f 10 0 |
| 4067 | wgac add 48 rem f 10 |
| 4068 | end |
| 4069 | end |
| 4070 | |
| 4071 | note "aux KEY X.YZ" |
| 4072 | fn wgauxs t view uchar * cs ulong to void |
| 4073 | o = get wgan 0 |
| 4074 | wgat wgtaux |
| 4075 | wgat t |
| 4076 | wgac 32 |
| 4077 | wgacs cs |
| 4078 | wgac 10 |
| 4079 | wgstapp o |
| 4080 | end |
| 4081 | |
| 4082 | note record gate g: value is arena [vo, top); prints "NAME VALUE PASS|FAIL" and appends the gate line |
| 4083 | fn wggate g ulong vo ulong ok bool to void |
| 4084 | vn = sub get wgan 0 vo |
| 4085 | o = get wgan 0 |
| 4086 | wggname g |
| 4087 | wgac 32 |
| 4088 | wgacp vo vn |
| 4089 | wgac 32 |
| 4090 | if ok |
| 4091 | wgat wgtPASS |
| 4092 | put wgg g 1 |
| 4093 | else |
| 4094 | wgat wgtFAIL |
| 4095 | put wgg g 2 |
| 4096 | end |
| 4097 | wgac 10 |
| 4098 | wdoclr |
| 4099 | for i ulong sub get wgan 0 o |
| 4100 | wdoc ulong get wga add o i |
| 4101 | end |
| 4102 | wdoflush 1 |
| 4103 | o2 = get wgan 0 |
| 4104 | wgat wgtgate |
| 4105 | wgacp o sub sub o2 o 1 |
| 4106 | wgac 32 |
| 4107 | wgasl SWIN |
| 4108 | wgac 32 |
| 4109 | wgutc |
| 4110 | wgac 10 |
| 4111 | wgstapp o2 |
| 4112 | put wgan 0 vo |
| 4113 | end |
| 4114 | |
| 4115 | note load ROUND40/data/NAME rows (stride 1); returns the row count |
| 4116 | fn wgdata t view uchar * to ulong |
| 4117 | wdpclr |
| 4118 | wdpt wgtr40d |
| 4119 | wdpt t |
| 4120 | k = wgjfile |
| 4121 | n = wgjrows k 1 |
| 4122 | ret n |
| 4123 | end |
| 4124 | |
| 4125 | note one probes() run; returns the pass count |
| 4126 | fn wgprun lab view uchar * kd ulong n ulong to ulong |
| 4127 | wgsett SLAB lab |
| 4128 | put wgmd 2 kd |
| 4129 | c = wgprobes n |
| 4130 | ret c |
| 4131 | end |
| 4132 | |
| 4133 | note task 0: latency + copies (both checkpoints sample copy-final) |
| 4134 | fn wgtlat to void |
| 4135 | n = wgdata wgtdcopy |
| 4136 | wgsett SCK wgtbase |
| 4137 | t0 = monons |
| 4138 | cb = wgprun wgtlb 0 n |
| 4139 | bcs = ulong div add sub monons t0 5000000 10000000 |
| 4140 | put wgsl add mul SCK 2 0 wgso SCAND |
| 4141 | put wgsl add mul SCK 2 1 wgsn SCAND |
| 4142 | t1 = monons |
| 4143 | cc = wgprun wgtlc 0 n |
| 4144 | ccs = ulong div add sub monons t1 5000000 10000000 |
| 4145 | wgauxs wgtlbs bcs |
| 4146 | wgauxs wgtlcs ccs |
| 4147 | wgaux wgtlbp cb |
| 4148 | wgaux wgtlcp cc |
| 4149 | if eq bcs 0 |
| 4150 | wgdie wgtzero 70 |
| 4151 | end |
| 4152 | vo = get wgan 0 |
| 4153 | wgratio ccs bcs |
| 4154 | wggate 0 vo le mul ccs 100 mul bcs 102 |
| 4155 | vo2 = get wgan 0 |
| 4156 | wgad cc |
| 4157 | wggate 1 vo2 eq cc 64 |
| 4158 | end |
| 4159 | |
| 4160 | note round(c / b, 4) in Python float repr onto the arena (half up on the fifth digit) |
| 4161 | fn wgratio c ulong b ulong to void |
| 4162 | v = div add mul c 20000 b mul b 2 |
| 4163 | wgad div v 10000 |
| 4164 | wgac 46 |
| 4165 | f = rem v 10000 |
| 4166 | if eq f 0 |
| 4167 | wgac 48 |
| 4168 | ret |
| 4169 | end |
| 4170 | k = ulong 1000 |
| 4171 | while gt f 0 bound 8 |
| 4172 | wgac add 48 div f k |
| 4173 | f = rem f k |
| 4174 | k = div k 10 |
| 4175 | end |
| 4176 | end |
| 4177 | |
| 4178 | fn wgtscr to void |
| 4179 | n = wgdata wgtdscr |
| 4180 | put wgsl add mul SCK 2 0 wgso SCAND |
| 4181 | put wgsl add mul SCK 2 1 wgsn SCAND |
| 4182 | c = wgprun wgtlscr 1 n |
| 4183 | vo = get wgan 0 |
| 4184 | wgad c |
| 4185 | wggate 2 vo eq c 8 |
| 4186 | end |
| 4187 | |
| 4188 | fn wgtreg to void |
| 4189 | n = wgdata wgtdreg |
| 4190 | put wgsl add mul SCK 2 0 wgso SCAND |
| 4191 | put wgsl add mul SCK 2 1 wgsn SCAND |
| 4192 | c = wgprun wgtlreg 0 n |
| 4193 | vo = get wgan 0 |
| 4194 | wgad c |
| 4195 | wggate 4 vo eq c 685 |
| 4196 | end |
| 4197 | |
| 4198 | fn wgtsty to void |
| 4199 | put wgsl add mul SCK 2 0 wgso SCAND |
| 4200 | put wgsl add mul SCK 2 1 wgsn SCAND |
| 4201 | wgsett SLOG wgtlsty |
| 4202 | v = wgscore |
| 4203 | vo = get wgan 0 |
| 4204 | wgad v |
| 4205 | wggate 5 vo le mul v 10000 mul ulong 1190843 10025 |
| 4206 | end |
| 4207 | |
| 4208 | note jobs over ROUND40/data/NAME under label lab; returns the job count |
| 4209 | fn wgtjrun t view uchar * lab view uchar * to ulong |
| 4210 | n = wgdata t |
| 4211 | put wgsl add mul SCK 2 0 wgso SCAND |
| 4212 | put wgsl add mul SCK 2 1 wgsn SCAND |
| 4213 | wgsett SJL lab |
| 4214 | put wgmd 2 2 |
| 4215 | wgjobs n |
| 4216 | wgsett SLAB lab |
| 4217 | wgjres n |
| 4218 | ret n |
| 4219 | end |
| 4220 | |
| 4221 | note job i passes and its pair value equals job j's (same JSON type and text) |
| 4222 | fn wgpaireq i ulong j ulong to bool |
| 4223 | a = wgjget get wgdr i wgtpair |
| 4224 | b = wgjget get wgdr j wgtpair |
| 4225 | if or eq a 0 eq b 0 |
| 4226 | ret false |
| 4227 | end |
| 4228 | if ne get wgjt a get wgjt b |
| 4229 | ret false |
| 4230 | end |
| 4231 | ret wgeq2 get wgjo a get wgjl a get wgjo b get wgjl b |
| 4232 | end |
| 4233 | |
| 4234 | fn wgtdev to void |
| 4235 | n = wgtjrun wgtddev wgtldev |
| 4236 | lg = ulong 0 |
| 4237 | ct = ulong 0 |
| 4238 | for i ulong n |
| 4239 | if eq get wgjps i 1 |
| 4240 | if wgjis get wgdr i wgtfltk wgtlogic |
| 4241 | lg = add lg 1 |
| 4242 | else |
| 4243 | ct = add ct 1 |
| 4244 | end |
| 4245 | end |
| 4246 | end |
| 4247 | pr = wgpairs n |
| 4248 | vo = get wgan 0 |
| 4249 | wgat wgtvlog |
| 4250 | wgad lg |
| 4251 | wgat wgtvctl |
| 4252 | wgad ct |
| 4253 | wgat wgtvpr |
| 4254 | wgad pr |
| 4255 | wggate 3 vo and ge lg 72 and ge ct 12 ge pr 24 |
| 4256 | end |
| 4257 | |
| 4258 | note distinct pair values whose jobs all pass |
| 4259 | fn wgpairs n ulong to ulong |
| 4260 | pr = ulong 0 |
| 4261 | for i ulong n |
| 4262 | if eq wgjget get wgdr i wgtpair 0 |
| 4263 | continue |
| 4264 | end |
| 4265 | fst = true |
| 4266 | alp = true |
| 4267 | for j ulong n |
| 4268 | if wgpaireq i j |
| 4269 | if lt j i |
| 4270 | fst = false |
| 4271 | end |
| 4272 | if ne get wgjps j 1 |
| 4273 | alp = false |
| 4274 | end |
| 4275 | end |
| 4276 | end |
| 4277 | if and fst alp |
| 4278 | pr = add pr 1 |
| 4279 | end |
| 4280 | end |
| 4281 | ret pr |
| 4282 | end |
| 4283 | |
| 4284 | fn wgtret to void |
| 4285 | n = wgtjrun wgtdret wgtlret |
| 4286 | c = wgjpass n |
| 4287 | vo = get wgan 0 |
| 4288 | wgad c |
| 4289 | wggate 6 vo eq c 847 |
| 4290 | end |
| 4291 | |
| 4292 | note read OUT/gates.txt: gate results into wgg, candidate sha checked against arena [ho, ho + 64) |
| 4293 | fn wgstread ho ulong to void |
| 4294 | wdpclr |
| 4295 | wgpsl SOUT |
| 4296 | wdpt wgtgst |
| 4297 | if not wgexist |
| 4298 | ret |
| 4299 | end |
| 4300 | o = wgload |
| 4301 | e = get wgan 0 |
| 4302 | p = o |
| 4303 | while lt p e bound 999999 |
| 4304 | q = wgeol p e |
| 4305 | nx = get wgr 2 |
| 4306 | if wgsw p sub q p wgtcsha |
| 4307 | if or ne sub q p 81 not wgeqa add p 17 ho 64 |
| 4308 | wgdie wgtcsm 5 |
| 4309 | end |
| 4310 | end |
| 4311 | if wgsw p sub q p wgtgate |
| 4312 | wgstg add p 5 sub q add p 5 |
| 4313 | end |
| 4314 | p = nx |
| 4315 | end |
| 4316 | put wgan 0 o |
| 4317 | end |
| 4318 | |
| 4319 | note "NAME VALUE PASS|FAIL ..." at (o, n): set wgg |
| 4320 | fn wgstg o ulong n ulong to void |
| 4321 | s1 = wgfindt o n wgtsp |
| 4322 | if eq s1 WGNO |
| 4323 | ret |
| 4324 | end |
| 4325 | for g ulong 7 |
| 4326 | m = get wgan 0 |
| 4327 | wggname g |
| 4328 | gl = sub get wgan 0 m |
| 4329 | eqn = wgeq2 o s1 m gl |
| 4330 | put wgan 0 m |
| 4331 | if eqn |
| 4332 | r = add add o s1 1 |
| 4333 | rn = sub n add s1 1 |
| 4334 | s2 = wgfindt r rn wgtsp |
| 4335 | if ne s2 WGNO |
| 4336 | if wgsw add add r s2 1 sub rn add s2 1 wgtPASS |
| 4337 | put wgg g 1 |
| 4338 | else |
| 4339 | put wgg g 2 |
| 4340 | end |
| 4341 | end |
| 4342 | end |
| 4343 | end |
| 4344 | end |
| 4345 | |
| 4346 | note estimate in seconds of task k (gates.py TASKS) |
| 4347 | fn wgest k ulong to ulong |
| 4348 | if eq k 0 |
| 4349 | ret 150 |
| 4350 | end |
| 4351 | if eq k 1 |
| 4352 | ret 60 |
| 4353 | end |
| 4354 | if eq k 2 |
| 4355 | ret 400 |
| 4356 | end |
| 4357 | if eq k 3 |
| 4358 | ret 150 |
| 4359 | end |
| 4360 | if eq k 4 |
| 4361 | ret 40 |
| 4362 | end |
| 4363 | ret 700 |
| 4364 | end |
| 4365 | |
| 4366 | note gate index that marks task k done (latency task records gates 0 and 1) |
| 4367 | fn wgtg k ulong to ulong |
| 4368 | if eq k 0 |
| 4369 | ret 1 |
| 4370 | end |
| 4371 | if eq k 1 |
| 4372 | ret 2 |
| 4373 | end |
| 4374 | if eq k 2 |
| 4375 | ret 3 |
| 4376 | end |
| 4377 | if eq k 3 |
| 4378 | ret 4 |
| 4379 | end |
| 4380 | if eq k 4 |
| 4381 | ret 5 |
| 4382 | end |
| 4383 | ret 6 |
| 4384 | end |
| 4385 | |
| 4386 | fn wgtask k ulong to void |
| 4387 | if eq k 0 |
| 4388 | wgtlat |
| 4389 | end |
| 4390 | if eq k 1 |
| 4391 | wgtscr |
| 4392 | end |
| 4393 | if eq k 2 |
| 4394 | wgtdev |
| 4395 | end |
| 4396 | if eq k 3 |
| 4397 | wgtreg |
| 4398 | end |
| 4399 | if eq k 4 |
| 4400 | wgtsty |
| 4401 | end |
| 4402 | if eq k 5 |
| 4403 | wgtret |
| 4404 | end |
| 4405 | end |
| 4406 | |
| 4407 | fn wganyf to bool |
| 4408 | for g ulong 7 |
| 4409 | if eq get wgg g 2 |
| 4410 | ret true |
| 4411 | end |
| 4412 | end |
| 4413 | ret false |
| 4414 | end |
| 4415 | |
| 4416 | note WSP_BUDGET seconds (default 1080; digits only) |
| 4417 | fn wgbudget to ulong |
| 4418 | if not wdenv wgtbud |
| 4419 | ret 1080 |
| 4420 | end |
| 4421 | n = get wdvn 0 |
| 4422 | if eq n 0 |
| 4423 | wgdie wgtbudb 2 |
| 4424 | end |
| 4425 | v = ulong 0 |
| 4426 | for i ulong n |
| 4427 | c = ulong get wdv i |
| 4428 | if not wgdig c |
| 4429 | wgdie wgtbudb 2 |
| 4430 | end |
| 4431 | v = add mul v 10 sub c 48 |
| 4432 | end |
| 4433 | ret v |
| 4434 | end |
| 4435 | |
| 4436 | fn wgrunm to int |
| 4437 | t0 = monons |
| 4438 | if ne ulong argcnt 4 |
| 4439 | wgdie wgtuse 2 |
| 4440 | end |
| 4441 | wgrwin |
| 4442 | bud = wgbudget |
| 4443 | wgresk 3 SOUT |
| 4444 | wgresk 2 SCAND |
| 4445 | wgmkout |
| 4446 | put wgmd 0 1 |
| 4447 | wgrhead |
| 4448 | mk = get wgan 0 |
| 4449 | for k ulong 6 |
| 4450 | if wganyf |
| 4451 | break |
| 4452 | end |
| 4453 | if ne get wgg wgtg k 0 |
| 4454 | continue |
| 4455 | end |
| 4456 | el = ulong div sub monons t0 1000000000 |
| 4457 | if gt add el wgest k bud |
| 4458 | wdoclr |
| 4459 | wdot wgtbudr |
| 4460 | wdod el |
| 4461 | wdoc 10 |
| 4462 | wdoflush 1 |
| 4463 | ret 10 |
| 4464 | end |
| 4465 | put wgan 0 mk |
| 4466 | put wgjn 0 0 |
| 4467 | wgtask k |
| 4468 | end |
| 4469 | wgrfin |
| 4470 | ret 0 |
| 4471 | end |
| 4472 | |
| 4473 | note SPARK_WINDOW into slot SWIN; exit 3 when it is missing or empty |
| 4474 | fn wgrwin to void |
| 4475 | if not wdenv wgtsw |
| 4476 | wgdie wgtrefu 3 |
| 4477 | end |
| 4478 | if eq get wdvn 0 0 |
| 4479 | wgdie wgtrefu 3 |
| 4480 | end |
| 4481 | o = get wgan 0 |
| 4482 | for i ulong get wdvn 0 |
| 4483 | wgac ulong get wdv i |
| 4484 | end |
| 4485 | wgsetf SWIN o |
| 4486 | end |
| 4487 | |
| 4488 | note base and candidate sha256, resume state, and the header lines of gates.txt |
| 4489 | fn wgrhead to void |
| 4490 | wdpclr |
| 4491 | wdpt wgtbase |
| 4492 | if not wdfsha |
| 4493 | wgdiep wgtfile 71 |
| 4494 | end |
| 4495 | if not wdhexeq wgtbsha |
| 4496 | wdpclr |
| 4497 | wdpt wgtbase |
| 4498 | wgdiep wgtbsm 4 |
| 4499 | end |
| 4500 | wdpclr |
| 4501 | wgpsl SCAND |
| 4502 | if not wdfsha |
| 4503 | wgdiep wgtfile 71 |
| 4504 | end |
| 4505 | ho = get wgan 0 |
| 4506 | wgahex |
| 4507 | wgstread ho |
| 4508 | wdpclr |
| 4509 | wgpsl SOUT |
| 4510 | wdpt wgtgst |
| 4511 | frs = not wgexist |
| 4512 | o2 = get wgan 0 |
| 4513 | if frs |
| 4514 | wgat wgtcand |
| 4515 | wgasl SCAND |
| 4516 | wgac 10 |
| 4517 | wgat wgtcsha |
| 4518 | wgacp ho 64 |
| 4519 | wgac 10 |
| 4520 | wgat wgtstart |
| 4521 | wgutc |
| 4522 | wgac 10 |
| 4523 | end |
| 4524 | wgat wgtwinl |
| 4525 | wgasl SWIN |
| 4526 | wgac 10 |
| 4527 | wgstapp o2 |
| 4528 | end |
| 4529 | |
| 4530 | note the end line and the verdict (GATES_PASS when all 7 gates passed) |
| 4531 | fn wgrfin to void |
| 4532 | alp = true |
| 4533 | for g ulong 7 |
| 4534 | if ne get wgg g 1 |
| 4535 | alp = false |
| 4536 | end |
| 4537 | end |
| 4538 | o3 = get wgan 0 |
| 4539 | wgat wgtendl |
| 4540 | wgutc |
| 4541 | wgac 32 |
| 4542 | vo = get wgan 0 |
| 4543 | if alp |
| 4544 | wgat wgtallp |
| 4545 | else |
| 4546 | wgat wgtnall |
| 4547 | end |
| 4548 | wgac 10 |
| 4549 | wdoclr |
| 4550 | for j ulong sub get wgan 0 vo |
| 4551 | wdoc ulong get wga add vo j |
| 4552 | end |
| 4553 | wdoflush 1 |
| 4554 | wgstapp o3 |
| 4555 | end |
| 4556 | |
| 4557 | note ---------------------------------------------------------------- entry |
| 4558 | |
| 4559 | text wgtrunm "run" |
| 4560 | text wgtrlog "replaylog" |
| 4561 | text wgtdryr "dryrun" |
| 4562 | |
| 4563 | fn main to int |
| 4564 | put wgan 0 0 |
| 4565 | put wgjn 0 0 |
| 4566 | put wgobf 0 1 |
| 4567 | put wgxr 0 WGABS |
| 4568 | put wgxr 1 WGABS |
| 4569 | if lt ulong argcnt 2 |
| 4570 | wgdie wgtuse 2 |
| 4571 | end |
| 4572 | n = wdarg 1 |
| 4573 | o = get wgan 0 |
| 4574 | for j ulong n |
| 4575 | wgac ulong get wdab j |
| 4576 | end |
| 4577 | put wgan 0 o |
| 4578 | r = int 2 |
| 4579 | if wgeqt o n wgtrunm |
| 4580 | r = wgrunm |
| 4581 | ret r |
| 4582 | end |
| 4583 | if wgeqt o n wgtrply |
| 4584 | r = wgreplay false |
| 4585 | ret r |
| 4586 | end |
| 4587 | if wgeqt o n wgtrlog |
| 4588 | r = wgreplay true |
| 4589 | ret r |
| 4590 | end |
| 4591 | if wgeqt o n wgtdryr |
| 4592 | r = wgdry |
| 4593 | ret r |
| 4594 | end |
| 4595 | wgdie wgtuse 2 |
| 4596 | ret r |
| 4597 | end |