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/sovereign-intelligence/blob/main/compiler/gate.om # sovereign-intelligence Front door to Drake Stapleton's sovereign stack. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `sovereign-intelligence / compiler / gate.om` 2113 lines ยท 42733 bytes Raw Blame History 1 om2 2 note compiler/gate.om: the gate of compiler/si.om, in pure seeded Omega. 3 note 4 note Build and run from the repository root, with the pinned seeded compiler and an existing 5 note scratch directory WORK: 6 note "$OMC" < compiler/gate.om > WORK/gate && chmod +x WORK/gate && WORK/gate "$OMC" WORK 7 note It checks that OMC is the pinned omc by its sha256 (any other omc, or none: SI NOT_RUN, exit 3), 8 note builds si from compiler/si.om and links from compiler/links.om with it into WORK/si and 9 note WORK/links, then runs the original thirty-five cases and seven rebuild cases: 10 note 1 the committed inputs (compiler/inventory.tsv, order.tsv and the generated Radicle state 11 note compiler/state.tsv) regenerate README.md and repos.tsv byte-identically (exit 0) 12 note 2 typed head: the first inventory row given a fourth field of 40 hex digits after its RID 13 note is refused: heads, branches and visibility come only from the Radicle state 14 note 3 RID mutant: the last character of the first inventory row's RID changed is refused (no 15 note default branch from a Radicle identity for it) 16 note 4 the old inventory of commit `3c37e6fb` (compiler/gate-`3c37e6fb`.tsv), five fields with a typed 17 note visibility and head, is refused as typed 18 note 34 private: the committed Radicle state with its first V line (the first inventory row's 19 note project) made "private" is refused: a listed project must be public on Radicle 20 note 35 stale block: README.md with the first generated head of its project table one digit off is 21 note not carried forward: si's output is the committed README.md again, so build.sh's 22 note comparison of the committed README.md with si's output catches a stale block 23 note 5 links on the repository root passes: every link row valid, no project source vendored 24 note 6 link RID mutant: WORK/5-tree/repos.tsv, the first link row's RID ending in 0 (not base58), 25 note is refused by links 26 note 7 link crypto mutant: WORK/6-tree/repos.tsv, the first link row's RID starting rad:z2ft64 27 note (the withdrawn crypto project), is refused by links 28 note 8 vendored mutant: WORK/7-tree, the committed repos.tsv beside a planted project directory 29 note omega-mv holding main.om, is refused by links 30 note 9 minimal tree: WORK/A-tree, the committed repos.tsv and compiler/ holding only its eight 31 note allowed file names (empty), passes links; cases 10-33 each change one thing in it 32 note 10-20 link-row mutants of WORK/B-tree to WORK/L-tree/repos.tsv, each refused by links with 33 note its own message: the first link row's name Omega-Pearl and aien-CRYPTO-mv (withdrawn 34 note crypto, any case) and ../x (bad name); its head with capitals, with a g, and 41 digits; 35 note its tier Core; its RID with a 29th character, and rad:z then 28 z (more than 20 bytes); 36 note the header's first field nam; and the header with no row after it 37 note 21-26 planted entries, each refused by links as not an SI file: compiler/evil.om (WORK/M-tree), 38 note compiler/si.om as a symbolic link to gate.om (N), a root symbolic link lnk to compiler (O), 39 note a root file evil.rs (P), a root directory vendor (Q) and gpu/x.bin (R) 40 note 27 README.zh-CN.md, an empty regular file at the root of the minimal tree (WORK/S-tree), 41 note passes links: the one translation SI holds (Drake, 2026-11-11, "approved for all") 42 note 28-33 planted entries, each refused by links as not an SI file: compiler/README.zh-CN.md 43 note (WORK/T-tree), a root README.zh-TW.md (U), README.fr.md (V) and readme.zh-cn.md (W), and a 44 note root README.zh-CN.md as a symbolic link to repos.tsv (X) and as a directory (Y) 45 note The si mutants are written to WORK/head.tsv, WORK/rid.tsv and WORK/priv.tsv. Cases 2-4, 34, 46 note 6, 7 and 10-20 first check that the input's sha256 differs from the committed file's, and cases 8 and 21-33 that the 47 note planted entry exists, so an edit that did not apply cannot pass as a refusal. An si refusal 48 note must be exit 1, stderr starting "si: " and the expected message, the README copy unchanged and 49 note no repos.tsv written; a links refusal exit 1 and stderr starting "links: " and the expected 50 note message; links passing exit 0 and stdout starting "links: pass: ". Each case prints PASS or 51 note FAIL with the evidence, then "SI pass=N fail=M"; exit 0 when no case fails, 1 otherwise, 2 on 52 note a usage error. links reads a directory entry's kind from getdents64 and refuses DT_UNKNOWN, 53 note which no case plants: ext4 and tmpfs never return it. 54 note Rebuild: a real Git fixture's two rebuilt artifacts must match its committed file. A changed 55 note artifact, exit 7, an off-chip hardware row even with hw=yes, and a deleted layer row must 56 note fail. Missing commands and macOS-only steps are NOT_RUN and cannot satisfy layers 1 and 2. 57 note SHA-256 (fn kinit to fn finish) is copied unchanged from omega-mv om/sha256/sha256-om2.om 58 note at `f4df82394e35893dcf1354dda69a2fe028d94bc1` (Apache-2.0, FIPS 180-4). 59 60 text tpin "`3ad9f10f64309e7acf8a725082b28e23a2a4aeb07e98322fb4dc0fcd8fc93194`" 61 text tusage "usage: gate OMC WORK (from the repository root; WORK is an existing directory)\n" 62 text tnrun "SI NOT_RUN: " 63 text tnoomc "cannot read omc " 64 text tnotpin "omc sha256 is not the pin " 65 text thave ", it is " 66 text tnl "\n" 67 text tpass "PASS " 68 text tfail "FAIL " 69 text tsep ": " 70 text tsum "SI pass=" 71 text tsumf " fail=" 72 text tsiom "compiler/si.om" 73 text tinv "compiler/inventory.tsv" 74 text tord "compiler/order.tsv" 75 text tsta "compiler/state.tsv" 76 text told "compiler/gate-`3c37e6fb`.tsv" 77 text trd "README.md" 78 text trepos "repos.tsv" 79 text tsi "si" 80 text tomcerr "omc.err" 81 text thead "head.tsv" 82 text trid "rid.tsv" 83 text xreadme "-README.md" 84 text xrepos "-repos.tsv" 85 text xsh "-si.sh" 86 text xout "-out" 87 text xerr "-err" 88 text tcomp "build si from compiler/si.om" 89 text tlom "compiler/links.om" 90 text tlinks "links" 91 text tlcomp "build links from compiler/links.om" 92 text tdot "." 93 text xtree "-tree" 94 text xtrepo "-tree/repos.tsv" 95 text xvdir "-tree/omega-mv" 96 text xvfile "-tree/omega-mv/main.om" 97 text tlcur "links-current" 98 text tlrid "links-rid-mutant" 99 text tlcry "links-crypto-mutant" 100 text tlven "links-vendored-mutant" 101 text mlk "links: " 102 text mlpass "pass: " 103 text mlrid "RID is not rad:z" 104 text mlcry "withdrawn crypto project is never linked" 105 text mlven "not an SI file" 106 text tz2ft "2ft64" 107 text fplant "the planted project file is missing" 108 text tcur "current inventory regenerates README.md and repos.tsv byte-identically" 109 text thm "typed-head" 110 text trm "rid-mutant" 111 text tom "old-`3c37e6fb`" 112 text msi "si: " 113 text mhead "inventory carries a typed head, branch or visibility; those come from Radicle (tools/si-state.sh): " 114 text mrid "no default branch from a Radicle identity for: " 115 text tpv "private-state" 116 text tpriv "priv.tsv" 117 text mpriv "listed project is not public on Radicle: " 118 text tpub "public" 119 text tprw "private" 120 text tstl "stale-block" 121 text tibeg "" 122 text tgitc ".git) | `" 123 text tixc "` | `" 124 text fstale "the stale head could not be planted in the README copy" 125 text fstok ": README.md with its first generated head one digit off regenerates to the committed README.md and repos.tsv\n" 126 text fsame "input sha256 equals the committed inventory's" 127 text frc "exit status " 128 text fmsg "stderr lacks the expected refusal" 129 text frd "README.md copy was changed" 130 text frepo "repos.tsv was written" 131 text fio "cannot read or write a gate file" 132 text fdiff "regenerated output differs from the committed file" 133 text tsha "sha256 " 134 text tarrow " -> " 135 text tref " refused: " 136 text hexd "`0123456789abcdef`" 137 text tcmpd "/compiler" 138 text tf1 "/README.md" 139 text tf2 "/si.om" 140 text tf3 "/gate.om" 141 text tf4 "/links.om" 142 text tf5 "/inventory.tsv" 143 text tf6 "/order.tsv" 144 text tf7 "/state.tsv" 145 text tf8 "/gate-`3c37e6fb`.tsv" 146 text tp1 "/compiler/evil.om" 147 text tp2 "/compiler/si.om" 148 text tp3 "/lnk" 149 text tp4 "/evil.rs" 150 text tp5 "/vendor" 151 text tp6 "/gpu/x.bin" 152 text tp7 "/README.zh-CN.md" 153 text tp8 "/compiler/README.zh-CN.md" 154 text tp9 "/README.zh-TW.md" 155 text tp10 "/README.fr.md" 156 text tp11 "/readme.zh-cn.md" 157 text tgpud "/gpu" 158 text ts2 "gate.om" 159 text ts3 "compiler" 160 text cgood "links-minimal-tree" 161 text cpearl "links-name-pearl" 162 text ccrypto "links-name-crypto" 163 text cname "links-name-bad" 164 text chupper "links-head-upper" 165 text chg "links-head-g" 166 text ch41 "links-head-41" 167 text ctier "links-tier-bad" 168 text crlong "links-rid-long" 169 text crbig "links-rid-big" 170 text chdr "links-header" 171 text chonly "links-header-only" 172 text ccfile "links-compiler-file" 173 text cclink "links-compiler-link" 174 text crlink "links-root-link" 175 text crfile "links-root-file" 176 text crdir "links-root-dir" 177 text cgfile "links-gpu-file" 178 text czh "links-root-readme-zh-CN" 179 text czsub "links-compiler-readme-zh-CN" 180 text cztw "links-root-readme-zh-TW" 181 text czfr "links-root-readme-fr" 182 text czlc "links-root-readme-zh-cn-lowercase" 183 text czlink "links-root-readme-zh-CN-link" 184 text czdir "links-root-readme-zh-CN-dir" 185 text rpearl "Omega-Pearl" 186 text rcrypt "aien-CRYPTO-mv" 187 text rbadn "../x" 188 text rhup "ABCDEF0123456789ABCDEF0123456789ABCDEF01" 189 text rhg "g123456789abcdef0123456789abcdef01234567" 190 text rzero "0" 191 text rtier "Core" 192 text rz "z" 193 text rbig "rad:zzzzzzzzzzzzzzzzzzzzzzzzzzzzz" 194 text rnam "nam" 195 text mlname "bad project name" 196 text mlhead "head is not a 40-digit lowercase hex commit" 197 text mltier "tier is not core or rest" 198 text mlhdr "repos.tsv header is not" 199 text mlnone "repos.tsv lists no project" 200 201 note file buffers, the path being built, the two arguments, the packed argv of a child 202 global fb uchar `4194304` 203 global gb uchar `4194304` 204 global pb uchar 4096 205 global pbn ulong 1 206 global wd uchar 2048 207 global wdn ulong 1 208 global om uchar 2048 209 global omn ulong 1 210 global av uchar 16384 211 global avp ulong 1 212 global avc ulong 1 213 note child wait status, last digest, its hex and the previous hex, decimal digits, pass and fail counts 214 global st uchar 4 215 global dg uchar 32 216 global hx uchar 64 217 global hy uchar 64 218 global dgt uchar 24 219 global tally ulong 2 220 note lf: start and end of the field lfind found; sb: an lstat buffer 221 global lf ulong 2 222 global sb uchar 256 223 224 note K[0..63]: the first 32 bits of the fractional parts of the cube roots of the first 64 primes. 225 note Copied mechanically from seed/qualification/om2/fixtures/sha256-k.dec (tool-computed, never typed). 226 fn kinit k edit uint 64 to void 227 put k 0 0x428a2f98 228 put k 1 0x71374491 229 put k 2 0xb5c0fbcf 230 put k 3 0xe9b5dba5 231 put k 4 0x3956c25b 232 put k 5 0x59f111f1 233 put k 6 0x923f82a4 234 put k 7 0xab1c5ed5 235 put k 8 0xd807aa98 236 put k 9 0x12835b01 237 put k 10 0x243185be 238 put k 11 0x550c7dc3 239 put k 12 0x72be5d74 240 put k 13 0x80deb1fe 241 put k 14 0x9bdc06a7 242 put k 15 0xc19bf174 243 put k 16 0xe49b69c1 244 put k 17 0xefbe4786 245 put k 18 0x0fc19dc6 246 put k 19 0x240ca1cc 247 put k 20 0x2de92c6f 248 put k 21 0x4a7484aa 249 put k 22 0x5cb0a9dc 250 put k 23 0x76f988da 251 put k 24 0x983e5152 252 put k 25 0xa831c66d 253 put k 26 0xb00327c8 254 put k 27 0xbf597fc7 255 put k 28 0xc6e00bf3 256 put k 29 0xd5a79147 257 put k 30 0x06ca6351 258 put k 31 0x14292967 259 put k 32 0x27b70a85 260 put k 33 0x2e1b2138 261 put k 34 0x4d2c6dfc 262 put k 35 0x53380d13 263 put k 36 0x650a7354 264 put k 37 0x766a0abb 265 put k 38 0x81c2c92e 266 put k 39 0x92722c85 267 put k 40 0xa2bfe8a1 268 put k 41 0xa81a664b 269 put k 42 0xc24b8b70 270 put k 43 0xc76c51a3 271 put k 44 0xd192e819 272 put k 45 0xd6990624 273 put k 46 0xf40e3585 274 put k 47 0x106aa070 275 put k 48 0x19a4c116 276 put k 49 0x1e376c08 277 put k 50 0x2748774c 278 put k 51 0x34b0bcb5 279 put k 52 0x391c0cb3 280 put k 53 0x4ed8aa4a 281 put k 54 0x5b9cca4f 282 put k 55 0x682e6ff3 283 put k 56 0x748f82ee 284 put k 57 0x78a5636f 285 put k 58 0x84c87814 286 put k 59 0x8cc70208 287 put k 60 0x90befffa 288 put k 61 0xa4506ceb 289 put k 62 0xbef9a3f7 290 put k 63 0xc67178f2 291 end 292 293 note H(0): the first 32 bits of the fractional parts of the square roots of the first 8 primes 294 note (fixtures/sha256-iv.dec). 295 fn iv s edit uint 8 to void 296 put s 0 0x6a09e667 297 put s 1 0xbb67ae85 298 put s 2 0x3c6ef372 299 put s 3 0xa54ff53a 300 put s 4 0x510e527f 301 put s 5 0x9b05688c 302 put s 6 0x1f83d9ab 303 put s 7 0x5be0cd19 304 end 305 306 note Message schedule of the block m[o .. o+64). w is fresh: its incoming contents are never read. 307 note The compiler proves that every get of w reads an element written earlier in this function 308 note (error 27 otherwise): w[0..16) are the block's big-endian words, w[16..64) the FIPS recurrence. 309 fn sched w edit uint 64 fresh m view uchar * o ulong to void 310 q = ulong 0 311 x = uint 0 312 y = uint 0 313 for i ulong 16 unroll 314 q = add o mul i 4 315 x = uint get m q 316 x = or shl x 8 uint get m add q 1 317 x = or shl x 8 uint get m add q 2 318 put w i or shl x 8 uint get m add q 3 319 end 320 for i ulong 48 unroll 321 x = get w add i 1 322 y = get w add i 14 323 x = add add get w i get w add i 9 xor xor rotr x 7 rotr x 18 shr x 3 324 put w add i 16 add x xor xor rotr y 17 rotr y 19 shr y 10 325 end 326 end 327 328 note The 64 rounds on the chaining value s. One round body, emitted 64 times by unroll; i is a constant 329 note in each copy, so get kt i and get w i need no run-time check. uint arithmetic wraps mod 2^32. 330 note Ch(e,f,g) = (e and f) xor (not e and g) is written g xor (e and (f xor g)); Maj(a,b,c) = 331 note (a and b) xor (a and c) xor (b and c) is written (a and b) or (c and (a or b)). Both are bitwise 332 note identities. h first becomes T1, then T1 + T2, which is the next a; the names then shift by one. 333 note The sums are built a term per line and each Sigma in two lines through t: 12 names are live, and 334 note omc hands out 16 registers with no spilling (error 12 under compiler-s1/s2 for longer lines). 335 fn rounds s edit uint 8 w view uint 64 kt view uint 64 to void 336 a = get s 0 337 b = get s 1 338 c = get s 2 339 d = get s 3 340 e = get s 4 341 f = get s 5 342 g = get s 6 343 h = get s 7 344 t = uint 0 345 for i ulong 64 unroll 346 h = add h get kt i 347 h = add h get w i 348 t = xor rotr e 6 rotr e 11 349 t = xor t rotr e 25 350 h = add h t 351 h = add h xor g and e xor f g 352 d = add d h 353 t = xor rotr a 2 rotr a 13 354 t = xor t rotr a 22 355 h = add h t 356 t = and c or a b 357 h = add h or and a b t 358 t = h 359 h = g 360 g = f 361 f = e 362 e = d 363 d = c 364 c = b 365 b = a 366 a = t 367 end 368 put s 0 add get s 0 a 369 put s 1 add get s 1 b 370 put s 2 add get s 2 c 371 put s 3 add get s 3 d 372 put s 4 add get s 4 e 373 put s 5 add get s 5 f 374 put s 6 add get s 6 g 375 put s 7 add get s 7 h 376 end 377 378 note One block m[o .. o+64) into s. sched and rounds stay calls: inlined, their names would share 379 note one 16-register frame with this function's parameters (no spilling, error 12). 380 fn compress s edit uint 8 w edit uint 64 kt view uint 64 m view uchar * o ulong to void 381 sched w m o 382 rounds s w kt 383 end 384 385 note The whole blocks of m (len m is a multiple of 64 and at most 2^25, so under 2^19 passes). 386 fn run s edit uint 8 w edit uint 64 kt view uint 64 m view uchar * to void 387 for j ulong shr len m 6 388 compress s w kt m shl j 6 389 end 390 end 391 392 note The whole blocks of m (len m a multiple of 64). A rolled loop traps 4 after `1000000` passes 393 note (OMEGESE.md section 2; omc s_for), so m is cut into runs of 2^25 bytes (2^19 blocks): 394 note len m = top * 2^44 + mid * 2^25 + rest, and no loop passes 2^20 times. top reaches `1000000` 395 note only above 1.7e19 bytes, which no AArch64 address space holds. 396 fn blocks s edit uint 8 w edit uint 64 kt view uint 64 m view uchar * to void 397 q = ulong 0 398 for a ulong shr len m 44 399 for b ulong 0x80000 400 run s w kt part m q 0x2000000 401 q = add q 0x2000000 402 end 403 end 404 for b ulong and shr len m 25 0x7ffff 405 run s w kt part m q 0x2000000 406 q = add q 0x2000000 407 end 408 run s w kt part m q sub len m q 409 end 410 411 note Pad the k pending bytes already in p (k < 64; p was all zero past them): 0x80, zeros, and the 412 note 64-bit big-endian bit length of the n-byte message in the last 8 bytes of one or two blocks. 413 fn finish s edit uint 8 w edit uint 64 kt view uint 64 p edit uchar 128 k ulong n ulong to void 414 put p k 0x80 415 e = ulong 64 416 if ge k 56 417 e = 128 418 end 419 bits = shl n 3 420 for i ulong 8 unroll 421 put p sub e add i 1 uchar and shr bits mul i 8 0xff 422 end 423 compress s w kt view p 0 424 if eq e 128 425 compress s w kt view p 64 426 end 427 end 428 429 430 note blkcopy: the 64 bytes of fb from o into b (omc refuses a global as an argument, error 19) 431 fn blkcopy b edit uchar 64 o ulong to void 432 for i ulong 64 433 put b i get fb add o i 434 end 435 end 436 437 note sha: SHA-256 of fb[0, n) into dg; sha256_hash of om/sha256/sha256-om2.om, reading each 438 note whole block of fb through a local copy 439 fn sha n ulong to void 440 s = new uint 8 0 441 w = new uint 64 0 442 kt = new uint 64 0 443 p = new uchar 128 0 444 blk = new uchar 64 0 445 kinit kt 446 iv s 447 nb = shr n 6 448 for j ulong nb 449 blkcopy blk shl j 6 450 compress s w kt view blk 0 451 end 452 off = shl nb 6 453 k = sub n off 454 for i ulong k 455 put p i get fb add off i 456 end 457 finish s w kt p k n 458 digest s 459 end 460 461 note digest: the chaining value s, big-endian, into dg 462 fn digest s view uint 8 to void 463 v = ulong 0 464 for i ulong 8 unroll 465 v = ulong get s i 466 for j ulong 4 unroll 467 put dg add mul i 4 j uchar and shr v sub 24 mul j 8 0xff 468 end 469 end 470 end 471 472 note hexdg: dg in lowercase hex into hx 473 fn hexdg to void 474 for i ulong 32 475 b = ulong get dg i 476 put hx mul i 2 get hexd shr b 4 477 put hx add mul i 2 1 get hexd and b 15 478 end 479 end 480 481 fn say t view uchar * to void 482 w = write 1 t 0 len t 483 end 484 485 note sayn: v in decimal on stdout 486 fn sayn v ulong to void 487 x = v 488 k = ulong 1 489 put dgt 0 uchar add rem x 10 48 490 x = div x 10 491 while gt x 0 bound 24 492 put dgt k uchar add rem x 10 48 493 k = add k 1 494 x = div x 10 495 end 496 while gt k 0 bound 24 497 k = sub k 1 498 w = write 1 dgt k 1 499 end 500 end 501 502 fn pclr to void 503 put pbn 0 0 504 end 505 506 note padd: append a text to the path pb 507 fn padd t view uchar * to void 508 p = get pbn 0 509 n = len t 510 for i ulong n 511 put pb add p i get t i 512 end 513 put pbn 0 add p n 514 end 515 516 note pwd: pb becomes WORK/ 517 fn pwd to void 518 n = get wdn 0 519 for i ulong n 520 put pb i get wd i 521 end 522 put pb n 47 523 put pbn 0 add n 1 524 end 525 526 note pcase: pb becomes WORK/, a file of case v 527 fn pcase v ulong t view uchar * to void 528 pwd 529 p = get pbn 0 530 put pb p uchar add 48 v 531 put pbn 0 add p 1 532 padd t 533 end 534 535 note psta: pb becomes the Radicle state of case v: WORK/priv.tsv for case 34 (v 49), else the 536 note committed compiler/state.tsv 537 fn psta v ulong to void 538 pclr 539 if eq v 49 540 pwd 541 padd tpriv 542 else 543 padd tsta 544 end 545 end 546 547 note pinv: pb becomes the inventory of case v 548 fn pinv v ulong to void 549 pclr 550 if or eq v 0 or eq v 49 eq v 50 551 padd tinv 552 end 553 if eq v 1 554 pwd 555 padd thead 556 end 557 if eq v 2 558 pwd 559 padd trid 560 end 561 if eq v 3 562 padd told 563 end 564 end 565 566 note rdf, rdg: read the file named by pb into fb or gb; its length, `4194304` when unreadable or too big 567 fn rdf to ulong 568 fd = fopen pb 0 get pbn 0 524288 0 569 if lt fd 0 570 ret `4194304` 571 end 572 p = ulong 0 573 while lt p `4194304` bound `4194305` 574 k = read int fd fb p sub `4194304` p 575 if lt k 0 576 p = `4194304` 577 break 578 end 579 if eq k 0 580 break 581 end 582 p = add p ulong k 583 end 584 c = fclose int fd 585 ret p 586 end 587 588 fn rdg to ulong 589 fd = fopen pb 0 get pbn 0 524288 0 590 if lt fd 0 591 ret `4194304` 592 end 593 p = ulong 0 594 while lt p `4194304` bound `4194305` 595 k = read int fd gb p sub `4194304` p 596 if lt k 0 597 p = `4194304` 598 break 599 end 600 if eq k 0 601 break 602 end 603 p = add p ulong k 604 end 605 c = fclose int fd 606 ret p 607 end 608 609 note wrf: write fb[0, n) to the file named by pb, created or truncated, mode 0644 610 fn wrf n ulong to bool 611 fd = fopen pb 0 get pbn 0 524865 420 612 if lt fd 0 613 ret false 614 end 615 p = ulong 0 616 while lt p n bound `4194305` 617 k = write int fd fb p sub n p 618 if le k 0 619 c = fclose int fd 620 ret false 621 end 622 p = add p ulong k 623 end 624 c = fclose int fd 625 ret eq c 0 626 end 627 628 note opr, opw: open pb to read, or to write (created or truncated); the fd, negative on failure 629 fn opr to int 630 ret int fopen pb 0 get pbn 0 524288 0 631 end 632 633 fn opw to int 634 ret int fopen pb 0 get pbn 0 524865 420 635 end 636 637 note astart, aadd: begin the packed argv of a child, append pb as its next argument 638 fn astart to void 639 put avp 0 2 640 put avc 0 0 641 end 642 643 fn aadd to void 644 p = get avp 0 645 n = get pbn 0 646 put av p uchar and n 255 647 put av add p 1 uchar shr n 8 648 p = add p 2 649 for i ulong n 650 put av add p i get pb i 651 end 652 put avp 0 add p n 653 put avc 0 add get avc 0 1 654 end 655 656 note spawn: run the argv in av with fds i, o, e as stdin, stdout and stderr; its exit status, 657 note 256 plus the signal when a signal ended it, 512 when it could not be run 658 fn spawn i int o int e int to ulong 659 put av 0 uchar and get avc 0 255 660 put av 1 uchar shr get avc 0 8 661 pid = fork 662 if lt pid 0 663 ret 512 664 end 665 if eq pid 0 666 r = dupfd i 0 0 667 r = dupfd o 1 0 668 r = dupfd e 2 0 669 r = execprog av 0 get avp 0 670 exit 98 671 end 672 c = fclose i 673 c = fclose o 674 c = fclose e 675 r = waitpid int pid st 0 4 0 676 if ne r pid 677 ret 512 678 end 679 if ne get st 0 0 680 ret add 256 ulong get st 0 681 end 682 ret ulong get st 1 683 end 684 685 note pin: OMC must be readable and its sha256 the pin, else SI NOT_RUN and exit 3 686 fn pin to void 687 n = get omn 0 688 for i ulong n 689 put pb i get om i 690 end 691 put pbn 0 n 692 m = rdf 693 if ge m `4194304` 694 say tnrun 695 say tnoomc 696 w = write 1 om 0 get omn 0 697 say tnl 698 exit 3 699 end 700 sha m 701 hexdg 702 for i ulong 64 703 if ne get hx i get tpin i 704 say tnrun 705 say tnotpin 706 say tpin 707 say thave 708 w = write 1 hx 0 64 709 say tnl 710 exit 3 711 end 712 end 713 end 714 715 note fatal: a gate step that every case needs failed; exit 1 716 fn fatal t view uchar * r ulong to void 717 say tfail 718 say t 719 say tsep 720 say frc 721 sayn r 722 say tnl 723 exit 1 724 end 725 726 note build: OMC < source s > WORK/b, with nothing on stderr, then chmod 0755; step t names it 727 fn build s view uchar * b view uchar * t view uchar * to void 728 astart 729 n = get omn 0 730 for i ulong n 731 put pb i get om i 732 end 733 put pbn 0 n 734 aadd 735 pclr 736 padd s 737 i = opr 738 pwd 739 padd b 740 o = opw 741 pwd 742 padd tomcerr 743 e = opw 744 if or lt i 0 or lt o 0 lt e 0 745 fatal fio 0 746 end 747 r = spawn i o e 748 pwd 749 padd tomcerr 750 n = rdf 751 if or ne r 0 ne n 0 752 fatal t r 753 end 754 pwd 755 padd b 756 c = chmod pb 0 get pbn 0 493 757 if ne c 0 758 fatal fio 0 759 end 760 end 761 762 note runsi: copy README.md to WORK/-README.md (for case 50 with a stale head planted), then run 763 note WORK/si on case v's inventory and Radicle state, writing 764 note WORK/-README.md, -repos.tsv and -si.sh, stdout to -out, stderr to -err; its exit status 765 fn runsi v ulong to ulong 766 pclr 767 padd trd 768 n = rdf 769 if ge n `4194304` 770 ret 513 771 end 772 if eq v 50 773 if not stale n 774 ret 514 775 end 776 end 777 pcase v xreadme 778 if not wrf n 779 ret 513 780 end 781 pcase v xrepos 782 r = unlink pb 0 get pbn 0 783 pcase v xsh 784 r = unlink pb 0 get pbn 0 785 astart 786 pwd 787 padd tsi 788 aadd 789 pinv v 790 aadd 791 pclr 792 padd tord 793 aadd 794 psta v 795 aadd 796 pcase v xreadme 797 aadd 798 pcase v xrepos 799 aadd 800 pcase v xsh 801 aadd 802 pclr 803 padd tsta 804 i = opr 805 pcase v xout 806 o = opw 807 pcase v xerr 808 e = opw 809 if or lt i 0 or lt o 0 lt e 0 810 ret 513 811 end 812 ret spawn i o e 813 end 814 815 note same: are WORK/ and the committed file t byte-identical 816 fn same v ulong x view uchar * t view uchar * to bool 817 pcase v x 818 n = rdf 819 pclr 820 padd t 821 m = rdg 822 if or ge n `4194304` ne n m 823 ret false 824 end 825 for i ulong n 826 if ne get fb i get gb i 827 ret false 828 end 829 end 830 ret true 831 end 832 833 note showx: the first line of case v's file WORK/, at most 300 bytes, then a newline 834 fn showx v ulong x view uchar * to void 835 pcase v x 836 n = rdf 837 if ge n `4194304` 838 n = 0 839 end 840 k = ulong 0 841 while lt k n bound `4194305` 842 if or eq get fb k 10 ge k 300 843 break 844 end 845 k = add k 1 846 end 847 w = write 1 fb 0 k 848 say tnl 849 end 850 851 note showerr: the first line of case v's stderr 852 fn showerr v ulong to void 853 showx v xerr 854 end 855 856 note errhas: does case v's stderr start with "si: " and the text m 857 fn errhas v ulong m view uchar * to bool 858 pcase v xerr 859 n = rdf 860 a = len msi 861 if or ge n `4194304` lt n add a len m 862 ret false 863 end 864 for i ulong a 865 if ne get fb i get msi i 866 ret false 867 end 868 end 869 for i ulong len m 870 if ne get fb add a i get m i 871 ret false 872 end 873 end 874 ret true 875 end 876 877 note absent: was case v's repos.tsv never written 878 fn absent v ulong to bool 879 pcase v xrepos 880 fd = fopen pb 0 get pbn 0 524288 0 881 if lt fd 0 882 ret true 883 end 884 c = fclose int fd 885 ret false 886 end 887 888 fn ok t view uchar * to void 889 put tally 0 add get tally 0 1 890 say tpass 891 say t 892 end 893 894 fn bad t view uchar * to void 895 put tally 1 add get tally 1 1 896 say tfail 897 say t 898 say tsep 899 end 900 901 note current: case 0, the committed inventory regenerates README.md and repos.tsv byte-identically 902 fn current to void 903 r = runsi 0 904 if eq r 0 905 if same 0 xreadme trd 906 if same 0 xrepos trepos 907 ok tcur 908 say tnl 909 ret 910 end 911 end 912 bad tcur 913 say fdiff 914 say tnl 915 ret 916 end 917 bad tcur 918 say frc 919 sayn r 920 say tsep 921 showerr 0 922 end 923 924 note mutate: write case v's mutant of the committed inventory: v 1 gives the first row a typed 925 note head, a fourth field of 40 hex digits after its RID; v 2 changes the last character of its 926 note RID to X (X to Y) 927 fn mutate v ulong to bool 928 pclr 929 padd tinv 930 n = rdf 931 if ge n `4194000` 932 ret false 933 end 934 t = ulong 0 935 p = ulong 0 936 q = ulong 0 937 while lt q n bound `4194305` 938 c = get fb q 939 if eq c 10 940 break 941 end 942 if eq c 9 943 t = add t 1 944 if eq t 2 945 p = q 946 break 947 end 948 end 949 q = add q 1 950 end 951 if eq p 0 952 ret false 953 end 954 if eq v 1 955 m = sub n p 956 for j ulong m 957 k = sub sub n 1 j 958 put fb add k 41 get fb k 959 end 960 put fb p uchar 9 961 for jj ulong 40 962 put fb add add p 1 jj get hexd rem jj 16 963 end 964 pinv v 965 ret wrf add n 41 966 end 967 x = get fb sub p 1 968 y = uchar 88 969 if eq x 88 970 y = uchar 89 971 end 972 put fb sub p 1 y 973 pinv v 974 ret wrf n 975 end 976 977 note mstate: write WORK/priv.tsv, the committed Radicle state with its first V line's "public" 978 note made "private": the first inventory row's project, since tools/si-state.sh writes the RIDs 979 note in inventory order 980 fn mstate to bool 981 pclr 982 padd tsta 983 n = rdf 984 if or lt n 16 ge n `4194000` 985 ret false 986 end 987 s = vline n 988 if eq s n 989 ret false 990 end 991 e = s 992 while lt e n bound `4194305` 993 if eq get fb e 10 994 break 995 end 996 e = add e 1 997 end 998 if lt sub e s 10 999 ret false 1000 end 1001 o = sub e 6 1002 if not ispub o 1003 ret false 1004 end 1005 shift1 n e 1006 for j ulong 7 1007 put fb add o j get tprw j 1008 end 1009 pwd 1010 padd tpriv 1011 ret wrf add n 1 1012 end 1013 1014 note vline: where the first line starting "V TAB" after the first line of fb[0, n) starts, or n 1015 fn vline n ulong to ulong 1016 q = ulong 0 1017 while lt q sub n 2 bound `4194305` 1018 if eq get fb q 10 1019 if eq get fb add q 1 86 1020 if eq get fb add q 2 9 1021 ret add q 1 1022 end 1023 end 1024 end 1025 q = add q 1 1026 end 1027 ret n 1028 end 1029 1030 note ispub: does fb hold "public" at o 1031 fn ispub o ulong to bool 1032 for j ulong 6 1033 if ne get fb add o j get tpub j 1034 ret false 1035 end 1036 end 1037 ret true 1038 end 1039 1040 note shift1: move fb[e, n) one byte to the right 1041 fn shift1 n ulong e ulong to void 1042 m = sub n e 1043 for j ulong m 1044 k = sub sub n 1 j 1045 put fb add k 1 get fb k 1046 end 1047 end 1048 1049 note fbfind: where t first starts in fb [s, e), or e 1050 fn fbfind s ulong e ulong t view uchar * to ulong 1051 n = len t 1052 if lt sub e s n 1053 ret e 1054 end 1055 for i ulong add sub sub e s n 1 1056 if fbat add s i t 1057 ret add s i 1058 end 1059 end 1060 ret e 1061 end 1062 1063 note fbat: does fb hold the text t at o 1064 fn fbat o ulong t view uchar * to bool 1065 for j ulong len t 1066 if ne get fb add o j get t j 1067 ret false 1068 end 1069 end 1070 ret true 1071 end 1072 1073 note stale: in fb[0, n), README.md, move the first digit of the first head of the project table on 1074 note (any digit to 0, 0 to 1); false when the table is not found 1075 fn stale n ulong to bool 1076 a = fbfind 0 n tibeg 1077 if eq a n 1078 ret false 1079 end 1080 b = fbfind a n tgitc 1081 if eq b n 1082 ret false 1083 end 1084 c = fbfind add b len tgitc n tixc 1085 if eq c n 1086 ret false 1087 end 1088 h = add c len tixc 1089 y = uchar 48 1090 if eq get fb h 48 1091 y = uchar 49 1092 end 1093 put fb h y 1094 ret true 1095 end 1096 1097 note stalecase: case 35 (v 50), a README.md left with a stale generated head must regenerate to the 1098 note committed README.md and repos.tsv 1099 fn stalecase to void 1100 r = runsi 50 1101 if eq r 514 1102 bad tstl 1103 say fstale 1104 say tnl 1105 ret 1106 end 1107 if ne r 0 1108 bad tstl 1109 say frc 1110 sayn r 1111 say tsep 1112 showerr 50 1113 ret 1114 end 1115 if not and same 50 xreadme trd same 50 xrepos trepos 1116 bad tstl 1117 say fdiff 1118 say tnl 1119 ret 1120 end 1121 ok tstl 1122 say fstok 1123 end 1124 1125 note shafile: sha256 of the file named by pb into hx; false when it cannot be read 1126 fn shafile to bool 1127 n = rdf 1128 if ge n `4194304` 1129 ret false 1130 end 1131 sha n 1132 hexdg 1133 ret true 1134 end 1135 1136 note differs: the committed inventory's sha256 into hy, case v's into hx; do they differ 1137 fn differs v ulong to bool 1138 pclr 1139 padd tinv 1140 if not shafile 1141 ret false 1142 end 1143 for i ulong 64 1144 put hy i get hx i 1145 end 1146 pinv v 1147 if not shafile 1148 ret false 1149 end 1150 for i ulong 64 1151 if ne get hx i get hy i 1152 ret true 1153 end 1154 end 1155 ret false 1156 end 1157 1158 note refused: case v must differ from the committed inventory and be refused with message m 1159 fn refused v ulong t view uchar * m view uchar * to void 1160 if not differs v 1161 bad t 1162 say fsame 1163 say tnl 1164 ret 1165 end 1166 refrun v t m 1167 end 1168 1169 note refusedst: case 34 (v 49), its Radicle state must differ from the committed one and be refused 1170 note with message m 1171 fn refusedst v ulong t view uchar * m view uchar * to void 1172 if not sdiffers 1173 bad t 1174 say fsame 1175 say tnl 1176 ret 1177 end 1178 refrun v t m 1179 end 1180 1181 note sdiffers: the committed state's sha256 into hy, WORK/priv.tsv's into hx; do they differ 1182 fn sdiffers to bool 1183 pclr 1184 padd tsta 1185 if not shafile 1186 ret false 1187 end 1188 for i ulong 64 1189 put hy i get hx i 1190 end 1191 pwd 1192 padd tpriv 1193 if not shafile 1194 ret false 1195 end 1196 for i ulong 64 1197 if ne get hx i get hy i 1198 ret true 1199 end 1200 end 1201 ret false 1202 end 1203 1204 note refrun: run si on case v; it must exit 1 with message m, the README copy unchanged and no 1205 note repos.tsv written 1206 fn refrun v ulong t view uchar * m view uchar * to void 1207 r = runsi v 1208 if ne r 1 1209 bad t 1210 say frc 1211 sayn r 1212 say tsep 1213 showerr v 1214 ret 1215 end 1216 if not errhas v m 1217 bad t 1218 say fmsg 1219 say tsep 1220 showerr v 1221 ret 1222 end 1223 if not same v xreadme trd 1224 bad t 1225 say frd 1226 say tnl 1227 ret 1228 end 1229 if not absent v 1230 bad t 1231 say frepo 1232 say tnl 1233 ret 1234 end 1235 ok t 1236 say tsep 1237 say tsha 1238 w = write 1 hy 0 64 1239 say tarrow 1240 w = write 1 hx 0 64 1241 say tref 1242 showerr v 1243 end 1244 1245 note lmut: write case v's links tree WORK/-tree/repos.tsv from the committed repos.tsv: v 5 ends 1246 note the first link row's RID in 0 (not base58), v 6 starts it rad:z2ft64, v 7 copies it unchanged 1247 fn lmut v ulong to bool 1248 pcase v xtree 1249 r = makedir pb 0 get pbn 0 493 1250 pclr 1251 padd trepos 1252 n = rdf 1253 if ge n `4194304` 1254 ret false 1255 end 1256 p = ulong 0 1257 while lt p n bound `4194305` 1258 if eq get fb p 10 1259 break 1260 end 1261 p = add p 1 1262 end 1263 while lt p n bound `4194305` 1264 if eq get fb p 9 1265 break 1266 end 1267 p = add p 1 1268 end 1269 p = add p 1 1270 e = p 1271 while lt e n bound `4194305` 1272 if eq get fb e 9 1273 break 1274 end 1275 e = add e 1 1276 end 1277 if or ge e n lt sub e p 10 1278 ret false 1279 end 1280 if eq v 5 1281 put fb sub e 1 48 1282 end 1283 if eq v 6 1284 for i ulong 5 1285 put fb add add p 5 i get tz2ft i 1286 end 1287 end 1288 pcase v xtrepo 1289 ret wrf n 1290 end 1291 1292 note ldiff: the committed repos.tsv's sha256 into hy, case v's tree copy's into hx; do they differ 1293 fn ldiff v ulong to bool 1294 pclr 1295 padd trepos 1296 if not shafile 1297 ret false 1298 end 1299 for i ulong 64 1300 put hy i get hx i 1301 end 1302 pcase v xtrepo 1303 if not shafile 1304 ret false 1305 end 1306 for i ulong 64 1307 if ne get hx i get hy i 1308 ret true 1309 end 1310 end 1311 ret false 1312 end 1313 1314 note runlk: run WORK/links on the repository root (v 4) or on WORK/-tree, stdout to 1315 note WORK/-out, stderr to WORK/-err; its exit status 1316 fn runlk v ulong to ulong 1317 astart 1318 pwd 1319 padd tlinks 1320 aadd 1321 pclr 1322 if eq v 4 1323 padd tdot 1324 else 1325 pcase v xtree 1326 end 1327 aadd 1328 pclr 1329 padd tsta 1330 i = opr 1331 pcase v xout 1332 o = opw 1333 pcase v xerr 1334 e = opw 1335 if or lt i 0 or lt o 0 lt e 0 1336 ret 513 1337 end 1338 ret spawn i o e 1339 end 1340 1341 note lhas: does case v's file WORK/ start with "links: " and the text m 1342 fn lhas v ulong x view uchar * m view uchar * to bool 1343 pcase v x 1344 n = rdf 1345 a = len mlk 1346 if or ge n `4194304` lt n add a len m 1347 ret false 1348 end 1349 for i ulong a 1350 if ne get fb i get mlk i 1351 ret false 1352 end 1353 end 1354 for i ulong len m 1355 if ne get fb add a i get m i 1356 ret false 1357 end 1358 end 1359 ret true 1360 end 1361 1362 note lcur: case 5, links passes on the repository root 1363 fn lcur to void 1364 r = runlk 4 1365 if and eq r 0 lhas 4 xout mlpass 1366 ok tlcur 1367 say tsep 1368 showx 4 xout 1369 ret 1370 end 1371 bad tlcur 1372 say frc 1373 sayn r 1374 say tsep 1375 showx 4 xerr 1376 end 1377 1378 note lref: links case v (5 RID, 6 crypto, 7 vendored) must be refused with message m. The v 5 and 6 1379 note trees must differ from the committed repos.tsv; the v 7 tree must hold the planted file. 1380 fn lref v ulong t view uchar * m view uchar * to void 1381 if not lmut v 1382 bad t 1383 say fio 1384 say tnl 1385 ret 1386 end 1387 if eq v 7 1388 pcase v xvdir 1389 r = makedir pb 0 get pbn 0 493 1390 put fb 0 10 1391 pcase v xvfile 1392 if not wrf 1 1393 bad t 1394 say fio 1395 say tnl 1396 ret 1397 end 1398 pcase v xvfile 1399 n = rdf 1400 if ne n 1 1401 bad t 1402 say fplant 1403 say tnl 1404 ret 1405 end 1406 else 1407 if not ldiff v 1408 bad t 1409 say fsame 1410 say tnl 1411 ret 1412 end 1413 end 1414 lcheck v t m ne v 7 1415 end 1416 1417 note lcheck: links on WORK/-tree must exit 1 with stderr "links: " m; sh: show the sha256 change 1418 note of repos.tsv (hy to hx, from ldiff) 1419 fn lcheck v ulong t view uchar * m view uchar * sh bool to void 1420 r = runlk v 1421 if ne r 1 1422 bad t 1423 say frc 1424 sayn r 1425 say tsep 1426 showx v xerr 1427 ret 1428 end 1429 if not lhas v xerr m 1430 bad t 1431 say fmsg 1432 say tsep 1433 showx v xerr 1434 ret 1435 end 1436 ok t 1437 say tsep 1438 if sh 1439 say tsha 1440 w = write 1 hy 0 64 1441 say tarrow 1442 w = write 1 hx 0 64 1443 end 1444 say tref 1445 showx v xerr 1446 end 1447 1448 note badw: case t fails with the reason w 1449 fn badw t view uchar * w view uchar * to void 1450 bad t 1451 say w 1452 say tnl 1453 end 1454 1455 note cfile: pb becomes WORK/-tree/compiler/ and the k-th file (k 0..7) links allows there 1456 fn cfile v ulong k ulong to void 1457 pcase v xtree 1458 padd tcmpd 1459 if eq k 0 1460 padd tf1 1461 end 1462 if eq k 1 1463 padd tf2 1464 end 1465 if eq k 2 1466 padd tf3 1467 end 1468 if eq k 3 1469 padd tf4 1470 end 1471 if eq k 4 1472 padd tf5 1473 end 1474 if eq k 5 1475 padd tf6 1476 end 1477 if eq k 6 1478 padd tf7 1479 end 1480 if eq k 7 1481 padd tf8 1482 end 1483 end 1484 1485 note lbase: WORK/-tree becomes the smallest tree links accepts: the committed repos.tsv and a 1486 note compiler/ holding its eight allowed file names, empty (links checks names and kinds only). 1487 note Each file is unlinked first, so a symbolic link left by an earlier run is never written through. 1488 fn lbase v ulong to bool 1489 pcase v xtree 1490 r1 = makedir pb 0 get pbn 0 493 1491 padd tcmpd 1492 r2 = makedir pb 0 get pbn 0 493 1493 for k ulong 8 1494 cfile v k 1495 r3 = unlink pb 0 get pbn 0 1496 if not wrf 0 1497 ret false 1498 end 1499 end 1500 pclr 1501 padd trepos 1502 n = rdf 1503 if ge n `4194304` 1504 ret false 1505 end 1506 pcase v xtrepo 1507 ret wrf n 1508 end 1509 1510 note lfind: start and end of field f (from 0) of line ln (from 1) of fb[0, n) into lf; false when 1511 note the line or field is missing 1512 fn lfind n ulong ln ulong f ulong to bool 1513 p = ulong 0 1514 k = ulong 1 1515 while and lt k ln lt p n bound `4194305` 1516 if eq get fb p 10 1517 k = add k 1 1518 end 1519 p = add p 1 1520 end 1521 if ne k ln 1522 ret false 1523 end 1524 j = ulong 0 1525 while and lt j f lt p n bound `4194305` 1526 c = get fb p 1527 if eq c 10 1528 ret false 1529 end 1530 if eq c 9 1531 j = add j 1 1532 end 1533 p = add p 1 1534 end 1535 if ne j f 1536 ret false 1537 end 1538 e = p 1539 while lt e n bound `4194305` 1540 d = get fb e 1541 if or eq d 9 eq d 10 1542 break 1543 end 1544 e = add e 1 1545 end 1546 put lf 0 p 1547 put lf 1 e 1548 ret true 1549 end 1550 1551 note lsplit: fb[0, n) becomes fb[0, q), t, fb[e, n) (q <= e; gb holds the tail); its new length 1552 fn lsplit q ulong e ulong n ulong t view uchar * to ulong 1553 tl = sub n e 1554 for i ulong tl 1555 put gb i get fb add e i 1556 end 1557 for i ulong len t 1558 put fb add q i get t i 1559 end 1560 b = add q len t 1561 for i ulong tl 1562 put fb add b i get gb i 1563 end 1564 ret add b tl 1565 end 1566 1567 note lsplice: WORK/-tree/repos.tsv becomes the committed repos.tsv with field f of the first link 1568 note row (line 2) replaced by t (kind 0) or t appended to it (kind 1); or of the header (line 1) 1569 note replaced by t (kind 3); or cut after the header (kind 2, f 4: its last field) 1570 fn lsplice v ulong f ulong kind ulong t view uchar * to bool 1571 pclr 1572 padd trepos 1573 n = rdf 1574 if ge n `4194304` 1575 ret false 1576 end 1577 ln = ulong 2 1578 if ge kind 2 1579 ln = 1 1580 end 1581 if not lfind n ln f 1582 ret false 1583 end 1584 e = get lf 1 1585 if eq kind 2 1586 pcase v xtrepo 1587 ret wrf add e 1 1588 end 1589 q = e 1590 if ne kind 1 1591 q = get lf 0 1592 end 1593 m = lsplit q get lf 1 n t 1594 pcase v xtrepo 1595 ret wrf m 1596 end 1597 1598 note lprep: case v's minimal tree with its repos.tsv spliced (lsplice f kind r); 0 when it is 1599 note ready, 1 when a gate file could not be read or written, 2 when it equals the committed one 1600 fn lprep v ulong f ulong kind ulong r view uchar * to ulong 1601 if not lbase v 1602 ret 1 1603 end 1604 if not lsplice v f kind r 1605 ret 1 1606 end 1607 if not ldiff v 1608 ret 2 1609 end 1610 ret 0 1611 end 1612 1613 note lrow: links case v, prepared by lprep with result why, must be refused with message m. A 1614 note function takes at most six argument slots and a view takes two, hence the split. 1615 fn lrow v ulong t view uchar * m view uchar * why ulong to void 1616 if eq why 1 1617 badw t fio 1618 ret 1619 end 1620 if eq why 2 1621 badw t fsame 1622 ret 1623 end 1624 lcheck v t m true 1625 end 1626 1627 note lpath: append the entry plant k puts in a tree: 1 compiler/evil.om, 2 compiler/si.om, 1628 note 3 lnk, 4 evil.rs, 5 vendor, 6 gpu/x.bin, 7 README.zh-CN.md, 8 compiler/README.zh-CN.md, 1629 note 9 README.zh-TW.md, 10 README.fr.md, 11 readme.zh-cn.md, 12 and 13 README.zh-CN.md 1630 fn lpath k ulong to void 1631 if eq k 1 1632 padd tp1 1633 end 1634 if eq k 2 1635 padd tp2 1636 end 1637 if eq k 3 1638 padd tp3 1639 end 1640 if eq k 4 1641 padd tp4 1642 end 1643 if eq k 5 1644 padd tp5 1645 end 1646 if eq k 6 1647 padd tp6 1648 end 1649 if or or eq k 7 eq k 12 eq k 13 1650 padd tp7 1651 end 1652 if eq k 8 1653 padd tp8 1654 end 1655 if eq k 9 1656 padd tp9 1657 end 1658 if eq k 10 1659 padd tp10 1660 end 1661 if eq k 11 1662 padd tp11 1663 end 1664 end 1665 1666 note lsym: the plant k (2, 3 or 12) of WORK/-tree as a symbolic link: compiler/si.om to gate.om, 1667 note lnk to compiler, README.zh-CN.md to repos.tsv (a regular file, so a check that followed the 1668 note link would admit it). symlnk takes the packed list target, link path, as aadd builds it. 1669 fn lsym v ulong k ulong to void 1670 astart 1671 pclr 1672 if eq k 2 1673 padd ts2 1674 end 1675 if eq k 3 1676 padd ts3 1677 end 1678 if eq k 12 1679 padd trepos 1680 end 1681 aadd 1682 pcase v xtree 1683 lpath k 1684 aadd 1685 put av 0 2 1686 put av 1 0 1687 r = symlnk av 0 get avp 0 1688 end 1689 1690 note lput: plant k in WORK/-tree: an empty file (1, 4, 6, 7 to 11), a symbolic link (2, 3, 12, 1691 note replacing compiler/si.om for 2) or a directory (5, 13) 1692 fn lput v ulong k ulong to void 1693 if eq k 6 1694 pcase v xtree 1695 padd tgpud 1696 r1 = makedir pb 0 get pbn 0 493 1697 end 1698 pcase v xtree 1699 lpath k 1700 if eq k 2 1701 r2 = unlink pb 0 get pbn 0 1702 end 1703 if or or eq k 2 eq k 3 eq k 12 1704 lsym v k 1705 ret 1706 end 1707 if or eq k 5 eq k 13 1708 r3 = makedir pb 0 get pbn 0 493 1709 ret 1710 end 1711 w = wrf 0 1712 end 1713 1714 note lplant: links case v, a minimal tree with plant k (lput) that must exist (lstat), is refused as 1715 note "not an SI file" 1716 fn lplant v ulong t view uchar * k ulong to void 1717 if not lbase v 1718 badw t fio 1719 ret 1720 end 1721 lput v k 1722 pcase v xtree 1723 lpath k 1724 r = lstat pb 0 get pbn 0 sb 0 256 1725 if ne r 0 1726 badw t fplant 1727 ret 1728 end 1729 lcheck v t mlven false 1730 end 1731 1732 note ladmit: links case v, a minimal tree with plant k (lput) that must exist (lstat), passes 1733 fn ladmit v ulong t view uchar * k ulong to void 1734 if not lbase v 1735 badw t fio 1736 ret 1737 end 1738 lput v k 1739 pcase v xtree 1740 lpath k 1741 r = lstat pb 0 get pbn 0 sb 0 256 1742 if ne r 0 1743 badw t fplant 1744 ret 1745 end 1746 rc = runlk v 1747 if and eq rc 0 lhas v xout mlpass 1748 ok t 1749 say tsep 1750 showx v xout 1751 ret 1752 end 1753 bad t 1754 say frc 1755 sayn rc 1756 say tsep 1757 showx v xerr 1758 end 1759 1760 note lgood: links case v, the minimal tree of lbase, passes; every other tree case is one change of it 1761 fn lgood v ulong to void 1762 if not lbase v 1763 badw cgood fio 1764 ret 1765 end 1766 r = runlk v 1767 if and eq r 0 lhas v xout mlpass 1768 ok cgood 1769 say tsep 1770 showx v xout 1771 ret 1772 end 1773 bad cgood 1774 say frc 1775 sayn r 1776 say tsep 1777 showx v xerr 1778 end 1779 1780 text rbom "compiler/rebuild.om" 1781 text rbin "rebuild" 1782 text rbcomp "build rebuild from compiler/rebuild.om" 1783 text rbd "/rb" 1784 text rbp "/rb/p" 1785 text rbpin "/rb/p/pinned" 1786 text rbrepos "/rb/repos.tsv" 1787 text rbtable "/rb/layers.tsv" 1788 text rbgout "/rb/git.out" 1789 text rbgerr "/rb/git.err" 1790 text rbabc "abc" 1791 text rbrp0 "name\trid\thead\ttier\tdescription\np\tx\t" 1792 text rbrp1 "\tcore\tfixture\n" 1793 text rbhdr "layers\t2\nlayer\trepo\tneeds\tcommand\tartifact\tcompare\n" 1794 text rbrow1 "1\tp\tany\tcp pinned built\tbuilt\tpinned\n" 1795 text rbrow2 "2\tp\tany\tcp pinned built\tbuilt\tpinned\n" 1796 text rbwrong "2\tp\tany\tprintf wrong > built\tbuilt\tpinned\n" 1797 text rbexit "2\tp\tany\texit 7\t-\t-\n" 1798 text rbchip "2\tp\tpci:ffff:ffff\tcp pinned built\tbuilt\tpinned\n" 1799 text rbnone "2\tp\tany\t-\t-\t-\n" 1800 text rbmac "2\tabsent\tmacos\tcp pinned built\tbuilt\tpinned\n" 1801 text rbpass "REBUILD pass=2 fail=0 not_run=0" 1802 text rbdiff "FAIL artifact differs from committed" 1803 text rbnz "FAIL command exited nonzero" 1804 text rbseven " | rc 7 |" 1805 text rbnot "NOT_RUN hardware row; no PCI device" 1806 text rbmiss "layer 2 has no row" 1807 text rbno "NOT_RUN no documented rebuild command" 1808 text rbmacm "NOT_RUN macOS only" 1809 text rbc0 "rebuild-positive" 1810 text rbc1 "rebuild-byte-mutant" 1811 text rbc2 "rebuild-exit-mutant" 1812 text rbc3 "rebuild-offchip-mutant" 1813 text rbc4 "rebuild-missing-layer-mutant" 1814 text rbc5 "rebuild-no-command" 1815 text rbc6 "rebuild-macos-only" 1816 text rbgit "/usr/bin/git" 1817 text rbinit "init" 1818 text rbquiet "-q" 1819 text rbcd "-C" 1820 text rbadd "add" 1821 text rbf "pinned" 1822 text rbc "-c" 1823 text rbuser "user.name=Fixture" 1824 text rbmail "user.email=fixture@example.invalid" 1825 text rbcommit "commit" 1826 text rbqm "-qm" 1827 text rbmsg "fixture" 1828 text rbrev "rev-parse" 1829 text rbhead "HEAD" 1830 text rbrun "run" 1831 text rbhw "hw=yes" 1832 text rbnull "/dev/null" 1833 1834 fn rbput t view uchar * n ulong to ulong 1835 for i ulong len t 1836 put fb add n i get t i 1837 end 1838 ret add n len t 1839 end 1840 fn rbpath t view uchar * to void 1841 pwd 1842 put pbn 0 sub get pbn 0 1 1843 padd t 1844 end 1845 fn rbarg t view uchar * to void 1846 pclr 1847 padd t 1848 aadd 1849 end 1850 fn rbg v ulong to ulong 1851 astart 1852 rbarg rbgit 1853 if eq v 0 1854 rbarg rbinit 1855 rbarg rbquiet 1856 rbpath rbp 1857 aadd 1858 else 1859 rbarg rbcd 1860 rbpath rbp 1861 aadd 1862 if eq v 1 1863 rbarg rbadd 1864 rbarg rbf 1865 end 1866 if eq v 2 1867 rbarg rbc 1868 rbarg rbuser 1869 rbarg rbc 1870 rbarg rbmail 1871 rbarg rbcommit 1872 rbarg rbqm 1873 rbarg rbmsg 1874 end 1875 if eq v 3 1876 rbarg rbrev 1877 rbarg rbhead 1878 end 1879 end 1880 pclr 1881 padd rbnull 1882 i = opr 1883 rbpath rbgout 1884 o = opw 1885 rbpath rbgerr 1886 e = opw 1887 ret spawn i o e 1888 end 1889 fn rbprep to void 1890 rbpath rbd 1891 c = makedir pb 0 get pbn 0 493 1892 rbpath rbp 1893 c = makedir pb 0 get pbn 0 493 1894 rbpath rbpin 1895 n = rbput rbabc 0 1896 if not wrf n 1897 fatal fio 0 1898 end 1899 for i ulong 4 1900 rc = rbg i 1901 if ne rc 0 1902 fatal rbcomp rc 1903 end 1904 end 1905 rbpath rbgout 1906 n = rdf 1907 if lt n 40 1908 fatal fio 0 1909 end 1910 for i ulong 40 1911 put gb i get fb i 1912 end 1913 n = rbput rbrp0 0 1914 for i ulong 40 1915 put fb add n i get gb i 1916 end 1917 n = rbput rbrp1 add n 40 1918 rbpath rbrepos 1919 if not wrf n 1920 fatal fio 0 1921 end 1922 end 1923 fn rbcall v ulong to ulong 1924 astart 1925 pwd 1926 padd rbin 1927 aadd 1928 rbarg rbrun 1929 rbpath rbtable 1930 aadd 1931 rbpath rbrepos 1932 aadd 1933 rbpath rbd 1934 aadd 1935 rbpath rbd 1936 aadd 1937 rbarg rbhw 1938 pclr 1939 padd rbnull 1940 i = opr 1941 pcase v xout 1942 o = opw 1943 pcase v xerr 1944 e = opw 1945 ret spawn i o e 1946 end 1947 fn rbat o ulong m view uchar * to bool 1948 for j ulong len m 1949 if ne get fb add o j get m j 1950 ret false 1951 end 1952 end 1953 ret true 1954 end 1955 fn rbhas v ulong x view uchar * m view uchar * to bool 1956 pcase v x 1957 n = rdf 1958 if ge n `4194304` 1959 ret false 1960 end 1961 if lt n len m 1962 ret false 1963 end 1964 for i ulong add sub n len m 1 1965 if rbat i m 1966 ret true 1967 end 1968 end 1969 ret false 1970 end 1971 fn rbmatch v ulong to bool 1972 if eq v 61 1973 ret rbhas v xout rbpass 1974 end 1975 if eq v 62 1976 ret rbhas v xout rbdiff 1977 end 1978 if eq v 63 1979 ret and rbhas v xout rbnz rbhas v xout rbseven 1980 end 1981 if eq v 64 1982 ret rbhas v xout rbnot 1983 end 1984 if eq v 65 1985 ret or rbhas v xout rbmiss rbhas v xerr rbmiss 1986 end 1987 if eq v 66 1988 ret rbhas v xout rbno 1989 end 1990 ret rbhas v xout rbmacm 1991 end 1992 fn rbcase v ulong t view uchar * row2 view uchar * to void 1993 n = rbput rbhdr 0 1994 n = rbput rbrow1 n 1995 if ne v 65 1996 n = rbput row2 n 1997 end 1998 rbpath rbtable 1999 if not wrf n 2000 fatal fio 0 2001 end 2002 rc = rbcall v 2003 match = rbmatch v 2004 want = ulong 1 2005 if eq v 61 2006 want = 0 2007 end 2008 if and eq rc want match 2009 ok t 2010 else 2011 bad t 2012 say frc 2013 sayn rc 2014 say fio 2015 end 2016 say tnl 2017 end 2018 fn rbcases to void 2019 build rbom rbin rbcomp 2020 rbprep 2021 rbcase 61 rbc0 rbrow2 2022 rbcase 62 rbc1 rbwrong 2023 rbcase 63 rbc2 rbexit 2024 rbcase 64 rbc3 rbchip 2025 rbcase 65 rbc4 rbrow2 2026 rbcase 66 rbc5 rbnone 2027 rbcase 67 rbc6 rbmac 2028 end 2029 2030 fn main to int 2031 if ne argcnt 3 2032 say tusage 2033 ret 2 2034 end 2035 n = argread 1 om 0 2048 2036 if le n 0 2037 say tusage 2038 ret 2 2039 end 2040 put omn 0 ulong n 2041 n = argread 2 wd 0 2048 2042 if le n 0 2043 say tusage 2044 ret 2 2045 end 2046 put wdn 0 ulong n 2047 pin 2048 build tsiom tsi tcomp 2049 build tlom tlinks tlcomp 2050 current 2051 if mutate 1 2052 refused 1 thm mhead 2053 else 2054 bad thm 2055 say fio 2056 say tnl 2057 end 2058 if mutate 2 2059 refused 2 trm mrid 2060 else 2061 bad trm 2062 say fio 2063 say tnl 2064 end 2065 refused 3 tom mhead 2066 if mstate 2067 refusedst 49 tpv mpriv 2068 else 2069 bad tpv 2070 say fio 2071 say tnl 2072 end 2073 stalecase 2074 lcur 2075 lref 5 tlrid mlrid 2076 lref 6 tlcry mlcry 2077 lref 7 tlven mlven 2078 lgood 17 2079 lrow 18 cpearl mlcry lprep 18 0 0 rpearl 2080 lrow 19 ccrypto mlcry lprep 19 0 0 rcrypt 2081 lrow 20 cname mlname lprep 20 0 0 rbadn 2082 lrow 21 chupper mlhead lprep 21 2 0 rhup 2083 lrow 22 chg mlhead lprep 22 2 0 rhg 2084 lrow 23 ch41 mlhead lprep 23 2 1 rzero 2085 lrow 24 ctier mltier lprep 24 3 0 rtier 2086 lrow 25 crlong mlrid lprep 25 1 1 rz 2087 lrow 26 crbig mlrid lprep 26 1 0 rbig 2088 lrow 27 chdr mlhdr lprep 27 0 3 rnam 2089 lrow 28 chonly mlnone lprep 28 4 2 rz 2090 lplant 29 ccfile 1 2091 lplant 30 cclink 2 2092 lplant 31 crlink 3 2093 lplant 32 crfile 4 2094 lplant 33 crdir 5 2095 lplant 34 cgfile 6 2096 ladmit 35 czh 7 2097 lplant 36 czsub 8 2098 lplant 37 cztw 9 2099 lplant 38 czfr 10 2100 lplant 39 czlc 11 2101 lplant 40 czlink 12 2102 lplant 41 czdir 13 2103 rbcases 2104 say tsum 2105 sayn get tally 0 2106 say tsumf 2107 sayn get tally 1 2108 say tnl 2109 if ne get tally 1 0 2110 ret 1 2111 end 2112 ret 0 2113 end