interplane.Get Omega
Read in your language

sovereign-intelligence

Front door to Drake Stapleton's sovereign stack.

Brought by drakestapleton

branch main Branches Tags History

sovereign-intelligence / compiler / gate.om

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