Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/seed/node/tests/tool-replay.om # omega-mv Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance. Brought by drakestapleton Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / seed / node / tests / tool-replay.om` 1117 lines ยท 28846 bytes Raw Blame History 1 note seed/node/tests/tool-replay.om: replay the round-40 tool transcripts through the Omega Node tool 2 note and compare every next prompt byte for byte (the seeded-Omega port of tool-replay.py). 3 note Build: { printf 'om2\n'; cat seed/json/json.om seed/node/tests/drv.om seed/node/tests/tool-replay.om; } 4 note | seed/out/omc > build/node/tool-replay 5 note Usage: tool-replay TOOL OMC ROUND40 OUTDIR. Reads ROUND40/final-selected.json (a list of runs). 6 note Per run: OUTDIR/ is removed, ROOT/dirname(job.path) and ROOT/.work made, job.broken written 7 note to ROOT/job.path unless job.fault is "missing". For every turn but the last the turn's raw answer 8 note is cut at the first "\nDone.", stripped (Python str.strip whitespace) and parsed as JSON; its tool 9 note runs as one TOOL process (read_file: read ROOT PATH; omega_check: check ROOT PATH ROOT/.work OMC 10 note KIND K N A with KIND add 1, mul 2, loop 3 and N job.n or 0; any other tool: replace ROOT PATH OLD 11 note NEW), stdout captured to OUTDIR/.tool-replay.out, stderr to /dev/null, 120 s deadline. Exit 0 gives 12 note the OMNT1 record (status, observation, content; content dropped for status 1); another exit gives 13 note status None and observation "exit N" (N = -signal for a signal). The rebuilt repair.py prompt 14 note (Task, File, Goal, State, Source, Tool result, Answer) must equal the next turn's prompt; the 15 note first difference prints "MISMATCH id fault tool status ST REPR" and " want REPR" (Python repr, 16 note first and last 200 code points) and fails the run. Summary: TOOL-REPLAY runs= pass= fail= 17 note actions=; exit 0 when no run failed, 1 otherwise, 2 for bad usage or an unreadable fixture. 18 note Where tool-replay.py would have raised (missing or mistyped fixture field, style outside 0..50, 19 note non-integer number, tool timeout, malformed OMNT1 record, field over its buffer), this driver 20 note fails the run instead: an "ERROR id step" line, or a MISMATCH with status None and observation 21 note "timeout", "malformed record" or "spawn error". A job id that is empty, ".", ".." or holds '/' 22 note is refused (ERROR) so OUTDIR/ is always a direct child of OUTDIR. repr approximation: code 23 note points U+0080..U+00A0 and U+00AD print as \xNN, every other non-ASCII code point raw. 24 note Buffers: raw answer 8192 bytes, prompt and tool stdout 16384, id 1024, path 3072, fault 1024, 25 note tool name 1024, broken 6144, any path 4095. 26 note ba (32768 bytes): TOOL 0, OMC 4096, OUTDIR 8192, ROOT 12288, WORK 16384, capture file 20480, 27 note prompt head 24576, fixture path 28672; their lengths in tra[0..7]. 28 note bj (16384 bytes): id 0, path 1024, fault 4096, tool name 5120, broken 6144, packed argv 12288; 29 note lengths tra-style in trb: [0] id, [1] path, [2] fault, [3] broken, [4] tool name, [5] broken set. 30 31 global tra ulong 8 32 global trb ulong 8 33 note trv: [0] style, [1] kind code (1 add, 2 mul, 3 loop, 0 other), [2] k, [3] n, [4] a, [5] n given. 34 global trv long 8 35 note trs: [0] status (dvnone = None), [1] obs offset, [2] obs length, [3] content offset, 36 note [4] content length, [5] next-turn token, [6] packed argv length. 37 global trs ulong 8 38 note trn: [0] runs, [1] passed runs, [2] failed runs, [3] tool actions. 39 global trn ulong 4 40 41 text trkjob "job" 42 text trkid "id" 43 text trkpath "path" 44 text trkflt "fault" 45 text trkkind "kind" 46 text trkstyl "style" 47 text trkk "k" 48 text trkn "n" 49 text trka "a" 50 text trkbrok "broken" 51 text trkturn "turns" 52 text trkraw "raw" 53 text trkstat "state" 54 text trkprom "prompt" 55 text trktool "tool" 56 text trkold "old" 57 text trknew "new" 58 text trmiss "missing" 59 text trrf "read_file" 60 text troc "omega_check" 61 text trcread "read" 62 text trcrepl "replace" 63 text trcchk "check" 64 text trloop "loop" 65 text tradd "add" 66 text trmul "mul" 67 text trdone "\nDone." 68 text trwork ".work" 69 text trcap ".tool-replay.out" 70 text trsel "/final-selected.json" 71 text trnull "/dev/null" 72 text trmagic "OMNT1" 73 text trtask "Task: " 74 text trfile "\nFile: " 75 text trgoal "\nGoal: " 76 text trstate "\nState: " 77 text trg1 "calc starts with x and adds " 78 text trg2 " exactly " 79 text trg3 " times in a for loop. main calls calc with " 80 text trg4 "calc returns x " 81 text trplus "plus " 82 text trtimes "times " 83 text trg5 ". main calls calc with " 84 text trdot "." 85 text trsrc "Source:\n" 86 text trres "Tool result: " 87 text trans "Answer:\n" 88 text trmis "MISMATCH " 89 text trstw " status " 90 text trnone "None" 91 text trwant " want " 92 text trsum1 "TOOL-REPLAY runs=" 93 text trsum2 " pass=" 94 text trsum3 " fail=" 95 text trsum4 " actions=" 96 text trexit "exit " 97 text trtmo "timeout" 98 text trbadr "malformed record" 99 text trspawn "spawn error" 100 text trerr "ERROR " 101 text trejob "job fields" 102 text trepath "paths" 103 text tretree "tree setup" 104 text treturn "turns" 105 text treraw "raw" 106 text trejson "raw json" 107 text tretool "tool" 108 text treargv "arguments" 109 text trewant "next prompt" 110 text treload "tool-replay: cannot load ROUND40/final-selected.json\n" 111 text trusage "usage: tool-replay TOOL OMC ROUND40 OUTDIR\n" 112 note trsty1, trsty2: repair.py STYLES 0..25 and 26..50, one per line. 113 text trsty1 "Repair this Omega file and verify it.\nUse tools to fix this Omega program, then test it.\nCheck this Omega file, correct any fault and confirm the result.\nPlease get this Omega file working according to its goal and check your work.\nInvestigate this Omega file and make its behavior match the goal.\nDiagnose this Omega file, repair it as needed, and verify the result.\nRepair the calculation in this Omega file and verify the result.\nFind and repair the mistake in this Omega file, then confirm its behavior.\nMake this Omega file satisfy its stated goal and verify the repaired result.\nFix this Omega file.\nCheck and repair the Omega program.\nMake the program match its goal and test it.\nUse tools to repair the file and check it.\nFind the wrong calculation, fix it, and test it.\nInspect this program and fix the error.\nRead the file, check it, repair it, and test again.\nPlease correct the Omega calculation and verify it.\nRepair this file to meet the stated goal.\nWork through this Omega repair and check the result.\nCheck this Omega file, find the error, repair it and verify the result.\nPlease inspect this Omega program to repair the calculation and verify the result.\nUse the goal to fix this Omega file and verify the changes.\nPlease repair this Omega program to do what the goal asks.\nGet this Omega file to match the goal, then check the result.\nPlease carefully repair the calculation using tools and confirm that the tests pass.\nPlease carefully examine this Omega file and repair any calculation that does not match its goal.\n" 114 text trsty2 "Find the incorrect behavior in this Omega file, fix it, and test the result.\nInspect and repair this Omega file, then verify it.\nCorrect this Omega program according to its goal.\nFix the error in this Omega program and check the result.\nCheck this file and repair it to meet its goal.\nPlease fix this program to match its goal.\nCorrect the calculation in this Omega file.\nRead this program and repair its calculation.\nPlease check the code and fix the mistake.\nRepair the program according to the stated goal.\nUse the goal to correct this Omega calculation.\nFix the calculation and test the corrected program.\nPlease inspect the file and correct the error.\nCheck the calculation, make the repair, and verify it.\nMake this file behave as the goal describes.\nPlease correct this program and check your work.\nRepair this calculation, then confirm the result.\nRepair this file and confirm it meets the goal.\nCheck the Omega program and correct its calculation.\nInspect this file, fix its calculation, and verify it.\nMake this Omega program meet the goal, then test it.\nRepair the file and verify its goal.\nCheck the code, repair its fault, and test it.\nFix the error in this file and confirm its goal.\nInspect the code and repair it to satisfy the goal.\n" 115 116 note ======== Python str.strip whitespace and repr 117 118 note tr_cpn c: the byte length of the UTF-8 sequence led by c (1 for ASCII or a stray byte). 119 fn tr_cpn c uchar to ulong 120 if lt c 192 121 ret 1 122 end 123 if lt c 224 124 ret 2 125 end 126 if lt c 240 127 ret 3 128 end 129 if lt c 248 130 ret 4 131 end 132 ret 1 133 end 134 135 note tr_cp b i k: the code point of the k-byte (2..4) UTF-8 sequence at b[i]. 136 fn tr_cp b view uchar 8192 i ulong k ulong to ulong 137 c = and ulong get b i shr 127 k 138 j = ulong 1 139 while lt j k bound 4 140 d = and ulong get b add i j 63 141 c = or shl c 6 d 142 j = add j 1 143 end 144 ret c 145 end 146 147 note tr_uws cp: whether non-ASCII code point cp is Python whitespace (str.isspace). 148 fn tr_uws cp ulong to bool 149 if or eq cp 133 eq cp 160 150 ret true 151 end 152 if eq cp 5760 153 ret true 154 end 155 if and ge cp 8192 le cp 8202 156 ret true 157 end 158 if or eq cp 8232 eq cp 8233 159 ret true 160 end 161 if or eq cp 8239 eq cp 8287 162 ret true 163 end 164 ret eq cp 12288 165 end 166 167 note tr_aws c: whether byte c is ASCII Python whitespace (\t \n \v \f \r, 0x1c..0x1f, space). 168 fn tr_aws c uchar to bool 169 ret or and ge c 9 le c 13 or eq c 32 and ge c 28 le c 31 170 end 171 172 note tr_wsat b i e: the byte length of the whitespace code point at b[i] (ending by e), or 0. 173 fn tr_wsat b view uchar 8192 i ulong e ulong to ulong 174 c = get b i 175 if tr_aws c 176 ret 1 177 end 178 k = tr_cpn c 179 if eq k 1 180 ret 0 181 end 182 if gt add i k e 183 ret 0 184 end 185 if tr_uws tr_cp b i k 186 ret k 187 end 188 ret 0 189 end 190 191 note tr_wsend b s e: the byte length of the whitespace code point ending at b[e] (e > s), or 0. 192 fn tr_wsend b view uchar 8192 s ulong e ulong to ulong 193 c = get b sub e 1 194 if lt c 128 195 if tr_aws c 196 ret 1 197 end 198 ret 0 199 end 200 j = sub e 1 201 while gt j s bound 4 202 d = get b j 203 if or lt d 128 gt d 191 204 break 205 end 206 if ge sub e j 4 207 break 208 end 209 j = sub j 1 210 end 211 k = tr_cpn get b j 212 if eq k 1 213 ret 0 214 end 215 if ne add j k e 216 ret 0 217 end 218 if tr_uws tr_cp b j k 219 ret k 220 end 221 ret 0 222 end 223 224 note tr_text rb n ib: raw.split('\nDone.')[0].strip() of rb[0, n) copied to ib[0, ..); its length. 225 fn tr_text rb view uchar 8192 n ulong ib edit uchar 8192 to ulong 226 e = dv_find part rb 0 n trdone 0 227 if eq e dvnone 228 e = n 229 end 230 s = ulong 0 231 while lt s e bound 8193 232 k = tr_wsat rb s e 233 if eq k 0 234 break 235 end 236 s = add s k 237 end 238 while gt e s bound 8193 239 k = tr_wsend rb s e 240 if eq k 0 241 break 242 end 243 e = sub e k 244 end 245 q = dv_cat ib 0 part rb s sub e s 246 ret sub e s 247 end 248 249 note tr_quote b: the quote Python repr uses for b: '"' when b holds a ' and no ", else '. 250 fn tr_quote b view uchar * to uchar 251 s1 = false 252 d1 = false 253 for i ulong len b 254 c = get b i 255 if eq c 39 256 s1 = true 257 end 258 if eq c 34 259 d1 = true 260 end 261 end 262 if and s1 not d1 263 ret 34 264 end 265 ret 39 266 end 267 268 note tr_rlen b i: the input bytes one repr step consumes at b[i] (a whole UTF-8 sequence). 269 fn tr_rlen b view uchar * i ulong to ulong 270 c = get b i 271 if lt c 128 272 ret 1 273 end 274 k = tr_cpn c 275 if gt k sub len b i 276 ret 1 277 end 278 ret k 279 end 280 281 note tr_hex t w c: "\xNN" (lower-case hex of c) at t[w]; w + 4. 282 fn tr_hex t edit uchar 65600 w ulong c uchar to ulong 283 put t w 92 284 put t add w 1 120 285 h = shr c 4 286 l = and c 15 287 if lt h 10 288 put t add w 2 add h 48 289 else 290 put t add w 2 add h 87 291 end 292 if lt l 10 293 put t add w 3 add l 48 294 else 295 put t add w 3 add l 87 296 end 297 ret add w 4 298 end 299 300 note tr_esc t w c: a backslash and c at t[w]; w + 2. 301 fn tr_esc t edit uchar 65600 w ulong c uchar to ulong 302 put t w 92 303 put t add w 1 c 304 ret add w 2 305 end 306 307 note tr_r1 t w b i q: the repr of the code point at b[i] (quote q) written at t[w]; the new w. 308 fn tr_r1 t edit uchar 65600 w ulong b view uchar * i ulong q uchar to ulong 309 c = get b i 310 if or eq c 92 eq c q 311 ret tr_esc t w c 312 end 313 if eq c 9 314 ret tr_esc t w 116 315 end 316 if eq c 10 317 ret tr_esc t w 110 318 end 319 if eq c 13 320 ret tr_esc t w 114 321 end 322 if or lt c 32 eq c 127 323 ret tr_hex t w c 324 end 325 if lt c 128 326 put t w c 327 ret add w 1 328 end 329 k = tr_rlen b i 330 if eq k 2 331 if eq c 194 332 d = get b add i 1 333 if or le d 160 eq d 173 334 ret tr_hex t w d 335 end 336 end 337 end 338 for j ulong k 339 put t add w j get b add i j 340 end 341 ret add w k 342 end 343 344 note tr_rfull t b: Python repr of the string b (UTF-8) written to t[0, ..); its length. 345 fn tr_rfull t edit uchar 65600 b view uchar * to ulong 346 q = tr_quote b 347 put t 0 q 348 w = ulong 1 349 i = ulong 0 350 while lt i len b bound `16777217` 351 w = tr_r1 t w b i q 352 i = add i tr_rlen b i 353 end 354 put t w q 355 ret add w 1 356 end 357 358 note tr_rcut t n lim: the byte length of the first lim code points of t[0, n). 359 fn tr_rcut t view uchar 65600 n ulong lim ulong to ulong 360 c = ulong 0 361 i = ulong 0 362 while lt i n bound 65601 363 d = get t i 364 if or lt d 128 gt d 191 365 if eq c lim 366 ret i 367 end 368 c = add c 1 369 end 370 i = add i 1 371 end 372 ret n 373 end 374 375 note tr_repr o p b lim: repr(b)[:lim] appended at o[p] (dv_cat rules); the new end or dvnone. 376 note b is at most 16384 bytes. 377 fn tr_repr o edit uchar * p ulong b view uchar * lim ulong to ulong 378 t = new uchar 65600 0 379 n = tr_rfull t b 380 m = tr_rcut t n lim 381 ret dv_cat o p view part t 0 m 382 end 383 384 note tr_back b n k: the start of the last k code points of b[0, n) (0 when fewer). 385 fn tr_back b view uchar 16384 n ulong k ulong to ulong 386 i = n 387 c = ulong 0 388 while gt i 0 bound 16385 389 i = sub i 1 390 d = get b i 391 if or lt d 128 gt d 191 392 c = add c 1 393 if eq c k 394 ret i 395 end 396 end 397 end 398 ret 0 399 end 400 401 note ======== the job and its prompt head 402 403 note tr_line o p t k: line k of the newline-terminated lines t appended at o[p]; the end or dvnone. 404 fn tr_line o edit uchar * p ulong t view uchar * k ulong to ulong 405 i = ulong 0 406 c = ulong 0 407 s = ulong 0 408 while lt i len t bound 4096 409 if eq get t i 10 410 if eq c k 411 ret dv_cat o p part t s sub i s 412 end 413 c = add c 1 414 s = add i 1 415 end 416 i = add i 1 417 end 418 ret dvnone 419 end 420 421 note tr_style o p: STYLES[job.style] appended at o[p]; dvnone for a style outside 0..50. 422 fn tr_style o edit uchar * p ulong to ulong 423 s = get trv 0 424 if or lt s 0 gt s 50 425 ret dvnone 426 end 427 if lt s 26 428 ret tr_line o p trsty1 ulong s 429 end 430 ret tr_line o p trsty2 sub ulong s 26 431 end 432 433 note tr_goal o p: repair.py goal(job) appended at o[p]; the end or dvnone. 434 fn tr_goal o edit uchar * p ulong to ulong 435 if eq get trv 1 3 436 if eq get trv 5 0 437 ret dvnone 438 end 439 q = dv_cat o p trg1 440 q = dv_fmtl o q get trv 2 441 q = dv_cat o q trg2 442 q = dv_fmtl o q get trv 3 443 q = dv_cat o q trg3 444 q = dv_fmtl o q get trv 4 445 ret dv_cat o q trdot 446 end 447 q = dv_cat o p trg4 448 if eq get trv 1 1 449 q = dv_cat o q trplus 450 else 451 q = dv_cat o q trtimes 452 end 453 q = dv_fmtl o q get trv 2 454 q = dv_cat o q trg5 455 q = dv_fmtl o q get trv 4 456 ret dv_cat o q trdot 457 end 458 459 note tr_jint src tape v i: whether token v is an integer; stores it in trv[i]. 460 fn tr_jint src view uchar * tape view uint dvtcap v ulong i ulong to bool 461 if not dv_jisl src tape v 462 ret false 463 end 464 put trv i dv_jnum src tape v 465 ret true 466 end 467 468 note tr_jnums src tape j: job style, kind, k, a and n (default 0) into trv; 0 or -1. 469 fn tr_jnums src view uchar * tape view uint dvtcap j ulong to long 470 if not tr_jint src tape dv_jkey src tape j trkstyl 0 471 ret neg long 1 472 end 473 if not tr_jint src tape dv_jkey src tape j trkk 2 474 ret neg long 1 475 end 476 if not tr_jint src tape dv_jkey src tape j trka 4 477 ret neg long 1 478 end 479 put trv 3 0 480 put trv 5 0 481 nv = dv_jkey src tape j trkn 482 if ne nv jsnone 483 if not tr_jint src tape nv 3 484 ret neg long 1 485 end 486 put trv 5 1 487 end 488 v = dv_jkey src tape j trkkind 489 put trv 1 0 490 if dv_jsteq src tape v tradd 491 put trv 1 1 492 end 493 if dv_jsteq src tape v trmul 494 put trv 1 2 495 end 496 if dv_jsteq src tape v trloop 497 put trv 1 3 498 end 499 ret 0 500 end 501 502 note tr_idok b: 0 when job id b is a single non-empty path component other than "." and "..". 503 fn tr_idok b view uchar * to long 504 n = len b 505 if eq n 0 506 ret neg long 1 507 end 508 for i ulong n 509 if or eq get b i 47 eq get b i 0 510 ret neg long 1 511 end 512 end 513 if eq get b 0 46 514 if eq n 1 515 ret neg long 1 516 end 517 if eq n 2 518 if eq get b 1 46 519 ret neg long 1 520 end 521 end 522 end 523 ret 0 524 end 525 526 note tr_job src tape j bj: job j's id, path, fault, broken (unless fault is "missing") into bj and 527 note its numbers into trv; 0 or -1. 528 fn tr_job src view uchar * tape view uint dvtcap j ulong bj edit uchar 16384 to long 529 v = dv_jkey src tape j trkid 530 n = dv_jstr src tape v part bj 0 1024 531 if lt n 0 532 ret neg long 1 533 end 534 put trb 0 ulong n 535 v = dv_jkey src tape j trkpath 536 n = dv_jstr src tape v part bj 1024 3072 537 if lt n 0 538 ret neg long 1 539 end 540 put trb 1 ulong n 541 v = dv_jkey src tape j trkflt 542 n = dv_jstr src tape v part bj 4096 1024 543 if lt n 0 544 ret neg long 1 545 end 546 put trb 2 ulong n 547 if lt tr_jnums src tape j 0 548 ret neg long 1 549 end 550 if not dv_eq view part bj 4096 get trb 2 trmiss 551 v = dv_jkey src tape j trkbrok 552 n = dv_jstr src tape v part bj 6144 6144 553 if lt n 0 554 ret neg long 1 555 end 556 put trb 3 ulong n 557 put trb 5 1 558 end 559 ret tr_idok view part bj 0 get trb 0 560 end 561 562 note tr_head ba bj: "Task: STYLE\nFile: PATH\nGoal: GOAL\nState: " into ba[24576, ..); 0 or -1. 563 fn tr_head ba edit uchar 32768 bj view uchar 16384 to long 564 o = new uchar 4096 0 565 p = dv_cat o 0 trtask 566 p = tr_style o p 567 p = dv_cat o p trfile 568 p = dv_cat o p part bj 1024 get trb 1 569 p = dv_cat o p trgoal 570 p = tr_goal o p 571 p = dv_cat o p trstate 572 if eq p dvnone 573 ret neg long 1 574 end 575 q = dv_cat part ba 24576 4096 0 view part o 0 p 576 put tra 6 p 577 ret 0 578 end 579 580 note tr_paths ba bj: ROOT = OUTDIR/id and WORK = ROOT/.work into ba, then the head; 0 or -1. 581 fn tr_paths ba edit uchar 32768 bj view uchar 16384 to long 582 t = new uchar 4096 0 583 n = dv_cat t 0 view part ba 8192 get tra 2 584 ni = get trb 0 585 r = dv_join part ba 12288 4096 view part t 0 n part bj 0 ni 586 if eq r dvnone 587 ret neg long 1 588 end 589 put tra 3 r 590 n = dv_cat t 0 view part ba 12288 r 591 r = dv_join part ba 16384 4096 view part t 0 n trwork 592 if eq r dvnone 593 ret neg long 1 594 end 595 put tra 4 r 596 ret tr_head ba bj 597 end 598 599 note tr_tree ba bj: rmtree(ROOT) (errors ignored), makedirs ROOT/dirname(path) and WORK, and the 600 note broken source written to ROOT/path; 0 or a negative error. 601 fn tr_tree ba view uchar 32768 bj view uchar 16384 to long 602 t = new uchar 4096 0 603 r = dv_rmrf part ba 12288 get tra 3 604 dn = dv_dirn part bj 1024 get trb 1 605 n = dv_join t part ba 12288 get tra 3 part bj 1024 dn 606 if eq n dvnone 607 ret neg long 36 608 end 609 r = dv_mkdirp view part t 0 n 610 if lt r 0 611 ret r 612 end 613 r = dv_mkdirp part ba 16384 get tra 4 614 if lt r 0 615 ret r 616 end 617 if eq get trb 5 0 618 ret 0 619 end 620 n = dv_join t part ba 12288 get tra 3 part bj 1024 get trb 1 621 if eq n dvnone 622 ret neg long 36 623 end 624 ret dv_spit view part t 0 n part bj 6144 get trb 3 625 end 626 627 note ======== one tool action 628 629 note tr_tcode bj: the tool of the current action: 1 read_file, 2 omega_check, 3 anything else. 630 fn tr_tcode bj view uchar 16384 to ulong 631 if dv_eq part bj 5120 get trb 4 trrf 632 ret 1 633 end 634 if dv_eq part bj 5120 get trb 4 troc 635 ret 2 636 end 637 ret 3 638 end 639 640 note tr_argc ba bj p: the check arguments WORK OMC KIND K N A appended to the packed list in bj. 641 fn tr_argc ba view uchar 32768 bj edit uchar 16384 p ulong to ulong 642 nb = new uchar 32 0 643 if eq get trv 1 0 644 ret dvnone 645 end 646 q = dv_pkadd part bj 12288 4096 p part ba 16384 get tra 4 647 q = dv_pkadd part bj 12288 4096 q part ba 4096 get tra 1 648 for i ulong 4 649 m = dv_fmtl nb 0 get trv add i 1 650 q = dv_pkadd part bj 12288 4096 q view part nb 0 m 651 end 652 ret q 653 end 654 655 note tr_argr bj p ib it: the replace arguments OLD NEW (strings of the parsed answer) appended. 656 fn tr_argr bj edit uchar 16384 p ulong ib view uchar 8192 it view uint dvtcap to ulong 657 ov = new uchar 4096 0 658 v = dv_jkey ib it 0 trkold 659 n = dv_jstr ib it v ov 660 if lt n 0 661 ret dvnone 662 end 663 q = dv_pkadd part bj 12288 4096 p view part ov 0 ulong n 664 v = dv_jkey ib it 0 trknew 665 n = dv_jstr ib it v ov 666 if lt n 0 667 ret dvnone 668 end 669 ret dv_pkadd part bj 12288 4096 q view part ov 0 ulong n 670 end 671 672 note tr_pkpa bj p pa n: pa[0, n) appended to the packed list in bj[12288, ..); as dv_pkadd. 673 fn tr_pkpa bj edit uchar 16384 p ulong pa view uchar 4096 n ulong to ulong 674 ret dv_pkadd part bj 12288 4096 p part pa 0 n 675 end 676 677 note tr_argv ba bj ib it: the TOOL command line of the parsed answer packed into bj[12288, ..); 678 note its length or dvnone. 679 fn tr_argv ba view uchar 32768 bj edit uchar 16384 ib view uchar 8192 it view uint dvtcap to ulong 680 pa = new uchar 4096 0 681 c = tr_tcode bj 682 p = dv_pkinit part bj 12288 4096 683 p = dv_pkadd part bj 12288 4096 p part ba 0 get tra 0 684 if eq c 1 685 p = dv_pkadd part bj 12288 4096 p trcread 686 end 687 if eq c 2 688 p = dv_pkadd part bj 12288 4096 p trcchk 689 end 690 if eq c 3 691 p = dv_pkadd part bj 12288 4096 p trcrepl 692 end 693 p = dv_pkadd part bj 12288 4096 p part ba 12288 get tra 3 694 n = dv_jstr ib it dv_jkey ib it 0 trkpath pa 695 if lt n 0 696 ret dvnone 697 end 698 p = tr_pkpa bj p pa ulong n 699 if eq c 2 700 ret tr_argc ba bj p 701 end 702 if eq c 3 703 ret tr_argr bj p ib it 704 end 705 ret p 706 end 707 708 note tr_split ob e fs: the ASCII-whitespace-separated fields of ob[0, e): the first four as 709 note (start, length) pairs in fs; the field count. 710 fn tr_split ob view uchar 16384 e ulong fs edit ulong 8 to ulong 711 k = ulong 0 712 s = ulong 0 713 inw = false 714 i = ulong 0 715 while lt i e bound 16385 716 if tr_aws get ob i 717 if inw 718 if lt k 4 719 put fs mul k 2 s 720 put fs add mul k 2 1 sub i s 721 end 722 k = add k 1 723 inw = false 724 end 725 else 726 if not inw 727 s = i 728 inw = true 729 end 730 end 731 i = add i 1 732 end 733 if inw 734 if lt k 4 735 put fs mul k 2 s 736 put fs add mul k 2 1 sub e s 737 end 738 k = add k 1 739 end 740 ret k 741 end 742 743 note tr_parse ob n: whether ob[0, n) is "OMNT1 st ol cl\n" then ol + cl body bytes; sets trs. 744 fn tr_parse ob view uchar 16384 n ulong to bool 745 fs = new ulong 8 0 746 nl = dv_find part ob 0 n dvnl 0 747 if eq nl dvnone 748 ret false 749 end 750 if lt tr_split ob nl fs 4 751 ret false 752 end 753 if not dv_eq part ob get fs 0 get fs 1 trmagic 754 ret false 755 end 756 st = dv_atou part ob get fs 2 get fs 3 757 ol = dv_atou part ob get fs 4 get fs 5 758 cl = dv_atou part ob get fs 6 get fs 7 759 if or or eq st dvnone eq ol dvnone eq cl dvnone 760 ret false 761 end 762 bl = sub sub n nl 1 763 if gt ol bl 764 ret false 765 end 766 if ne cl sub bl ol 767 ret false 768 end 769 put trs 0 st 770 put trs 1 add nl 1 771 put trs 2 ol 772 put trs 3 add add nl 1 ol 773 put trs 4 cl 774 if eq st 1 775 put trs 4 0 776 end 777 ret true 778 end 779 780 note tr_none ob w: observation for an action without a record into ob and trs (status None): 781 note w 0..255 "exit w", 256 + s "exit -s", -110 "timeout", -1000 "malformed record", else 782 note "spawn error". 783 fn tr_none ob edit uchar 16384 w long to void 784 n = ulong 0 785 if ge w 0 786 n = dv_cat ob 0 trexit 787 if gt w 255 788 n = dv_byte ob n 45 789 n = dv_fmtl ob n sub w 256 790 else 791 n = dv_fmtl ob n w 792 end 793 else 794 if eq w -110 795 n = dv_cat ob 0 trtmo 796 else 797 if eq w -1000 798 n = dv_cat ob 0 trbadr 799 else 800 n = dv_cat ob 0 trspawn 801 end 802 end 803 end 804 put trs 0 dvnone 805 put trs 1 0 806 put trs 2 n 807 put trs 3 0 808 put trs 4 0 809 end 810 811 note tr_got gb ba src tape: the head and the next turn's state and a newline into gb; end or dvnone. 812 fn tr_got gb edit uchar 16384 ba view uchar 32768 src view uchar * tape view uint dvtcap to ulong 813 sv = dv_jkey src tape get trs 5 trkstat 814 p = dv_cat gb 0 part ba 24576 get tra 6 815 n = dv_jstr src tape sv part gb p sub 16384 p 816 if lt n 0 817 ret dvnone 818 end 819 ret dv_byte gb add p ulong n 10 820 end 821 822 note tr_tail gb p ob: [Source:\n CONTENT][Tool result: OBS\n]Answer:\n appended at gb[p]. 823 fn tr_tail gb edit uchar 16384 p ulong ob view uchar 16384 to ulong 824 q = p 825 if gt get trs 4 0 826 q = dv_cat gb q trsrc 827 q = dv_cat gb q part ob get trs 3 get trs 4 828 end 829 if gt get trs 2 0 830 q = dv_cat gb q trres 831 q = dv_cat gb q part ob get trs 1 get trs 2 832 q = dv_byte gb q 10 833 end 834 ret dv_cat gb q trans 835 end 836 837 note tr_miss bj ob: print "MISMATCH id fault tool status ST REPR" (REPR: repr(obs)[:200]). 838 fn tr_miss bj view uchar 16384 ob view uchar 16384 to void 839 o = new uchar 8192 0 840 p = dv_cat o 0 trmis 841 p = dv_cat o p part bj 0 get trb 0 842 p = dv_byte o p 32 843 p = dv_cat o p part bj 4096 get trb 2 844 p = dv_byte o p 32 845 p = dv_cat o p part bj 5120 get trb 4 846 p = dv_cat o p trstw 847 if eq get trs 0 dvnone 848 p = dv_cat o p trnone 849 else 850 p = dv_fmtu o p get trs 0 851 end 852 p = dv_byte o p 32 853 p = tr_repr o p part ob get trs 1 get trs 2 200 854 p = dv_byte o p 10 855 if ne p dvnone 856 x = dv_out view part o 0 p 857 end 858 end 859 860 note tr_wline wb wn: print " want REPR" (REPR: repr of the last 200 code points of wb[0, wn)). 861 fn tr_wline wb view uchar 16384 wn ulong to void 862 o = new uchar 2048 0 863 s = tr_back wb wn 200 864 p = dv_cat o 0 trwant 865 p = tr_repr o p part wb s sub wn s 1000 866 p = dv_byte o p 10 867 if ne p dvnone 868 x = dv_out view part o 0 p 869 end 870 end 871 872 note tr_bad bj m: print "ERROR id m"; 1 (a failed run). 873 fn tr_bad bj view uchar 16384 m view uchar * to long 874 o = new uchar 4096 0 875 p = dv_cat o 0 trerr 876 p = dv_cat o p part bj 0 get trb 0 877 p = dv_byte o p 32 878 p = dv_cat o p m 879 p = dv_byte o p 10 880 if ne p dvnone 881 x = dv_out view part o 0 p 882 end 883 ret 1 884 end 885 886 note tr_same gb p wb wn: whether gb[0, p) (p not dvnone) equals wb[0, wn). 887 fn tr_same gb view uchar 16384 p ulong wb view uchar 16384 wn ulong to bool 888 if eq p dvnone 889 ret false 890 end 891 ret dv_eq part gb 0 p part wb 0 wn 892 end 893 894 note tr_judge ob src tape ba bj: rebuild the prompt from the observation in ob and trs and compare 895 note it with the next turn's prompt; 0 equal, 1 different (MISMATCH printed) or a fixture error. 896 fn tr_judge ob view uchar 16384 src view uchar * tape view uint dvtcap ba view uchar 32768 bj view uchar 16384 to long 897 gb = new uchar 16384 0 898 wb = new uchar 16384 0 899 p = tr_got gb ba src tape 900 p = tr_tail gb p ob 901 wn = dv_jstr src tape dv_jkey src tape get trs 5 trkprom wb 902 if lt wn 0 903 ret tr_bad bj trewant 904 end 905 if tr_same gb p wb ulong wn 906 ret 0 907 end 908 tr_miss bj ob 909 tr_wline wb ulong wn 910 ret 1 911 end 912 913 note tr_act ba bj ob: run the packed TOOL command (stdout to the capture file, stderr to /dev/null, 914 note 120 s deadline) and leave its observation in ob and trs. 915 fn tr_act ba view uchar 32768 bj view uchar 16384 ob edit uchar 16384 to void 916 pl = get trs 6 917 cl = get tra 5 918 pid = dv_spawn part bj 12288 pl part ba 20480 cl trnull 919 w = neg long 1 920 if ge pid 0 921 w = dv_wait pid `120000000000` 922 end 923 if ne w 0 924 tr_none ob w 925 ret 926 end 927 n = dv_slurp part ba 20480 cl ob 928 if lt n 0 929 tr_none ob -1000 930 ret 931 end 932 if not tr_parse ob ulong n 933 tr_none ob -1000 934 end 935 end 936 937 note tr_exec src tape ba bj: run the packed TOOL command, read its record, judge; as tr_judge. 938 fn tr_exec src view uchar * tape view uint dvtcap ba view uchar 32768 bj view uchar 16384 to long 939 ob = new uchar 16384 0 940 tr_act ba bj ob 941 put trn 3 add get trn 3 1 942 ret tr_judge ob src tape ba bj 943 end 944 945 note tr_raw src tape t ib: turn t's raw answer cut and stripped into ib; its length, or -1. 946 fn tr_raw src view uchar * tape view uint dvtcap t ulong ib edit uchar 8192 to long 947 rb = new uchar 8192 0 948 n = dv_jstr src tape dv_jkey src tape t trkraw rb 949 if lt n 0 950 ret n 951 end 952 ret long tr_text rb ulong n ib 953 end 954 955 note tr_ans ib it m ba bj: parse the answer ib[0, m), store its tool name and pack its TOOL 956 note command line into bj; 0, or 1 after an ERROR line. 957 fn tr_ans ib view uchar 8192 it edit uint dvtcap m ulong ba view uchar 32768 bj edit uchar 16384 to long 958 r = js_init it jsmaxn 64 959 if lt r 0 960 ret tr_bad bj trejson 961 end 962 r = js_parse ib it m 963 if lt r 0 964 ret tr_bad bj trejson 965 end 966 k = dv_jstr ib it dv_jkey ib it 0 trktool part bj 5120 1024 967 if lt k 0 968 ret tr_bad bj tretool 969 end 970 put trb 4 ulong k 971 p = tr_argv ba bj ib it 972 if eq p dvnone 973 ret tr_bad bj treargv 974 end 975 put trs 6 p 976 ret 0 977 end 978 979 note tr_turn src tape t ba bj: the action of turn t judged against the following turn; as tr_judge. 980 fn tr_turn src view uchar * tape view uint dvtcap t ulong ba view uchar 32768 bj edit uchar 16384 to long 981 ib = new uchar 8192 0 982 it = new uint dvtcap 0 983 put trs 5 js_enext tape t 984 m = tr_raw src tape t ib 985 if lt m 0 986 ret tr_bad bj treraw 987 end 988 if ne tr_ans ib it ulong m ba bj 0 989 ret 1 990 end 991 ret tr_exec src tape ba bj 992 end 993 994 note tr_run src tape r ba bj: replay run r; 0 passed, 1 failed. 995 fn tr_run src view uchar * tape view uint dvtcap r ulong ba edit uchar 32768 bj edit uchar 16384 to long 996 for i ulong 8 997 put trb i 0 998 end 999 j = dv_jkey src tape r trkjob 1000 if lt tr_job src tape j bj 0 1001 ret tr_bad bj trejob 1002 end 1003 if lt tr_paths ba bj 0 1004 ret tr_bad bj trepath 1005 end 1006 if lt tr_tree ba bj 0 1007 ret tr_bad bj tretree 1008 end 1009 tv = dv_jkey src tape r trkturn 1010 if ne js_type tape tv jsarr 1011 ret tr_bad bj treturn 1012 end 1013 t = js_first tape tv 1014 while ne t jsnone bound `16777216` 1015 nx = js_enext tape t 1016 if eq nx jsnone 1017 ret 0 1018 end 1019 if ne tr_turn src tape t ba bj 0 1020 ret 1 1021 end 1022 t = nx 1023 end 1024 ret 0 1025 end 1026 1027 note tr_args ba: TOOL, OMC, OUTDIR, ROUND40/final-selected.json and OUTDIR/.tool-replay.out into ba. 1028 fn tr_args ba edit uchar 32768 to long 1029 t = new uchar 4096 0 1030 n = dv_arg 1 part ba 0 4095 1031 if lt n 0 1032 ret n 1033 end 1034 put tra 0 ulong n 1035 n = dv_arg 2 part ba 4096 4095 1036 if lt n 0 1037 ret n 1038 end 1039 put tra 1 ulong n 1040 n = dv_arg 4 part ba 8192 4095 1041 if lt n 0 1042 ret n 1043 end 1044 put tra 2 ulong n 1045 n = dv_arg 3 part ba 28672 4095 1046 if lt n 0 1047 ret n 1048 end 1049 q = dv_cat part ba 28672 4095 ulong n trsel 1050 if eq q dvnone 1051 ret neg long 36 1052 end 1053 put tra 7 q 1054 q = dv_cat t 0 view part ba 8192 get tra 2 1055 q = dv_join part ba 20480 4095 view part t 0 q trcap 1056 if eq q dvnone 1057 ret neg long 36 1058 end 1059 put tra 5 q 1060 ret 0 1061 end 1062 1063 note tr_sum: print "TOOL-REPLAY runs=N pass=P fail=F actions=A". 1064 fn tr_sum to void 1065 o = new uchar 256 0 1066 p = dv_cat o 0 trsum1 1067 p = dv_fmtu o p get trn 0 1068 p = dv_cat o p trsum2 1069 p = dv_fmtu o p get trn 1 1070 p = dv_cat o p trsum3 1071 p = dv_fmtu o p get trn 2 1072 p = dv_cat o p trsum4 1073 p = dv_fmtu o p get trn 3 1074 p = dv_byte o p 10 1075 x = dv_out view part o 0 p 1076 end 1077 1078 fn main to int 1079 src = new uchar 983040 0 1080 tape = new uint dvtcap 0 1081 ba = new uchar 32768 0 1082 bj = new uchar 16384 0 1083 if lt dv_argc 5 1084 x = dv_err trusage 1085 ret 2 1086 end 1087 if lt tr_args ba 0 1088 x = dv_err trusage 1089 ret 2 1090 end 1091 n = dv_jload view part ba 28672 get tra 7 src tape 1092 if lt n 0 1093 x = dv_err treload 1094 ret 2 1095 end 1096 if ne js_type tape 0 jsarr 1097 x = dv_err treload 1098 ret 2 1099 end 1100 r = js_first tape 0 1101 while ne r jsnone bound `16777216` 1102 f = tr_run src tape r ba bj 1103 put trn 0 add get trn 0 1 1104 if eq f 0 1105 put trn 1 add get trn 1 1 1106 else 1107 put trn 2 add get trn 2 1 1108 end 1109 r = js_enext tape r 1110 end 1111 u = unlink ba 20480 get tra 5 1112 tr_sum 1113 if eq get trn 2 0 1114 ret 0 1115 end 1116 ret 1 1117 end