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/nodedrv.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 / nodedrv.om` 1723 lines ยท 43657 bytes Raw Blame History 1 note seed/node/tests/nodedrv.om: helpers for the Omega Node acceptance drivers (view-prep.om, 2 note view-accept.om): the DRA-291 fixture (prep: what view-prep.py did), node and fake-serve 3 note processes, omnode-op calls and their JSON answers, output lines, the journal and the 4 note listening check. Composition: om2, seed/json/json.om, seed/node/tests/drv.om, this unit, the 5 note driver's main unit. Names: nd_* functions, nd* globals and texts. 6 note The context buffer cx (65536 bytes) holds path slots, slot i at i*4096 with its length in 7 note ndl[i]: [0] BUILD, [1] OMC, [2] ROUND40, [3] OUTDIR, [4] BASE (the scenario directory), [5] 8 note scratch path, [6] the node command "PROGRAM [MODE...]" (nd_set; nd_node), [7] the op capture 9 note file. Bytes 32768..65535 hold the prepared objectives, one newline-terminated line each: 10 note ndl[8] their byte count, ndl[9] their number. Limits: 6 argument slots per function (an 11 note unsized view/edit costs 2, a sized one 1), so js is passed as ndjsz-sized where needed; this driver owns that width, not the JSON library. 12 13 const ndjsz ulong 983040 14 15 global ndl ulong 16 16 note ndpid, ndpst: tracked child processes (at most 16, ndpn[0] of them): the pid, and its status 17 note (-1 while it runs; dv_wstat code once reaped, so a finished process keeps its status). 18 global ndpid long 16 19 global ndpst long 16 20 global ndpn ulong 2 21 note ndr: the last op call: [0] its exit status (-110 at the 30 s deadline, other negative values: 22 note spawn errors), [1] 1 when its stdout parsed as JSON onto the caller's js and tp (root token 0). 23 global ndr long 4 24 note ndoa, ndon[0]: the op numbers after the port and word (nd_args, nd_argx): ndon[0] of ndoa. 25 global ndoa long 16 26 global ndon ulong 2 27 note ndbad[0]: set to 1 when an accessor meets a missing or mistyped value; callers clear it. 28 global ndbad ulong 1 29 note ndport: [0] the last fake-serve port, [1] the last node's view port, [2] 1 when that node's 30 note view came up (its CWV line seen while it still ran). 31 global ndport long 4 32 note ndob: the prepared objectives' original values, four each: kind code (1 add, 2 mul, 3 loop, 33 note 0 other), k, n, a. ndrun: their run tokens in the fixture (at most 128), ndrn[0] the count. 34 global ndob long 512 35 global ndrun ulong 128 36 global ndrn ulong 1 37 note ndw: the buffered writer: [0] bytes buffered, [1] descriptor + 1 (0 none), [2] counting mode 38 note (1: nd_wb counts into [3] and writes nothing), [3] the count. ndwe[0]: the first write error. 39 global ndw ulong 4 40 global ndwe long 1 41 note ndlc[0]: listening entries counted by nd_lsnf. 42 global ndlc ulong 1 43 note ndev, ndevn[0]: a list of up to 4096 events of four numbers each (the full scenario's own 44 note job events, or any caller's list). 45 global ndev long 16384 46 global ndevn ulong 1 47 48 text ndsel "final-selected.json" 49 text ndkjob "job" 50 text ndkpath "path" 51 text ndkflt "fault" 52 text ndkkind "kind" 53 text ndkstyl "style" 54 text ndkk "k" 55 text ndkn "n" 56 text ndka "a" 57 text ndkbrok "broken" 58 text ndkturn "turns" 59 text ndkraw "raw" 60 text ndkstat "state" 61 text ndkprom "prompt" 62 text ndkpass "pass" 63 text ndmiss "missing" 64 text ndadd "add" 65 text ndmul "mul" 66 text ndloop "loop" 67 text ndroot "root" 68 text ndrjobs "root/jobs" 69 text ndrsl "/root/" 70 text ndwork "work" 71 text ndjour "journal" 72 text ndjfile "journal/journal" 73 text ndobjs "objs.txt" 74 text ndexp "expect.json" 75 text ndmap "map" 76 text ndflog "fake.log" 77 text ndfake "fake-serve" 78 text ndinfer "infer" 79 text ndtool "tool" 80 text ndop "op" 81 text ndopout ".op.out" 82 text ndportw "PORT" 83 text ndcwv "CWV " 84 text ndview "view" 85 text ndcmd "cmd" 86 text ndwx "x" 87 text ndout ".out" 88 text nderr ".err" 89 text ndnone "None" 90 text ndtcp "/proc/net/tcp" 91 text ndtcp6 "/proc/net/tcp6" 92 note Keys and values of omnode-op answers (seed/node/view.om). 93 text ndklay "layout" 94 text ndkinc "incarnation" 95 text ndkver "version" 96 text ndksnce "since" 97 text ndkevs "events" 98 text ndkauth "authority" 99 text ndkpaus "paused" 100 text ndkq "queue" 101 text ndkwait "waiting" 102 text ndkrdy "ready" 103 text ndkrun "running" 104 text ndklim "limit" 105 text ndkref "refused" 106 text ndkcmds "commands" 107 text ndkcomm "committed" 108 text ndklast "last_id" 109 text ndkwkrs "workers" 110 text ndkunc "uncertain" 111 text ndkobs "objectives" 112 text ndkbud "budget" 113 text ndkph "phase" 114 text ndkres "result" 115 text ndkid "id" 116 text ndkst "status" 117 text ndsnap "snapshot" 118 text nddelta "delta" 119 text ndstale "stale" 120 text ndinval "invalid" 121 text nddup "duplicate" 122 note expect.json framing (json.dump indent=1) and the map answer around the raw text. 123 text ndx1 "{\n \"objs\": [\n " 124 text ndx2 ",\n " 125 text ndx3 "\n ],\n \"recs\": [\n {\n \"path\": " 126 text ndx4 "\n },\n {\n \"path\": " 127 text ndx5 ",\n \"obj\": " 128 text ndx6 ",\n \"turns\": [" 129 text ndx7 "\n {\n \"state\": " 130 text ndx8 ",\n \"prompt\": " 131 text ndx9 ",\n \"raw\": " 132 text ndx10 "\n }" 133 text ndx11 "," 134 text ndx12 "\n ]" 135 text ndx13 "]" 136 text ndx14 ",\n \"pass_\": " 137 text ndx15 ",\n \"state\": " 138 text ndx16 "\n }\n ]\n}" 139 text ndtrue "true" 140 text ndfalse "false" 141 text ndmv1 "{\"object\": \"text_completion\", \"choices\": [{\"index\": 0, \"text\": " 142 text ndmv2 ", \"finish_reason\": \"stop\"}], \"usage\": {\"prompt_tokens\": 1, \"completion_tokens\": 1}}" 143 note ndsty1, ndsty2: repair.py STYLES 0..25 and 26..50, one per line (as tool-replay.om). 144 text ndsty1 "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" 145 text ndsty2 "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" 146 147 note ======== paths 148 149 note nd_sub cx s q t: path slot s joined with t (os.path.join) into slot q; its length or dvnone. 150 fn nd_sub cx edit uchar 65536 s ulong q ulong t view uchar * to ulong 151 a = new uchar 4096 0 152 n = dv_cat a 0 view part cx mul s 4096 get ndl s 153 if eq n dvnone 154 ret dvnone 155 end 156 r = dv_join part cx mul q 4096 4096 view part a 0 n t 157 if ne r dvnone 158 put ndl q r 159 end 160 ret r 161 end 162 163 note nd_absj o a: a joined to the working directory (os.path.join: a itself when absolute) into 164 note o; the length, or dvnone when the directory is unknown or o is too short. 165 fn nd_absj o edit uchar 4096 a view uchar * to ulong 166 w = new uchar 4096 0 167 m = cwd w 0 4096 168 if lt m 2 169 ret dvnone 170 end 171 ret dv_join o view part w 0 sub ulong m 1 a 172 end 173 174 note nd_abs cx s i: command-line argument i made absolute (joined to the working directory when 175 note relative; not normalised) into slot s: 0, or -22 empty, -105 too long or no directory. 176 fn nd_abs cx edit uchar 65536 s ulong i ulong to long 177 a = new uchar 4096 0 178 b = new uchar 4096 0 179 n = dv_arg i a 180 if lt n 1 181 if eq n 0 182 ret neg long 22 183 end 184 ret n 185 end 186 r = nd_absj b view part a 0 ulong n 187 if eq r dvnone 188 ret neg long 105 189 end 190 x = nd_set cx s view part b 0 r 191 ret 0 192 end 193 194 note nd_base cx t: BASE (slot 4) = OUTDIR/t, and the op capture file (slot 7) = OUTDIR/.op.out; 195 note true when both fit. 196 fn nd_base cx edit uchar 65536 t view uchar * to bool 197 if eq nd_sub cx 3 4 t dvnone 198 ret false 199 end 200 ret ne nd_sub cx 3 7 ndopout dvnone 201 end 202 203 note ======== numbers and lines 204 205 note nd_w64 b o: the little-endian 64-bit word at b[o]. 206 fn nd_w64 b view uchar * o ulong to ulong 207 v = ulong 0 208 for i ulong 8 209 v = or v shl ulong get b add o i mul i 8 210 end 211 ret v 212 end 213 214 note nd_lend b s: the end of the line that starts at b[s] (its newline's index, or len b). 215 fn nd_lend b view uchar * s ulong to ulong 216 i = s 217 while lt i len b bound `16777217` 218 if eq get b i 10 219 ret i 220 end 221 i = add i 1 222 end 223 ret len b 224 end 225 226 note nd_pfx b s e t: true when b[s..e) starts with t. 227 fn nd_pfx b view uchar * s ulong e ulong t view uchar * to bool 228 if lt sub e s len t 229 ret false 230 end 231 ret dv_eq view part b s len t t 232 end 233 234 note nd_hasl b t: true when some line of b is exactly t. 235 fn nd_hasl b view uchar * t view uchar * to bool 236 s = ulong 0 237 while lt s len b bound `16777217` 238 e = nd_lend b s 239 if eq sub e s len t 240 if dv_eq view part b s len t t 241 ret true 242 end 243 end 244 s = add e 1 245 end 246 ret false 247 end 248 249 note nd_hasp b t: true when some line of b starts with t. 250 fn nd_hasp b view uchar * t view uchar * to bool 251 s = ulong 0 252 while lt s len b bound `16777217` 253 e = nd_lend b s 254 if nd_pfx b s e t 255 ret true 256 end 257 s = add e 1 258 end 259 ret false 260 end 261 262 note nd_lastl o p b: the last line of b (Python splitlines()[-1]; empty when b is) appended at o[p]. 263 fn nd_lastl o edit uchar * p ulong b view uchar * to ulong 264 n = len b 265 if gt n 0 266 if eq get b sub n 1 10 267 n = sub n 1 268 end 269 end 270 s = n 271 while gt s 0 bound `16777217` 272 if eq get b sub s 1 10 273 break 274 end 275 s = sub s 1 276 end 277 ret dv_cat o p part b s sub n s 278 end 279 280 note nd_pfxl o p b t: the Python repr of the list of lines of b starting with t (['l1', 'l2']) 281 note appended at o[p] (o is a 1024-byte detail buffer); lines are taken verbatim between quotes. 282 fn nd_pfxl o edit uchar 1024 p ulong b view uchar * t view uchar * to ulong 283 q = dv_byte o p 91 284 c = ulong 0 285 s = ulong 0 286 while lt s len b bound `16777217` 287 e = nd_lend b s 288 if nd_pfx b s e t 289 if gt c 0 290 q = dv_byte o q 44 291 q = dv_byte o q 32 292 end 293 q = dv_byte o q 39 294 q = dv_cat o q part b s sub e s 295 q = dv_byte o q 39 296 c = add c 1 297 end 298 s = add e 1 299 end 300 ret dv_byte o q 93 301 end 302 303 note nd_line o p t k: line k of the newline-terminated lines t appended at o[p]; the end or dvnone. 304 fn nd_line o edit uchar * p ulong t view uchar * k ulong to ulong 305 i = ulong 0 306 c = ulong 0 307 s = ulong 0 308 while lt i len t bound 4096 309 if eq get t i 10 310 if eq c k 311 ret dv_cat o p part t s sub i s 312 end 313 c = add c 1 314 s = add i 1 315 end 316 i = add i 1 317 end 318 ret dvnone 319 end 320 321 note nd_style o p s: repair.py STYLES[s] appended at o[p]; dvnone for s outside 0..50. 322 fn nd_style o edit uchar * p ulong s long to ulong 323 if or lt s 0 gt s 50 324 ret dvnone 325 end 326 if lt s 26 327 ret nd_line o p ndsty1 ulong s 328 end 329 ret nd_line o p ndsty2 sub ulong s 26 330 end 331 332 note ======== the buffered writer and the JSON string encoder (Python json.dumps, ensure_ascii) 333 334 note nd_wopen pa: open pa (created or truncated) for the writer: 0 or the negative fopen error. 335 fn nd_wopen pa view uchar * to long 336 fd = fopen pa 0 len pa 557633 420 337 if lt fd 0 338 ret fd 339 end 340 put ndw 0 0 341 put ndw 1 add ulong fd 1 342 put ndw 2 0 343 put ndw 3 0 344 put ndwe 0 0 345 ret 0 346 end 347 348 note nd_wflush ob: write out the bytes buffered in ob. 349 fn nd_wflush ob edit uchar * to void 350 n = get ndw 0 351 if eq n 0 352 ret 353 end 354 f = get ndw 1 355 if gt f 0 356 r = dv_wall int sub f 1 view part ob 0 n 357 if lt r 0 358 if eq get ndwe 0 0 359 put ndwe 0 r 360 end 361 end 362 end 363 put ndw 0 0 364 end 365 366 note nd_wclose ob: flush and close the writer: 0 or the first write error. 367 fn nd_wclose ob edit uchar * to long 368 nd_wflush ob 369 f = get ndw 1 370 if gt f 0 371 x = fclose int sub f 1 372 end 373 put ndw 1 0 374 ret get ndwe 0 375 end 376 377 note nd_wb ob c: byte c through the writer buffer ob (or counted, in counting mode). 378 fn nd_wb ob edit uchar * c uchar to void 379 if eq get ndw 2 1 380 put ndw 3 add get ndw 3 1 381 ret 382 end 383 if ge get ndw 0 len ob 384 nd_wflush ob 385 end 386 put ob get ndw 0 c 387 put ndw 0 add get ndw 0 1 388 end 389 390 note nd_wt ob t: the bytes of t through the writer. 391 fn nd_wt ob edit uchar * t view uchar * to void 392 for i ulong len t 393 nd_wb ob get t i 394 end 395 end 396 397 note nd_wu ob v: v in decimal through the writer. 398 fn nd_wu ob edit uchar * v ulong to void 399 d = new uchar 24 0 400 n = dv_fmtu d 0 v 401 nd_wt ob view part d 0 n 402 end 403 404 note nd_whex ob v: \u and v as four lowercase hex digits through the writer. 405 fn nd_whex ob edit uchar * v ulong to void 406 nd_wb ob 92 407 nd_wb ob 117 408 for i ulong 4 409 d = and shr v mul sub 3 i 4 15 410 if lt d 10 411 nd_wb ob uchar add d 48 412 else 413 nd_wb ob uchar add d 87 414 end 415 end 416 end 417 418 note nd_wch ob c: code point c JSON-escaped as Python's ensure_ascii encoder does. 419 fn nd_wch ob edit uchar * c ulong to void 420 e = ulong 0 421 if eq c 34 422 e = 34 423 end 424 if eq c 92 425 e = 92 426 end 427 if eq c 10 428 e = 110 429 end 430 if eq c 13 431 e = 114 432 end 433 if eq c 9 434 e = 116 435 end 436 if eq c 8 437 e = 98 438 end 439 if eq c 12 440 e = 102 441 end 442 if ne e 0 443 nd_wb ob 92 444 nd_wb ob uchar e 445 ret 446 end 447 if and ge c 32 le c 126 448 nd_wb ob uchar c 449 ret 450 end 451 if lt c 65536 452 nd_whex ob c 453 ret 454 end 455 v = sub c 65536 456 nd_whex ob add 55296 shr v 10 457 nd_whex ob add 56320 and v 1023 458 end 459 460 note nd_u8 s i: the UTF-8 sequence at s[i]: its code point, or'd with its byte length << 32 461 note (a stray or cut byte decodes as itself, or as U+FFFD at the end, with length 1). 462 fn nd_u8 s view uchar * i ulong to ulong 463 b = ulong get s i 464 k = ulong 1 465 c = b 466 if ge b 240 467 k = 4 468 c = and b 7 469 else 470 if ge b 224 471 k = 3 472 c = and b 15 473 else 474 if ge b 192 475 k = 2 476 c = and b 31 477 end 478 end 479 end 480 if gt add i k len s 481 ret or 65533 shl ulong 1 32 482 end 483 j = ulong 1 484 while lt j k bound 4 485 c = or shl c 6 and ulong get s add i j 63 486 j = add j 1 487 end 488 ret or c shl k 32 489 end 490 491 note nd_wesc ob s: the UTF-8 bytes s as a JSON string (quotes included) through the writer. 492 fn nd_wesc ob edit uchar * s view uchar * to void 493 nd_wb ob 34 494 i = ulong 0 495 while lt i len s bound `16777217` 496 r = nd_u8 s i 497 nd_wch ob and r `2097151` 498 i = add i shr r 32 499 end 500 nd_wb ob 34 501 end 502 503 note nd_wtk ob js tp t: JSON string token t re-encoded through the writer: 0, or the negative 504 note dv_jstr error (not a string, or longer than 65536 bytes decoded). 505 fn nd_wtk ob edit uchar * js view uchar * tp view uint dvtcap t ulong to long 506 d = new uchar 65536 0 507 n = dv_jstr js tp t d 508 if lt n 0 509 ret n 510 end 511 nd_wesc ob view part d 0 ulong n 512 ret 0 513 end 514 515 note nd_elen ob js tp t: the byte length nd_wtk would write for t, or its negative error. 516 fn nd_elen ob edit uchar * js view uchar * tp view uint dvtcap t ulong to long 517 put ndw 2 1 518 put ndw 3 0 519 r = nd_wtk ob js tp t 520 put ndw 2 0 521 if lt r 0 522 ret r 523 end 524 ret long get ndw 3 525 end 526 527 note ======== the DRA-291 fixture (view-prep) 528 529 note nd_jint js tp t key: integer member key of object token t; ndbad set and 0 when it is no 530 note integer. 531 fn nd_jint js view uchar * tp view uint dvtcap t ulong key view uchar * to long 532 v = dv_jkey js tp t key 533 if not dv_jisl js tp v 534 put ndbad 0 1 535 ret 0 536 end 537 ret dv_jnum js tp v 538 end 539 540 note nd_find js tp w: the first run of the fixture array whose job.path contains w, or jsnone. 541 fn nd_find js view uchar * tp view uint dvtcap w view uchar * to ulong 542 d = new uchar 4096 0 543 r = js_first tp 0 544 while ne r jsnone bound `16777217` 545 j = dv_jkey js tp r ndkjob 546 n = dv_jstr js tp dv_jkey js tp j ndkpath d 547 if ge n 0 548 if ne dv_find view part d 0 ulong n w 0 dvnone 549 ret r 550 end 551 end 552 r = js_enext tp r 553 end 554 ret jsnone 555 end 556 557 note nd_rpath cx js tp j: BASE/root/ followed by job j's path into slot 5; its length or dvnone. 558 fn nd_rpath cx edit uchar 65536 js view uchar * tp view uint dvtcap j ulong to ulong 559 a = new uchar 4096 0 560 d = new uchar 4096 0 561 n = dv_jstr js tp dv_jkey js tp j ndkpath d 562 if lt n 0 563 ret dvnone 564 end 565 p = dv_cat a 0 view part cx 16384 get ndl 4 566 p = dv_cat a p ndrsl 567 p = dv_cat a p view part d 0 ulong n 568 if eq p dvnone 569 ret dvnone 570 end 571 ret nd_set cx 5 view part a 0 p 572 end 573 574 note nd_brok cx js tp j: write job j's broken text to BASE/root/PATH unless its fault is 575 note "missing": 0 or a negative error. 576 fn nd_brok cx edit uchar 65536 js view uchar * tp view uint dvtcap j ulong to long 577 b = new uchar 65536 0 578 if dv_jsteq js tp dv_jkey js tp j ndkflt ndmiss 579 ret 0 580 end 581 n = dv_jstr js tp dv_jkey js tp j ndkbrok b 582 if lt n 0 583 ret n 584 end 585 q = nd_rpath cx js tp j 586 if eq q dvnone 587 ret neg long 36 588 end 589 ret dv_spit view part cx 20480 q view part b 0 ulong n 590 end 591 592 note nd_objv js tp j i: job j's kind code, k, n (0 when absent) and a stored as objective i in 593 note ndob: 0, or -22 for a field that is no integer. 594 fn nd_objv js view uchar * tp view uint dvtcap j ulong i ulong to long 595 put ndbad 0 0 596 o = mul i 4 597 c = long 0 598 kd = dv_jkey js tp j ndkkind 599 if dv_jsteq js tp kd ndadd 600 c = 1 601 end 602 if dv_jsteq js tp kd ndmul 603 c = 2 604 end 605 if dv_jsteq js tp kd ndloop 606 c = 3 607 end 608 put ndob o c 609 put ndob add o 1 nd_jint js tp j ndkk 610 n = long 0 611 if ne dv_jkey js tp j ndkn jsnone 612 n = nd_jint js tp j ndkn 613 end 614 put ndob add o 2 n 615 put ndob add o 3 nd_jint js tp j ndka 616 if eq get ndbad 0 1 617 ret neg long 22 618 end 619 ret 0 620 end 621 622 note nd_obj o js tp j i: "kind,k,n," of job j (objective i in ndob) written at o[0]; the end or dvnone. 623 fn nd_obj o edit uchar 4096 js view uchar * tp view uint dvtcap j ulong i ulong to ulong 624 kd = new uchar 64 0 625 o4 = mul i 4 626 n = dv_jstr js tp dv_jkey js tp j ndkkind kd 627 if lt n 0 628 ret dvnone 629 end 630 q = dv_cat o 0 view part kd 0 ulong n 631 q = dv_byte o q 44 632 q = dv_fmtl o q get ndob add o4 1 633 q = dv_byte o q 44 634 q = dv_fmtl o q get ndob add o4 2 635 ret dv_byte o q 44 636 end 637 638 note nd_objt o js tp j i a: objective i's line "kind,k,n,a,path,STYLE\n" (job j, argument a) 639 note written at o[0]; its length, or dvnone. 640 fn nd_objt o edit uchar 4096 js view uchar ndjsz tp view uint dvtcap j ulong i ulong a long to ulong 641 d = new uchar 4096 0 642 p = nd_obj o js tp j i 643 p = dv_fmtl o p a 644 p = dv_byte o p 44 645 n = dv_jstr js tp dv_jkey js tp j ndkpath d 646 if lt n 0 647 ret dvnone 648 end 649 p = dv_cat o p view part d 0 ulong n 650 p = dv_byte o p 44 651 p = nd_style o p nd_jint js tp j ndkstyl 652 ret dv_byte o p 10 653 end 654 655 note nd_addl cx o n: the line o[0..n) appended to the prepared objectives in cx: 0, or -7 when 656 note they would pass 32768 bytes. 657 fn nd_addl cx edit uchar 65536 o view uchar 4096 n ulong to long 658 e = get ndl 8 659 if gt n sub 32768 e 660 ret neg long 7 661 end 662 for i ulong n 663 put cx add add 32768 e i get o i 664 end 665 put ndl 8 add e n 666 put ndl 9 add get ndl 9 1 667 ret 0 668 end 669 670 note nd_objl cx js tp j i wrong: objective i's line (nd_objt; a = k+n+a+1 for the first objective 671 note when wrong) appended to the objectives in cx: 0 or a negative error. 672 fn nd_objl cx edit uchar 65536 js view uchar ndjsz tp view uint dvtcap j ulong i ulong wrong bool to long 673 o = new uchar 4096 0 674 o4 = mul i 4 675 a = get ndob add o4 3 676 if wrong 677 if eq i 0 678 k = get ndob add o4 1 679 k = add k get ndob add o4 2 680 a = add add k a 1 681 end 682 end 683 p = nd_objt o js tp j i a 684 if eq p dvnone 685 ret neg long 22 686 end 687 ret nd_addl cx o p 688 end 689 690 note nd_prep1 cx js tp w wrong: prepare the first run whose path contains w: 0 or negative. 691 fn nd_prep1 cx edit uchar 65536 js view uchar ndjsz tp view uint dvtcap w view uchar * wrong bool to long 692 r = nd_find js tp w 693 if eq r jsnone 694 ret neg long 2 695 end 696 i = get ndrn 0 697 if ge i 128 698 ret neg long 7 699 end 700 put ndrun i r 701 put ndrn 0 add i 1 702 j = dv_jkey js tp r ndkjob 703 x = nd_brok cx js tp j 704 if lt x 0 705 ret x 706 end 707 x = nd_objv js tp j i 708 if lt x 0 709 ret x 710 end 711 ret nd_objl cx js tp j i wrong 712 end 713 714 note nd_tree cx: BASE removed and recreated with root/jobs and work: 0 or a negative error. 715 fn nd_tree cx edit uchar 65536 to long 716 r = dv_rmrf view part cx 16384 get ndl 4 717 q = nd_sub cx 4 5 ndrjobs 718 if eq q dvnone 719 ret neg long 36 720 end 721 r = dv_mkdirp view part cx 20480 q 722 if lt r 0 723 ret r 724 end 725 q = nd_sub cx 4 5 ndwork 726 if eq q dvnone 727 ret neg long 36 728 end 729 ret dv_mkdirp view part cx 20480 q 730 end 731 732 note nd_wturn ob js tp u: turn object u written as an expect.json turn: 0 or negative. 733 fn nd_wturn ob edit uchar * js view uchar * tp view uint dvtcap u ulong to long 734 nd_wt ob ndx7 735 r = nd_wtk ob js tp dv_jkey js tp u ndkstat 736 nd_wt ob ndx8 737 x = nd_wtk ob js tp dv_jkey js tp u ndkprom 738 r = or r x 739 nd_wt ob ndx9 740 x = nd_wtk ob js tp dv_jkey js tp u ndkraw 741 r = or r x 742 nd_wt ob ndx10 743 if ne r 0 744 ret neg long 22 745 end 746 ret 0 747 end 748 749 note nd_wobj ob js tp i: prepared run i's "kind,k,n,a" (its original a) written as a JSON string. 750 fn nd_wobj ob edit uchar * js view uchar * tp view uint dvtcap i ulong to long 751 o = new uchar 4096 0 752 j = dv_jkey js tp get ndrun i ndkjob 753 p = nd_obj o js tp j i 754 p = dv_fmtl o p get ndob add mul i 4 3 755 if eq p dvnone 756 ret neg long 22 757 end 758 nd_wesc ob view part o 0 p 759 ret 0 760 end 761 762 note nd_wtrns ob js tp ts: the turns array ts written as expect.json turns ([] when empty). 763 fn nd_wtrns ob edit uchar * js view uchar * tp view uint dvtcap ts ulong to long 764 if ne js_type tp ts jsarr 765 ret neg long 22 766 end 767 e = long 0 768 u = js_first tp ts 769 c = ulong 0 770 while ne u jsnone bound `16777217` 771 if gt c 0 772 nd_wt ob ndx11 773 end 774 x = nd_wturn ob js tp u 775 e = or e x 776 c = add c 1 777 u = js_enext tp u 778 end 779 if gt c 0 780 nd_wt ob ndx12 781 else 782 nd_wt ob ndx13 783 end 784 ret e 785 end 786 787 note nd_wrec ob js tp i: prepared run i written as an expect.json rec: 0 or negative. 788 fn nd_wrec ob edit uchar * js view uchar * tp view uint dvtcap i ulong to long 789 r = get ndrun i 790 j = dv_jkey js tp r ndkjob 791 e = nd_wtk ob js tp dv_jkey js tp j ndkpath 792 nd_wt ob ndx5 793 x = nd_wobj ob js tp i 794 e = or e x 795 nd_wt ob ndx6 796 x = nd_wtrns ob js tp dv_jkey js tp r ndkturn 797 e = or e x 798 nd_wt ob ndx14 799 u = dv_jkey js tp r ndkpass 800 if eq js_type tp u jstrue 801 nd_wt ob ndtrue 802 else 803 if eq js_type tp u jsfalse 804 nd_wt ob ndfalse 805 else 806 e = neg long 22 807 end 808 end 809 nd_wt ob ndx15 810 x = nd_wtk ob js tp dv_jkey js tp r ndkstat 811 e = or e x 812 if ne e 0 813 ret neg long 22 814 end 815 ret 0 816 end 817 818 note nd_wobjs ob b: each line of b (the prepared objectives) written as a JSON string, ", "-joined. 819 fn nd_wobjs ob edit uchar * b view uchar * to void 820 s = ulong 0 821 c = ulong 0 822 while lt s len b bound `16777217` 823 t = nd_lend b s 824 if gt c 0 825 nd_wt ob ndx2 826 end 827 nd_wesc ob view part b s sub t s 828 c = add c 1 829 s = add t 1 830 end 831 end 832 833 note nd_wexp cx js tp: BASE/expect.json, byte for byte what view-prep.py's json.dump(indent=1) 834 note wrote: 0 or a negative error. 835 fn nd_wexp cx edit uchar 65536 js view uchar * tp view uint dvtcap to long 836 ob = new uchar 65536 0 837 q = nd_sub cx 4 5 ndexp 838 if eq q dvnone 839 ret neg long 36 840 end 841 e = nd_wopen view part cx 20480 q 842 if lt e 0 843 ret e 844 end 845 nd_wt ob ndx1 846 nd_wobjs ob view part cx 32768 get ndl 8 847 for i ulong get ndrn 0 848 if eq i 0 849 nd_wt ob ndx3 850 else 851 nd_wt ob ndx4 852 end 853 x = nd_wrec ob js tp i 854 if lt x 0 855 e = x 856 end 857 end 858 nd_wt ob ndx16 859 x = nd_wclose ob 860 if lt x 0 861 ret x 862 end 863 ret e 864 end 865 866 note nd_wpair ob js tp u: turn u as a map record "KLEN VLEN\n" KEY VALUE: 0 or negative. 867 fn nd_wpair ob edit uchar * js view uchar * tp view uint dvtcap u ulong to long 868 p = dv_jkey js tp u ndkprom 869 w = dv_jkey js tp u ndkraw 870 kl = nd_elen ob js tp p 871 vl = nd_elen ob js tp w 872 if or lt kl 0 lt vl 0 873 ret neg long 22 874 end 875 nd_wu ob ulong kl 876 nd_wb ob 32 877 nd_wu ob add add ulong vl len ndmv1 len ndmv2 878 nd_wb ob 10 879 x = nd_wtk ob js tp p 880 nd_wt ob ndmv1 881 x = nd_wtk ob js tp w 882 nd_wt ob ndmv2 883 ret 0 884 end 885 886 note nd_wmap cx js tp: BASE/map, the fake-serve map of every prepared turn (prompt to raw), 887 note byte for byte what view-prep.py wrote: 0 or a negative error. 888 fn nd_wmap cx edit uchar 65536 js view uchar * tp view uint dvtcap to long 889 ob = new uchar 65536 0 890 q = nd_sub cx 4 5 ndmap 891 if eq q dvnone 892 ret neg long 36 893 end 894 e = nd_wopen view part cx 20480 q 895 if lt e 0 896 ret e 897 end 898 for i ulong get ndrn 0 899 u = js_first tp dv_jkey js tp get ndrun i ndkturn 900 while ne u jsnone bound `16777217` 901 x = nd_wpair ob js tp u 902 if lt x 0 903 e = x 904 end 905 u = js_enext tp u 906 end 907 end 908 x = nd_wclose ob 909 if lt x 0 910 ret x 911 end 912 ret e 913 end 914 915 note nd_prepl cx js tp ids wrong: nd_prep1 for each comma-separated id of ids: 0 or negative. 916 fn nd_prepl cx edit uchar 65536 js view uchar ndjsz tp view uint dvtcap ids view uchar * wrong bool to long 917 s = ulong 0 918 i = ulong 0 919 while le i len ids bound `16777217` 920 c = true 921 if lt i len ids 922 c = eq get ids i 44 923 end 924 if c 925 r = nd_prep1 cx js tp view part ids s sub i s wrong 926 if lt r 0 927 ret r 928 end 929 s = add i 1 930 end 931 i = add i 1 932 end 933 ret 0 934 end 935 936 note nd_wobjf cx: the prepared objective lines written to BASE/objs.txt: 0 or negative. 937 fn nd_wobjf cx edit uchar 65536 to long 938 b = new uchar 32768 0 939 m = get ndl 8 940 for i ulong m 941 put b i get cx add 32768 i 942 end 943 n = nd_sub cx 4 5 ndobjs 944 if eq n dvnone 945 ret neg long 36 946 end 947 ret dv_spit view part cx 20480 n view part b 0 m 948 end 949 950 note nd_prep cx js tp ids wrong: view-prep: load ROUND40/final-selected.json (slot 2) onto js and 951 note tp, rebuild BASE (slot 4) and prepare, for each comma-separated id of ids, the first run whose 952 note job path contains it: its broken file under BASE/root (unless the fault is "missing"), its 953 note objective line (in cx and BASE/objs.txt), its expect.json rec and its map records; with wrong 954 note the first objective's a is k+n+a+1. The number of objectives, or a negative error. 955 fn nd_prep cx edit uchar 65536 js edit uchar ndjsz tp edit uint dvtcap ids view uchar * wrong bool to long 956 put ndl 8 0 957 put ndl 9 0 958 put ndrn 0 0 959 n = nd_sub cx 2 5 ndsel 960 if eq n dvnone 961 ret neg long 36 962 end 963 k = dv_jload view part cx 20480 n js tp 964 if lt k 0 965 ret k 966 end 967 if ne js_type tp 0 jsarr 968 ret neg long 22 969 end 970 r = nd_tree cx 971 if lt r 0 972 ret r 973 end 974 r = nd_prepl cx js tp ids wrong 975 if lt r 0 976 ret r 977 end 978 r = nd_wobjf cx 979 if lt r 0 980 ret r 981 end 982 r = nd_wexp cx js tp 983 if lt r 0 984 ret r 985 end 986 r = nd_wmap cx js tp 987 if lt r 0 988 ret r 989 end 990 ret long get ndl 9 991 end 992 993 note ======== processes 994 995 note nd_track pid: a slot for child pid (its status -1, running), or dvnone when the table is 996 note full (the child is then killed and reaped). 997 fn nd_track pid long to ulong 998 i = get ndpn 0 999 if ge i 16 1000 x = dv_killg pid 9 1001 x = dv_kill pid 9 1002 x = dv_reap pid 1003 ret dvnone 1004 end 1005 put ndpid i pid 1006 put ndpst i neg long 1 1007 put ndpn 0 add i 1 1008 ret i 1009 end 1010 1011 note nd_poll i: tracked process i's status without blocking: -1 while it runs, its dv_wstat 1012 note status once finished (kept), -10 for no such slot. 1013 fn nd_poll i ulong to long 1014 if ge i get ndpn 0 1015 ret neg long 10 1016 end 1017 s = get ndpst i 1018 if ne s -1 1019 ret s 1020 end 1021 r = dv_poll get ndpid i 1022 if ne r -1 1023 put ndpst i r 1024 end 1025 ret r 1026 end 1027 1028 note nd_fin i sec: wait for tracked process i up to sec seconds: its status, or -110 when it was 1029 note killed (group and pid) at the deadline. 1030 fn nd_fin i ulong sec ulong to long 1031 if ge i get ndpn 0 1032 ret neg long 10 1033 end 1034 s = get ndpst i 1035 if ne s -1 1036 ret s 1037 end 1038 r = dv_wait get ndpid i mul sec `1000000000` 1039 put ndpst i r 1040 ret r 1041 end 1042 1043 note nd_sig i sig: signal sig to tracked process i alone (not its group) while it runs. 1044 fn nd_sig i ulong sig int to long 1045 if ge i get ndpn 0 1046 ret neg long 10 1047 end 1048 if ne get ndpst i -1 1049 ret 0 1050 end 1051 ret dv_kill get ndpid i sig 1052 end 1053 1054 note nd_reap i: wait (blocking) for tracked process i: its status. 1055 fn nd_reap i ulong to long 1056 if ge i get ndpn 0 1057 ret neg long 10 1058 end 1059 s = get ndpst i 1060 if ne s -1 1061 ret s 1062 end 1063 r = dv_reap get ndpid i 1064 put ndpst i r 1065 ret r 1066 end 1067 1068 note nd_clean: SIGKILL every tracked process's group and every one still running, reap them, 1069 note and empty the table (the end of each scenario). 1070 fn nd_clean to void 1071 for i ulong get ndpn 0 1072 x = dv_killg get ndpid i 9 1073 if eq get ndpst i -1 1074 x = dv_kill get ndpid i 9 1075 x = dv_reap get ndpid i 1076 put ndpst i x 1077 end 1078 end 1079 put ndpn 0 0 1080 end 1081 1082 note ======== spawning fake-serve and the node 1083 1084 note nd_pkn pk p v: the decimal v appended to the packed list (dv_pkadd; pk is 4096 bytes). 1085 fn nd_pkn pk edit uchar 4096 p ulong v long to ulong 1086 d = new uchar 24 0 1087 q = dv_fmtl d 0 v 1088 ret dv_pkadd pk p view part d 0 q 1089 end 1090 1091 note nd_pks cx pk p s t: path slot s joined with t appended to the packed list. 1092 fn nd_pks cx edit uchar 65536 pk edit uchar 4096 p ulong s ulong t view uchar * to ulong 1093 n = nd_sub cx s 5 t 1094 if eq n dvnone 1095 ret dvnone 1096 end 1097 ret dv_pkadd pk p view part cx 20480 n 1098 end 1099 1100 note nd_pkw pk p t: each space-separated word of t appended to the packed list. 1101 fn nd_pkw pk edit uchar 4096 p ulong t view uchar * to ulong 1102 q = p 1103 s = ulong 0 1104 i = ulong 0 1105 while le i len t bound `16777217` 1106 c = true 1107 if lt i len t 1108 c = eq get t i 32 1109 end 1110 if c 1111 if gt i s 1112 q = dv_pkadd pk q view part t s sub i s 1113 end 1114 s = add i 1 1115 end 1116 i = add i 1 1117 end 1118 ret q 1119 end 1120 1121 note nd_pkobj pk p b: each line of b (the prepared objectives, cx[32768..+ndl[8])) appended to the 1122 note packed list. 1123 fn nd_pkobj pk edit uchar 4096 p ulong b view uchar * to ulong 1124 q = p 1125 s = ulong 0 1126 while lt s len b bound `16777217` 1127 e = nd_lend b s 1128 q = dv_pkadd pk q view part b s sub e s 1129 s = add e 1 1130 end 1131 ret q 1132 end 1133 1134 note nd_wtext pa t l0 sec: true once file pa holds t at or after offset l0, polled every 20 ms 1135 note for up to sec seconds. 1136 fn nd_wtext pa view uchar * t view uchar * l0 ulong sec ulong to bool 1137 b = new uchar 262144 0 1138 t0 = ulong monons 1139 while true bound `9223372036854775807` 1140 n = dv_slurp pa b 1141 if ge n 0 1142 if ne dv_find view part b 0 ulong n t l0 dvnone 1143 ret true 1144 end 1145 end 1146 if ge sub ulong monons t0 mul sec `1000000000` 1147 ret false 1148 end 1149 x = sleepns `20000000` 1150 end 1151 ret false 1152 end 1153 1154 note nd_flen pa: the length of file pa (0 when it is missing or longer than 262144 bytes). 1155 fn nd_flen pa view uchar * to ulong 1156 b = new uchar 262144 0 1157 n = dv_slurp pa b 1158 if lt n 0 1159 ret 0 1160 end 1161 ret ulong n 1162 end 1163 1164 note nd_fake cx dl: start BUILD/fake-serve on a free port (ndport[0]) with BASE/map and delay dl 1165 note ms, stdout and stderr appended to BASE/fake.log, and wait up to 5 s for its new PORT line: 1166 note its process slot, or dvnone. 1167 fn nd_fake cx edit uchar 65536 dl ulong to ulong 1168 pk = new uchar 4096 0 1169 lg = new uchar 4096 0 1170 pt = dv_port 1171 if lt pt 0 1172 ret dvnone 1173 end 1174 put ndport 0 pt 1175 n = nd_sub cx 4 5 ndflog 1176 m = dv_cat lg 0 view part cx 20480 n 1177 l0 = nd_flen view part lg 0 m 1178 p = dv_pkinit pk 1179 p = nd_pks cx pk p 0 ndfake 1180 p = nd_pkn pk p pt 1181 p = nd_pks cx pk p 4 ndmap 1182 p = nd_pkn pk p long dl 1183 if or eq p dvnone eq m dvnone 1184 ret dvnone 1185 end 1186 pid = dv_spawna view part pk 0 p view part lg 0 m 1187 if lt pid 0 1188 ret dvnone 1189 end 1190 i = nd_track pid 1191 x = nd_wtext view part lg 0 m ndportw l0 5 1192 ret i 1193 end 1194 1195 note nd_tagp cx o tg sx: BASE/ followed by tg and sx into o; the length or dvnone. 1196 fn nd_tagp cx edit uchar 65536 o edit uchar 4096 tg view uchar * sx view uchar * to ulong 1197 a = new uchar 4096 0 1198 n = dv_cat a 0 tg 1199 n = dv_cat a n sx 1200 if eq n dvnone 1201 ret dvnone 1202 end 1203 ret dv_join o view part cx 16384 get ndl 4 view part a 0 n 1204 end 1205 1206 note nd_set cx s t: text t copied into path slot s; its length or dvnone. 1207 fn nd_set cx edit uchar 65536 s ulong t view uchar * to ulong 1208 n = dv_cat part cx mul s 4096 4096 0 t 1209 if ne n dvnone 1210 put ndl s n 1211 end 1212 ret n 1213 end 1214 1215 note nd_pknode cx pk fp vp: the node argument list: BUILD/PROGRAM and the mode words (slot 6, 1216 note "PROGRAM [MODE...]"), BUILD/infer, BUILD/tool, OMC, BASE/root, BASE/work, BASE/journal, fp, 1217 note vp, then the objective lines. 1218 fn nd_pknode cx edit uchar 65536 pk edit uchar 4096 fp long vp long to ulong 1219 w = new uchar 4096 0 1220 n = dv_cat w 0 view part cx 24576 get ndl 6 1221 e = ulong 0 1222 while lt e n bound 4097 1223 if eq get w e 32 1224 break 1225 end 1226 e = add e 1 1227 end 1228 p = dv_pkinit pk 1229 p = nd_pks cx pk p 0 view part w 0 e 1230 p = nd_pkw pk p view part w e sub n e 1231 p = nd_pks cx pk p 0 ndinfer 1232 p = nd_pks cx pk p 0 ndtool 1233 p = dv_pkadd pk p view part cx 4096 get ndl 1 1234 p = nd_pks cx pk p 4 ndroot 1235 p = nd_pks cx pk p 4 ndwork 1236 p = nd_pks cx pk p 4 ndjour 1237 p = nd_pkn pk p fp 1238 p = nd_pkn pk p vp 1239 ret nd_pkobj pk p view part cx 32768 get ndl 8 1240 end 1241 1242 note nd_fhas pa t l0: true when file pa (read up to 256 KiB) holds t at or after offset l0. 1243 fn nd_fhas pa view uchar * t view uchar * l0 ulong to bool 1244 b = new uchar 262144 0 1245 n = dv_slurp pa b 1246 if lt n 0 1247 ret false 1248 end 1249 ret ne dv_find view part b 0 ulong n t l0 dvnone 1250 end 1251 1252 note nd_nodeup fo vp i: wait up to 10 s for "CWV vp" in file fo or for process i to exit: true 1253 note when the line was seen and the process still runs. 1254 fn nd_nodeup fo view uchar * vp long i ulong to bool 1255 w = new uchar 32 0 1256 q = dv_cat w 0 ndcwv 1257 q = dv_fmtl w q vp 1258 q = dv_byte w q 10 1259 t0 = ulong monons 1260 while true bound `9223372036854775807` 1261 f = nd_fhas fo view part w 0 q 0 1262 r = nd_poll i 1263 if or f ne r -1 1264 ret and f eq r -1 1265 end 1266 if ge sub ulong monons t0 `10000000000` 1267 ret false 1268 end 1269 x = sleepns `20000000` 1270 end 1271 ret false 1272 end 1273 1274 note nd_nsp pk p fo fe n: spawn the packed list pk[0..p) with stdout to fo[0..n) and stderr to 1275 note fe[0..n): its pid, or a negative error. 1276 fn nd_nsp pk view uchar 4096 p ulong fo view uchar 4096 fe view uchar 4096 n ulong to long 1277 ret dv_spawn view part pk 0 p view part fo 0 n view part fe 0 n 1278 end 1279 1280 note nd_nodew cx tg vp i: nd_nodeup on BASE/tg.out. 1281 fn nd_nodew cx edit uchar 65536 tg view uchar * vp long i ulong to bool 1282 fo = new uchar 4096 0 1283 nl = nd_tagp cx fo tg ndout 1284 if eq nl dvnone 1285 ret false 1286 end 1287 ret nd_nodeup view part fo 0 nl vp i 1288 end 1289 1290 note nd_node cx tg fp: start the node of slot 6 ("PROGRAM [MODE...]", nd_set; e.g. "code-main" or 1291 note "code-test overload 1", PROGRAM under BUILD) with fake-serve port fp, the prepared objectives 1292 note and a free view port (ndport[1]), stdout to BASE/tg.out and stderr to BASE/tg.err, and wait for 1293 note its view (ndport[2] 1 when up): its process slot, or dvnone when it could not start. 1294 fn nd_node cx edit uchar 65536 tg view uchar * fp long to ulong 1295 pk = new uchar 4096 0 1296 fo = new uchar 4096 0 1297 fe = new uchar 4096 0 1298 put ndport 2 0 1299 vp = dv_port 1300 put ndport 1 vp 1301 if lt vp 0 1302 ret dvnone 1303 end 1304 p = nd_pknode cx pk fp vp 1305 if eq p dvnone 1306 ret dvnone 1307 end 1308 n = nd_tagp cx fo tg ndout 1309 x = nd_tagp cx fe tg nderr 1310 if or eq n dvnone ne x n 1311 ret dvnone 1312 end 1313 pid = nd_nsp pk p fo fe n 1314 if lt pid 0 1315 ret dvnone 1316 end 1317 i = nd_track pid 1318 if nd_nodew cx tg vp i 1319 put ndport 2 1 1320 end 1321 ret i 1322 end 1323 1324 note nd_outl cx tg b: file BASE/tg.out read into b: its length, or the negative dv_slurp error. 1325 fn nd_outl cx edit uchar 65536 tg view uchar * b edit uchar * to long 1326 fo = new uchar 4096 0 1327 n = nd_tagp cx fo tg ndout 1328 if eq n dvnone 1329 ret neg long 36 1330 end 1331 ret dv_slurp view part fo 0 n b 1332 end 1333 1334 note ======== omnode-op calls 1335 1336 note nd_pkop pk p w: the op word w (1 view, 2 cmd, 3 the usage control "view x") and the ndon[0] 1337 note numbers of ndoa appended. 1338 fn nd_pkop pk edit uchar 4096 p ulong w ulong to ulong 1339 q = p 1340 if eq w 2 1341 q = dv_pkadd pk q ndcmd 1342 else 1343 q = dv_pkadd pk q ndview 1344 end 1345 if eq w 3 1346 q = dv_pkadd pk q ndwx 1347 end 1348 for i ulong get ndon 0 1349 q = nd_pkn pk q get ndoa i 1350 end 1351 ret q 1352 end 1353 1354 note nd_args n a b c d e: the first n (at most 5) of a b c d e as the op numbers (ndoa, ndon[0]). 1355 fn nd_args n ulong a long b long c long d long e long to void 1356 put ndoa 0 a 1357 put ndoa 1 b 1358 put ndoa 2 c 1359 put ndoa 3 d 1360 put ndoa 4 e 1361 put ndon 0 n 1362 end 1363 1364 note nd_argx n a b c d: the first n (at most 4) of a b c d appended to the op numbers. 1365 fn nd_argx n ulong a long b long c long d long to void 1366 k = get ndon 0 1367 if gt add k n 16 1368 ret 1369 end 1370 if gt n 0 1371 put ndoa k a 1372 end 1373 if gt n 1 1374 put ndoa add k 1 b 1375 end 1376 if gt n 2 1377 put ndoa add k 2 c 1378 end 1379 if gt n 3 1380 put ndoa add k 3 d 1381 end 1382 put ndon 0 add k n 1383 end 1384 1385 note nd_op cx js tp pt w: run BUILD/op pt WORD NUMBERS... (word w as nd_pkop, the op numbers) with 1386 note stdout captured to slot 7 and a 30 s deadline; its stdout parsed onto js and tp. Sets ndr; 1387 note returns its status. 1388 fn nd_op cx edit uchar 65536 js edit uchar ndjsz tp edit uint dvtcap pt long w ulong to long 1389 pk = new uchar 4096 0 1390 put ndr 0 neg long 7 1391 put ndr 1 0 1392 p = dv_pkinit pk 1393 p = nd_pks cx pk p 0 ndop 1394 p = nd_pkn pk p pt 1395 p = nd_pkop pk p w 1396 if eq p dvnone 1397 ret neg long 7 1398 end 1399 pid = dv_spawn view part pk 0 p view part cx 28672 get ndl 7 dvnull 1400 if lt pid 0 1401 put ndr 0 pid 1402 ret pid 1403 end 1404 r = dv_wait pid `30000000000` 1405 put ndr 0 r 1406 k = dv_jload view part cx 28672 get ndl 7 js tp 1407 if gt k 0 1408 put ndr 1 1 1409 end 1410 ret r 1411 end 1412 1413 note nd_view cx js tp pt: op pt view (a snapshot): its status. 1414 fn nd_view cx edit uchar 65536 js edit uchar ndjsz tp edit uint dvtcap pt long to long 1415 put ndon 0 0 1416 ret nd_op cx js tp pt 1 1417 end 1418 1419 note nd_viewd cx js tp pt sn inc: op pt view sn inc (a delta since version sn): its status. 1420 fn nd_viewd cx edit uchar 65536 js edit uchar ndjsz tp edit uint dvtcap pt long sn long inc long to long 1421 nd_args 2 sn inc 0 0 0 1422 ret nd_op cx js tp pt 1 1423 end 1424 1425 note nd_vctl cx js tp pt: the usage control op pt view x 1: its status. 1426 fn nd_vctl cx edit uchar 65536 js edit uchar ndjsz tp edit uint dvtcap pt long to long 1427 nd_args 1 1 0 0 0 0 1428 ret nd_op cx js tp pt 3 1429 end 1430 1431 note nd_cmd cx js tp pt: op pt cmd NUMBERS (set by nd_args and nd_argx: cid opn tg inc ver, then 1432 note any operation arguments): its status. 1433 fn nd_cmd cx edit uchar 65536 js edit uchar ndjsz tp edit uint dvtcap pt long to long 1434 ret nd_op cx js tp pt 2 1435 end 1436 1437 note ======== answers of the last op call (all jsnone/missing-safe) 1438 1439 note nd_tk js tp t key: member key of object token t of the last answer; jsnone when it did not 1440 note parse, t is jsnone or no object, or key is missing. 1441 fn nd_tk js view uchar * tp view uint dvtcap t ulong key view uchar * to ulong 1442 if or eq get ndr 1 0 eq t jsnone 1443 ret jsnone 1444 end 1445 ret dv_jkey js tp t key 1446 end 1447 1448 note nd_ti js tp t key: integer member key of token t (nd_tk); 0 with ndbad set when missing. 1449 fn nd_ti js view uchar * tp view uint dvtcap t ulong key view uchar * to long 1450 v = nd_tk js tp t key 1451 if not dv_jisl js tp v 1452 put ndbad 0 1 1453 ret 0 1454 end 1455 ret dv_jnum js tp v 1456 end 1457 1458 note nd_el tp t i: element i of array token t, or jsnone. 1459 fn nd_el tp view uint dvtcap t ulong i ulong to ulong 1460 if or eq get ndr 1 0 eq t jsnone 1461 ret jsnone 1462 end 1463 ret dv_jidx tp t i 1464 end 1465 1466 note nd_ei js tp t i: integer element i of array token t; 0 with ndbad set when missing. 1467 fn nd_ei js view uchar * tp view uint dvtcap t ulong i ulong to long 1468 v = nd_el tp t i 1469 if not dv_jisl js tp v 1470 put ndbad 0 1 1471 ret 0 1472 end 1473 ret dv_jnum js tp v 1474 end 1475 1476 note nd_n tp t: the element count of array token t; 0 with ndbad set when t is no array. 1477 fn nd_n tp view uint dvtcap t ulong to ulong 1478 if or eq get ndr 1 0 eq t jsnone 1479 put ndbad 0 1 1480 ret 0 1481 end 1482 if ne js_type tp t jsarr 1483 put ndbad 0 1 1484 ret 0 1485 end 1486 ret dv_jlen tp t 1487 end 1488 1489 note nd_status js tp s: true when the last answer parsed as an object whose status is s. 1490 fn nd_status js view uchar * tp view uint dvtcap s view uchar * to bool 1491 v = nd_tk js tp 0 ndkst 1492 if eq v jsnone 1493 ret false 1494 end 1495 ret dv_jsteq js tp v s 1496 end 1497 1498 note nd_dj o p js tp t: token t's JSON text as the last answer had it (compact), or None when the 1499 note answer did not parse or t is jsnone, appended at o[p] (o is a 1024-byte detail buffer). 1500 fn nd_dj o edit uchar 1024 p ulong js view uchar * tp view uint dvtcap t ulong to ulong 1501 if or eq get ndr 1 0 eq t jsnone 1502 ret dv_cat o p ndnone 1503 end 1504 ret dv_cat o p part js js_off tp t js_span tp t 1505 end 1506 1507 note nd_frarg sv n js tp: the op numbers sv[0..3) INC VER sv[3..n), with INC and VER (incarnation, 1508 note version) of the last answer (a view). 1509 fn nd_frarg sv view long 16 n ulong js view uchar ndjsz tp view uint dvtcap to void 1510 inc = nd_ti js tp 0 ndkinc 1511 ver = nd_ti js tp 0 ndkver 1512 nd_args 5 get sv 0 get sv 1 get sv 2 inc ver 1513 for i ulong sub n 3 1514 put ndoa add i 5 get sv add i 3 1515 end 1516 put ndon 0 add n 2 1517 end 1518 1519 note nd_fresh cx js tp pt: with the op numbers cid opn tg [ARGS...] (nd_args, nd_argx), up to 20 1520 note times: view, then cmd cid opn tg INC VER ARGS... with that view's incarnation and version, 1521 note until the answer is not stale. Its status; ndr[1] 0 and no answer when a view did not parse. 1522 fn nd_fresh cx edit uchar 65536 js edit uchar ndjsz tp edit uint dvtcap pt long to long 1523 sv = new long 16 0 1524 n = get ndon 0 1525 if or lt n 3 gt n 14 1526 ret neg long 22 1527 end 1528 for i ulong n 1529 put sv i get ndoa i 1530 end 1531 r = long 0 1532 for k ulong 20 1533 r = nd_view cx js tp pt 1534 if eq get ndr 1 0 1535 ret r 1536 end 1537 nd_frarg sv n js tp 1538 r = nd_cmd cx js tp pt 1539 if not nd_status js tp ndstale 1540 ret r 1541 end 1542 end 1543 ret r 1544 end 1545 1546 note ======== the journal and the listening check 1547 1548 note nd_jset b m o: true when a settled DONE record (type 4, word 7 non-zero) among the m records 1549 note of journal b carries the operation words 3..6 of the record at b[o]. 1550 fn nd_jset b view uchar * m ulong o ulong to bool 1551 for i ulong m 1552 r = add 64 mul i 128 1553 if eq nd_w64 b r 4 1554 if ne nd_w64 b add r 56 0 1555 c = true 1556 for w ulong 4 1557 if ne nd_w64 b add r mul add w 3 8 nd_w64 b add o mul add w 3 8 1558 c = false 1559 end 1560 end 1561 if c 1562 ret true 1563 end 1564 end 1565 end 1566 end 1567 ret false 1568 end 1569 1570 note nd_jstart cx jid: true when BASE/journal/journal holds a START record (type 3) for job jid 1571 note whose operation no settled DONE record carries (view-accept.py journal_started). 1572 fn nd_jstart cx edit uchar 65536 jid ulong to bool 1573 b = new uchar `1048576` 0 1574 q = nd_sub cx 4 5 ndjfile 1575 if eq q dvnone 1576 ret false 1577 end 1578 n = dv_slurp view part cx 20480 q b 1579 if lt n 64 1580 ret false 1581 end 1582 m = div sub ulong n 64 128 1583 for i ulong m 1584 o = add 64 mul i 128 1585 if eq nd_w64 b o 3 1586 if eq nd_w64 b add o 64 jid 1587 if not nd_jset view part b 0 ulong n m o 1588 ret true 1589 end 1590 end 1591 end 1592 end 1593 ret false 1594 end 1595 1596 note nd_hexv b s e: the hexadecimal number b[s..e) (dvnone for another byte). 1597 fn nd_hexv b view uchar * s ulong e ulong to ulong 1598 v = ulong 0 1599 for i ulong sub e s 1600 c = ulong get b add s i 1601 d = dvnone 1602 if and ge c 48 le c 57 1603 d = sub c 48 1604 end 1605 if and ge c 65 le c 70 1606 d = sub c 55 1607 end 1608 if and ge c 97 le c 102 1609 d = sub c 87 1610 end 1611 if eq d dvnone 1612 ret dvnone 1613 end 1614 v = or shl v 4 d 1615 end 1616 ret v 1617 end 1618 1619 note nd_lsnl l pt: 1 when /proc/net/tcp line l is a LISTEN (st 0A) entry on local port pt. 1620 fn nd_lsnl l view uchar * pt long to ulong 1621 f = new ulong 8 0 1622 nf = ulong 0 1623 s = ulong 0 1624 inf = false 1625 for i ulong len l 1626 sp = eq get l i 32 1627 if and not sp not inf 1628 s = i 1629 inf = true 1630 end 1631 if and sp inf 1632 if lt nf 4 1633 put f mul nf 2 s 1634 put f add mul nf 2 1 i 1635 end 1636 nf = add nf 1 1637 inf = false 1638 end 1639 end 1640 if and inf lt nf 4 1641 put f mul nf 2 s 1642 put f add mul nf 2 1 len l 1643 nf = add nf 1 1644 end 1645 if lt nf 4 1646 ret 0 1647 end 1648 if ne sub get f 7 get f 6 2 1649 ret 0 1650 end 1651 if ne nd_hexv l get f 6 get f 7 10 1652 ret 0 1653 end 1654 e = get f 3 1655 c = e 1656 while gt c get f 2 bound 64 1657 if eq get l sub c 1 58 1658 break 1659 end 1660 c = sub c 1 1661 end 1662 if eq c get f 2 1663 ret 0 1664 end 1665 if eq nd_hexv l c e ulong pt 1666 ret 1 1667 end 1668 ret 0 1669 end 1670 1671 note nd_lsnb b pt: count (into ndlc) the LISTEN entries on pt among the complete lines of b: 1672 note the bytes consumed (through the last newline). 1673 fn nd_lsnb b view uchar * pt long to ulong 1674 s = ulong 0 1675 i = ulong 0 1676 while lt i len b bound `16777217` 1677 if eq get b i 10 1678 put ndlc 0 add get ndlc 0 nd_lsnl view part b s sub i s pt 1679 s = add i 1 1680 end 1681 i = add i 1 1682 end 1683 ret s 1684 end 1685 1686 note nd_lsnf pa pt: the number of LISTEN entries on port pt in table pa (/proc/net/tcp or tcp6), 1687 note read in 65536-byte chunks; 0 when it cannot be opened. 1688 fn nd_lsnf pa view uchar * pt long to ulong 1689 b = new uchar 65536 0 1690 put ndlc 0 0 1691 fd = fopen pa 0 len pa 524288 0 1692 if lt fd 0 1693 ret 0 1694 end 1695 n = ulong 0 1696 while true bound `16777217` 1697 k = read int fd b n sub 65536 n 1698 if le k 0 1699 break 1700 end 1701 n = add n ulong k 1702 s = nd_lsnb view part b 0 n pt 1703 for j ulong sub n s 1704 put b j get b add s j 1705 end 1706 n = sub n s 1707 if ge n 65536 1708 n = 0 1709 end 1710 end 1711 if gt n 0 1712 put ndlc 0 add get ndlc 0 nd_lsnl view part b 0 n pt 1713 end 1714 x = fclose int fd 1715 ret get ndlc 0 1716 end 1717 1718 note nd_lsn pt: true when some TCP socket (IPv4 or IPv6) listens on port pt (ss -ltn's answer). 1719 fn nd_lsn pt long to bool 1720 a = nd_lsnf ndtcp pt 1721 b = nd_lsnf ndtcp6 pt 1722 ret gt add a b 0 1723 end