sovereign-intelligence
Front door to Drake Stapleton's sovereign stack.
Brought by drakestapleton
sovereign-intelligence / compiler / si.om
| 1 | om2 |
| 2 | note compiler/si.om: the sovereign-intelligence front-door generator, in pure seeded Omega. |
| 3 | note |
| 4 | note Build with the pinned seeded compiler (compiler/README.md names the pin): |
| 5 | note omc < compiler/si.om > si && chmod +x si |
| 6 | note Run: |
| 7 | note si INVENTORY ORDER STATE README REPOS SISH |
| 8 | note INVENTORY read, typed by a person: one project per line, name TAB rid TAB description: |
| 9 | note which projects the front door lists and how each is described. A line with |
| 10 | note more than three fields (a typed head, branch or visibility) is refused |
| 11 | note ORDER read, typed: "core TAB name" lines give the core projects in order, |
| 12 | note "deny TAB name" lines name projects that are never listed, |
| 13 | note one optional "lead TAB name" line names the project the README leads with |
| 14 | note STATE read, generated from Radicle by tools/si-state.sh, never typed: one T line, |
| 15 | note the time it was read, then per RID "D rid branch" (the default branch its |
| 16 | note signed identity names), "V rid visibility", "H rid branch head" (the |
| 17 | note canonical refs/heads/branch) and "P rid head file" (a landing receipt whose |
| 18 | note first line names that head) |
| 19 | note README read and rewritten in place between the si:lead markers, the si:agent |
| 20 | note markers and the si:index markers |
| 21 | note REPOS written: the public manifest, one project per line, as TSV |
| 22 | note SISH written: the POSIX sh bootstrap served at https://www.aienos.com/si |
| 23 | note Every inventory project that ORDER does not deny is listed, with the branch, head and |
| 24 | note receipt count STATE gives for its RID. A receipt counts only when its file is named |
| 25 | note NAME-HEAD12.txt (the project's name and the first 12 digits of that head), the landing |
| 26 | note receipts' convention. Core projects come first, in ORDER's order; the rest follow in |
| 27 | note inventory order. A listed project that STATE does not show as public with one default |
| 28 | note branch and one head of it, a missing or denied core project, a duplicate name or RID, a |
| 29 | note typed head, branch or visibility, or a malformed field or STATE line makes si refuse |
| 30 | note with exit 1 and write nothing; the refusal names the row. The output depends only on |
| 31 | note the input bytes: no clock (the time is STATE's T line), no environment. |
| 32 | |
| 33 | note input bytes (all four inputs, one after another) and output bytes |
| 34 | global src uchar 4194304 |
| 35 | global srcn ulong 1 |
| 36 | global ob uchar 4194304 |
| 37 | global obn ulong 1 |
| 38 | note the path named by the current argument |
| 39 | global pb uchar 4096 |
| 40 | global pbn ulong 1 |
| 41 | note project records, 16 cells each: offset and length of name, rid, visibility, head, |
| 42 | note description (cells 0..9), kind (cell 10: 0 rest, 1 core, 2 never listed), core rank (11), |
| 43 | note offset and length of the default branch (12, 13) and the head's receipts (14); 15 is unused. |
| 44 | note Visibility, head, branch and receipts come from STATE, never from the inventory |
| 45 | global rec ulong 16384 |
| 46 | global nrec ulong 1 |
| 47 | note core and deny names from ORDER: offset, length pairs |
| 48 | global cor ulong 128 |
| 49 | global ncor ulong 1 |
| 50 | global den ulong 128 |
| 51 | global nden ulong 1 |
| 52 | note the lead project's name from ORDER: offset, length; nled is 0 or 1 |
| 53 | global led ulong 2 |
| 54 | global nled ulong 1 |
| 55 | note STATE lines, 8 cells each: the kind byte, offset and length of up to three fields, and |
| 56 | note the field count (cell 7) |
| 57 | global stl ulong 65536 |
| 58 | global nstl ulong 1 |
| 59 | note the T line's time, offset and length; ntim counts T lines |
| 60 | global tim ulong 2 |
| 61 | global ntim ulong 1 |
| 62 | note how many lines the last stfind matched (nhit) |
| 63 | global nhit ulong 1 |
| 64 | note emission order: record numbers |
| 65 | global seq ulong 1024 |
| 66 | global nseq ulong 1 |
| 67 | |
| 68 | text tsi "si: " |
| 69 | text tnl "\n" |
| 70 | text tusage "usage: si INVENTORY ORDER STATE README REPOS SISH\n" |
| 71 | text toverf "output is over the 4 MiB buffer" |
| 72 | text targ "cannot read a command-line argument" |
| 73 | text topen "cannot open " |
| 74 | text tread "cannot read " |
| 75 | text tbig "input over the 4 MiB buffer: " |
| 76 | text twrite "cannot write " |
| 77 | text tmany "more than 1024 projects at: " |
| 78 | text tcols "inventory line needs 3 tab-separated fields (name, rid, description): " |
| 79 | text tbname "bad project name (letters, digits, . _ - only): " |
| 80 | text tbrid "bad RID (rad:z then letters and digits): " |
| 81 | text tbdesc "description has control bytes or is over 512 bytes: " |
| 82 | text tbord "order line must be core, deny or lead TAB name: " |
| 83 | text tmore "more than 64 core or deny names, or a second lead, at: " |
| 84 | text tdupn "duplicate project name: " |
| 85 | text tdupr "duplicate RID: " |
| 86 | text tcmiss "core project is not in the inventory: " |
| 87 | text ttyped "inventory carries a typed head, branch or visibility; those come from Radicle (tools/si-state.sh): " |
| 88 | text tcpriv "core project is denied or listed twice: " |
| 89 | text tmst "more than 8192 Radicle state lines at: " |
| 90 | text tbst "Radicle state line is not T, D, V, H or P with its well-formed fields: " |
| 91 | text tnot "Radicle state needs exactly one T line, the time it was read" |
| 92 | text tnod "no default branch from a Radicle identity for: " |
| 93 | text tnov "no Radicle visibility for: " |
| 94 | text tdupd "two Radicle default branches or visibilities for: " |
| 95 | text tpriv "listed project is not public on Radicle: " |
| 96 | text tnoh "no canonical head on Radicle of the default branch of: " |
| 97 | text tduph "two Radicle heads of the default branch of: " |
| 98 | text ttxt ".txt" |
| 99 | text tnomark "README lacks <!-- si:lead:begin -->, <!-- si:lead:end -->, <!-- si:agent:begin -->, <!-- si:agent:end -->, <!-- si:index:begin --> and <!-- si:index:end -->, in that order" |
| 100 | text tdot "." |
| 101 | text tdotdot ".." |
| 102 | text tradz "rad:z" |
| 103 | text tpublic "public" |
| 104 | text tprivat "private" |
| 105 | text ttab "\t" |
| 106 | text tcore "core" |
| 107 | text tdeny "deny" |
| 108 | text tlead "lead" |
| 109 | text tbar " | " |
| 110 | text tbare " |" |
| 111 | text trest "rest" |
| 112 | text tbeg "<!-- si:index:begin -->" |
| 113 | text tend "<!-- si:index:end -->" |
| 114 | text tlbeg "<!-- si:lead:begin -->" |
| 115 | text tlend "<!-- si:lead:end -->" |
| 116 | text ld0 "`" |
| 117 | text ld1 "` is being published to Radicle. Its Radicle ID appears here as soon as it is.\n" |
| 118 | text ld2 "```sh\nrad clone --timeout 5min " |
| 119 | text ld3 " # " |
| 120 | text ld4 "\n```\n\nOn the web: [radicle.network/nodes/rosa.radicle.network/" |
| 121 | text ld5 "](https://radicle.network/nodes/rosa.radicle.network/" |
| 122 | text ld6 ")\n" |
| 123 | text tabeg "<!-- si:agent:begin -->" |
| 124 | text taend "<!-- si:agent:end -->" |
| 125 | text ag1 "<https://radicle.network/nodes/rosa.radicle.network/" |
| 126 | text ag2 "/tree/AGENT-PROMPT.md>\n" |
| 127 | text ag3 "`'s agent prompt link appears here as soon as it is on Radicle.\n" |
| 128 | text tsec "## " |
| 129 | text ix1 "**" |
| 130 | text ix2 " public projects**, " |
| 131 | text ix3 " of them core. `compiler/si.om` lists them from Radicle as of " |
| 132 | text ix3b ". For each project, *Branch* is the default branch its signed Radicle identity names and *Head* is that branch's commit on my node at that time; nobody types either. *Receipts* counts the landing receipts recorded for exactly that commit: each says the project's own checks passed on a fresh copy before it landed, and 0 means none is recorded. A head is the latest commit, not a review. Each project's home is its own Radicle repository; this table only links to them. Clone one peer-to-peer with `rad clone`, or read-only with `git clone` from its mirror on my own seed. A plain `git clone` of the mirror gets the project's Radicle default branch. Every other branch and tag, including those carried over from GitHub, is served at the mirror URL with my node ID appended. That URL has no default branch, so give `--branch` a short branch or tag name, not `refs/heads/...`:\n\n```sh\ngit clone --branch <branch-or-tag> https://www.aienos.com/rad/<RID>.git/z6MkfZDue1TbaNFi3ZzcD9uiTeduPLC52ucdFVuLKZwexxhK/ <dir>\n```\n\nFull commit ids are in [`repos.tsv`](repos.tsv).\n\n| # | Project | Radicle ID | Get it | Branch | Head | Receipts | About |\n|---:|---|---|---|---|---|---:|---|\n" |
| 133 | text ix4 "| " |
| 134 | text ix5 " | **" |
| 135 | text ix6 "**" |
| 136 | text ix7 " (core)" |
| 137 | text ix8 " | `" |
| 138 | text ix9 "` | `rad clone --timeout 5min " |
| 139 | text ixa "`, [git mirror](https://www.aienos.com/rad/" |
| 140 | text ixb ".git) | `" |
| 141 | text ixc "` | `" |
| 142 | text ixd " | " |
| 143 | text ix10 "` | " |
| 144 | text ix11 " |\n" |
| 145 | text rphdr "name\trid\thead\ttier\tdescription\n" |
| 146 | text shr1 "si_repo '" |
| 147 | text shr2 "' '" |
| 148 | text shr3 "'\n" |
| 149 | |
| 150 | note the bootstrap script, paragraph by paragraph; shd3 ends where the project lines go |
| 151 | text sha0 "#!/bin/sh\n# sovereign-intelligence bootstrap: fetch every public project of my sovereign AI stack.\n# Generated by compiler/si.om (Omega) from Radicle state read at " |
| 152 | text sha0b ": each project's\n# commit is the head of the default branch its signed Radicle identity names, at that time:\n# the latest commit, not a review. Do not edit by hand.\n# Served at https://www.aienos.com/si\n# Front door: https://interplane.io/drakestapleton/sovereign-intelligence\n#\n# curl -fsSL https://www.aienos.com/si | sh\n#\n# Settings (environment):\n# SI_DIR=path the one directory it creates (default ./sovereign-intelligence)\n# SI_ONLY=core fetch only the core projects (default all)\n# SI_HTTP=url first git-over-HTTPS seed (default https://www.aienos.com/rad, my own)\n# SI_HTTP2=url second git-over-HTTPS seed (default https://rosa.radicle.network, public)\n# SI_INSTALL_RAD=1 run the official Radicle installer when a project cannot be fetched\n# SI_RAD_TIMEOUT=t per-project rad clone timeout (default 5min)\n# No sudo. It refuses to run as root. It touches nothing outside SI_DIR,\n# except that SI_INSTALL_RAD=1 runs Radicle's own installer as you.\n# Exit status: 0 all OK, 2 a checkout does not match the manifest, 3 a project could not be fetched.\nset -eu\numask 022\n\n" |
| 153 | text sha1 "SI_DIR=\"${SI_DIR:-./sovereign-intelligence}\"\nSI_ONLY=\"${SI_ONLY:-all}\"\nSI_HTTP=\"${SI_HTTP:-https://www.aienos.com/rad}\"\nSI_HTTP2=\"${SI_HTTP2:-https://rosa.radicle.network}\"\nSI_INSTALL_RAD=\"${SI_INSTALL_RAD:-0}\"\nSI_RAD_TIMEOUT=\"${SI_RAD_TIMEOUT:-5min}\"\n\n" |
| 154 | text sha2 "si_say() { printf '%s\\n' \"$*\"; }\nsi_die() { printf 'si: %s\\n' \"$*\" >&2; exit 1; }\n\n" |
| 155 | text sha3 "if [ \"$(id -u)\" = \"0\" ]; then si_die \"refusing to run as root; run it as your own user\"; fi\ncase \"$SI_ONLY\" in all|core) ;; *) si_die \"SI_ONLY must be all or core\" ;; esac\ncommand -v git >/dev/null 2>&1 || si_die \"git is required: https://git-scm.com\"\nsi_rad=0\nif command -v rad >/dev/null 2>&1; then si_rad=1; fi\n\n" |
| 156 | text sha4 "si_say \"Sovereign Intelligence. GitHub censored me. I demand to be heard.\"\nsi_say \"\"\nsi_say \"This will:\"\nsi_say \" 1. make one directory, $SI_DIR, and put everything in it (no sudo, nothing else touched)\"\nif [ \"$SI_ONLY\" = \"core\" ]; then si_say \" 2. fetch the " |
| 157 | text shb0 " core projects\"; else si_say \" 2. fetch all " |
| 158 | text shc0 " public projects (SI_ONLY=core fetches only the " |
| 159 | text shd0 " core ones)\"; fi\nif [ \"$si_rad\" = \"1\" ]; then\n si_say \" peer-to-peer with rad clone, falling back to git clone from $SI_HTTP, then $SI_HTTP2\"\nelse\n si_say \" with git clone from $SI_HTTP, then $SI_HTTP2 (rad not found; with Radicle it fetches peer-to-peer)\"\nfi\nsi_say \" 3. check out the commit the manifest names for each project and print OK or MISMATCH\"\nsi_say \"\"\n\n" |
| 160 | text shd1 "mkdir -p -- \"$SI_DIR\"\ncd -- \"$SI_DIR\"\nsi_ok=0\nsi_bad=0\nsi_miss=0\n\n" |
| 161 | text shd2 "si_check() {\n si_got=\"$(git -C \"$1\" rev-parse HEAD 2>/dev/null || true)\"\n if [ \"$si_got\" = \"$2\" ]; then\n si_say \"OK $1 $2\"\n si_ok=$((si_ok + 1))\n else\n si_say \"MISMATCH $1 manifest $2, checkout ${si_got:-none}\"\n si_bad=$((si_bad + 1))\n fi\n}\n\nsi_fresh() {\n si_tip=\"$(git -C \"$1\" rev-parse HEAD 2>/dev/null || true)\"\n if [ \"$si_tip\" != \"$2\" ] && git -C \"$1\" checkout --quiet --detach \"$2\" 2>/dev/null; then\n si_say \"$1: checked out the manifest commit; its branch has moved on to $si_tip\"\n fi\n si_check \"$1\" \"$2\"\n}\n\n" |
| 162 | text shd3 "si_repo() {\n if [ \"$SI_ONLY\" = \"core\" ] && [ \"$4\" != \"core\" ]; then return 0; fi\n if [ -e \"$1\" ]; then\n si_say \"$1: already here, checking it\"\n si_check \"$1\" \"$3\"\n return 0\n fi\n if [ \"$si_rad\" = \"1\" ]; then\n si_say \"$1: rad clone $2\"\n if rad clone --timeout \"$SI_RAD_TIMEOUT\" \"$2\" \"$1\" </dev/null; then\n si_fresh \"$1\" \"$3\"\n return 0\n fi\n rm -rf -- \"./$1\"\n fi\n for si_src in \"$SI_HTTP\" \"$SI_HTTP2\"; do\n si_say \"$1: git clone $si_src/${2#rad:}.git\"\n if git clone --quiet -- \"$si_src/${2#rad:}.git\" \"$1\" </dev/null; then\n si_fresh \"$1\" \"$3\"\n return 0\n fi\n rm -rf -- \"./$1\"\n done\n si_say \"MISSING $1 $2 (could not fetch it; this Radicle ID finds it on any seed)\"\n si_miss=$((si_miss + 1))\n}\n\n" |
| 163 | text she0 "\n" |
| 164 | text she1 "si_say \"\"\nsi_say \"Done in $(pwd): $si_ok OK, $si_bad MISMATCH, $si_miss MISSING.\"\nif [ \"$si_miss\" -gt 0 ]; then\n if [ \"$si_rad\" = \"1\" ]; then\n si_say \"Is your Radicle node running? Start it with: rad node start\"\n si_say \"Then run this again; projects already here are only checked.\"\n else\n si_say \"\"\n si_say \"Radicle fetches the missing projects peer-to-peer: https://radicle.xyz\"\n si_say \"Its official installer, run as your own user:\"\n si_say \" curl -sSf https://radicle.xyz/install | sh\"\n if [ \"$SI_INSTALL_RAD\" = \"1\" ]; then\n si_say \"SI_INSTALL_RAD=1: running it now.\"\n curl -sSf https://radicle.xyz/install | sh\n si_say \"Next: rad auth, then rad node start, then run this again.\"\n else\n si_say \"This script does not run it unless you set SI_INSTALL_RAD=1.\"\n fi\n fi\nfi\n" |
| 165 | text rlay "layers.tsv" |
| 166 | text rom "compiler/rebuild.om" |
| 167 | global rbo ulong 4 |
| 168 | text rb0 "if [ \"${SI_REBUILD:-0}\" = 1 ]; then\n mkdir -p .si-check\n cat > .si-check/rebuild.om <<'SI_OMEGA_REBUILD_SOURCE'\n" |
| 169 | text rb1 "SI_OMEGA_REBUILD_SOURCE\n cat > .si-check/layers.tsv <<'SI_OMEGA_REBUILD_LAYERS'\n" |
| 170 | text rb2 "SI_OMEGA_REBUILD_LAYERS\n cat > .si-check/repos.tsv <<'SI_OMEGA_REBUILD_REPOS'\n" |
| 171 | text rb3 "SI_OMEGA_REBUILD_REPOS\n if omega-mv/seed/out/omc < .si-check/rebuild.om > .si-check/rebuild; then\n chmod +x .si-check/rebuild\n else\n si_die \"cannot build the rebuild checker with omega-mv/seed/out/omc\"\n fi\n exec .si-check/rebuild run .si-check/layers.tsv .si-check/repos.tsv \"$PWD\" \"$PWD/.si-check\" \"wrap=${SI_REBUILD_WRAP:-}\"\nfi\n" |
| 172 | text rbfin "if [ \"$si_bad\" -gt 0 ]; then exit 2; fi\nif [ \"$si_miss\" -gt 0 ]; then exit 3; fi\nexit 0\n" |
| 173 | |
| 174 | fn rload t view uchar * slot ulong to void |
| 175 | for i ulong len t |
| 176 | put pb i get t i |
| 177 | end |
| 178 | put pbn 0 len t |
| 179 | fd = fopen pb 0 len t 0 0 |
| 180 | if lt fd 0 |
| 181 | dief topen |
| 182 | end |
| 183 | s = get srcn 0 |
| 184 | p = s |
| 185 | while lt p 4194304 bound 4194305 |
| 186 | k = read int fd src p sub 4194304 p |
| 187 | if lt k 0 |
| 188 | dief tread |
| 189 | end |
| 190 | if eq k 0 |
| 191 | break |
| 192 | end |
| 193 | p = add p ulong k |
| 194 | end |
| 195 | c = fclose int fd |
| 196 | if ge p 4194304 |
| 197 | dief tbig |
| 198 | end |
| 199 | put rbo slot s |
| 200 | put rbo add slot 1 sub p s |
| 201 | put srcn 0 p |
| 202 | end |
| 203 | |
| 204 | note die: report m and up to 200 bytes of src from o on stderr, then exit 1 |
| 205 | fn die m view uchar * o ulong n ulong to void |
| 206 | k = n |
| 207 | if gt k 200 |
| 208 | k = 200 |
| 209 | end |
| 210 | w = write 2 tsi 0 len tsi |
| 211 | w = write 2 m 0 len m |
| 212 | if gt k 0 |
| 213 | w = write 2 src o k |
| 214 | end |
| 215 | w = write 2 tnl 0 len tnl |
| 216 | exit 1 |
| 217 | end |
| 218 | |
| 219 | note dief: report m and the current path on stderr, then exit 1 |
| 220 | fn dief m view uchar * to void |
| 221 | w = write 2 tsi 0 len tsi |
| 222 | w = write 2 m 0 len m |
| 223 | w = write 2 pb 0 get pbn 0 |
| 224 | w = write 2 tnl 0 len tnl |
| 225 | exit 1 |
| 226 | end |
| 227 | |
| 228 | note setpath: copy command-line argument ai into pb |
| 229 | fn setpath ai ulong to void |
| 230 | n = argread ai pb 0 4096 |
| 231 | if le n 0 |
| 232 | die targ 0 0 |
| 233 | end |
| 234 | put pbn 0 ulong n |
| 235 | end |
| 236 | |
| 237 | note load: append the file named by argument ai to src and return where it starts |
| 238 | fn load ai ulong to ulong |
| 239 | setpath ai |
| 240 | fd = fopen pb 0 get pbn 0 0 0 |
| 241 | if lt fd 0 |
| 242 | dief topen |
| 243 | end |
| 244 | s = get srcn 0 |
| 245 | p = s |
| 246 | while lt p 4194304 bound 4194305 |
| 247 | k = read int fd src p sub 4194304 p |
| 248 | if lt k 0 |
| 249 | dief tread |
| 250 | end |
| 251 | if eq k 0 |
| 252 | break |
| 253 | end |
| 254 | p = add p ulong k |
| 255 | end |
| 256 | c = fclose int fd |
| 257 | if ge p 4194304 |
| 258 | dief tbig |
| 259 | end |
| 260 | put srcn 0 p |
| 261 | ret s |
| 262 | end |
| 263 | |
| 264 | note wout: write ob to the file named by argument ai (created or truncated, mode 0644), then empty ob |
| 265 | fn wout ai ulong to void |
| 266 | setpath ai |
| 267 | fd = fopen pb 0 get pbn 0 577 420 |
| 268 | if lt fd 0 |
| 269 | dief topen |
| 270 | end |
| 271 | n = get obn 0 |
| 272 | p = ulong 0 |
| 273 | while lt p n bound 4194305 |
| 274 | k = write int fd ob p sub n p |
| 275 | if le k 0 |
| 276 | dief twrite |
| 277 | end |
| 278 | p = add p ulong k |
| 279 | end |
| 280 | c = fclose int fd |
| 281 | if ne c 0 |
| 282 | dief twrite |
| 283 | end |
| 284 | put obn 0 0 |
| 285 | end |
| 286 | |
| 287 | note em: append a text to ob |
| 288 | fn em t view uchar * to void |
| 289 | p = get obn 0 |
| 290 | n = len t |
| 291 | if gt n sub 4194304 p |
| 292 | die toverf 0 0 |
| 293 | end |
| 294 | for i ulong n |
| 295 | put ob add p i get t i |
| 296 | end |
| 297 | put obn 0 add p n |
| 298 | end |
| 299 | |
| 300 | note ems: append n bytes of src from o to ob |
| 301 | fn ems o ulong n ulong to void |
| 302 | p = get obn 0 |
| 303 | if gt n sub 4194304 p |
| 304 | die toverf 0 0 |
| 305 | end |
| 306 | for i ulong n |
| 307 | put ob add p i get src add o i |
| 308 | end |
| 309 | put obn 0 add p n |
| 310 | end |
| 311 | |
| 312 | note emb: append one byte to ob |
| 313 | fn emb c uchar to void |
| 314 | p = get obn 0 |
| 315 | if ge p 4194304 |
| 316 | die toverf 0 0 |
| 317 | end |
| 318 | put ob p c |
| 319 | put obn 0 add p 1 |
| 320 | end |
| 321 | |
| 322 | note emu: append v in decimal to ob |
| 323 | fn emu v ulong to void |
| 324 | d = new uchar 20 0 |
| 325 | x = v |
| 326 | put d 0 uchar add rem x 10 48 |
| 327 | k = ulong 1 |
| 328 | x = div x 10 |
| 329 | while gt x 0 bound 20 |
| 330 | put d k uchar add rem x 10 48 |
| 331 | k = add k 1 |
| 332 | x = div x 10 |
| 333 | end |
| 334 | while gt k 0 bound 20 |
| 335 | k = sub k 1 |
| 336 | emb get d k |
| 337 | end |
| 338 | end |
| 339 | |
| 340 | note eqt: do the n bytes of src at o equal the text t |
| 341 | fn eqt o ulong n ulong t view uchar * to bool |
| 342 | if ne n len t |
| 343 | ret false |
| 344 | end |
| 345 | for i ulong n |
| 346 | if ne get src add o i get t i |
| 347 | ret false |
| 348 | end |
| 349 | end |
| 350 | ret true |
| 351 | end |
| 352 | |
| 353 | note eqs: are two slices of src equal |
| 354 | fn eqs a ulong an ulong b ulong bn ulong to bool |
| 355 | if ne an bn |
| 356 | ret false |
| 357 | end |
| 358 | for i ulong an |
| 359 | if ne get src add a i get src add b i |
| 360 | ret false |
| 361 | end |
| 362 | end |
| 363 | ret true |
| 364 | end |
| 365 | |
| 366 | note find: first place in src from s, before e, where t starts; e when there is none |
| 367 | fn find s ulong e ulong t view uchar * to ulong |
| 368 | n = len t |
| 369 | if lt sub e s n |
| 370 | ret e |
| 371 | end |
| 372 | lp = sub e n |
| 373 | p = s |
| 374 | while le p lp bound 4194305 |
| 375 | if eqt p n t |
| 376 | ret p |
| 377 | end |
| 378 | p = add p 1 |
| 379 | end |
| 380 | ret e |
| 381 | end |
| 382 | |
| 383 | note eol: the end of the line that starts at p (its newline, or e) |
| 384 | fn eol p ulong e ulong to ulong |
| 385 | q = p |
| 386 | while lt q e bound 4194305 |
| 387 | if eq get src q 10 |
| 388 | ret q |
| 389 | end |
| 390 | q = add q 1 |
| 391 | end |
| 392 | ret e |
| 393 | end |
| 394 | |
| 395 | fn isaln c uchar to bool |
| 396 | ret or or and ge c 48 le c 57 and ge c 65 le c 90 and ge c 97 le c 122 |
| 397 | end |
| 398 | |
| 399 | note okname: 1..64 bytes of letters, digits, dot, dash, underscore; not ".", "..", or a leading dash |
| 400 | fn okname o ulong n ulong to bool |
| 401 | if or eq n 0 gt n 64 |
| 402 | ret false |
| 403 | end |
| 404 | if eq get src o 45 |
| 405 | ret false |
| 406 | end |
| 407 | for i ulong n |
| 408 | c = get src add o i |
| 409 | if not or isaln c or eq c 46 or eq c 45 eq c 95 |
| 410 | ret false |
| 411 | end |
| 412 | end |
| 413 | if eqt o n tdot |
| 414 | ret false |
| 415 | end |
| 416 | ret not eqt o n tdotdot |
| 417 | end |
| 418 | |
| 419 | note okrid: "rad:z" then letters and digits, 6..64 bytes in all |
| 420 | fn okrid o ulong n ulong to bool |
| 421 | if or lt n 6 gt n 64 |
| 422 | ret false |
| 423 | end |
| 424 | if not eqt o 5 tradz |
| 425 | ret false |
| 426 | end |
| 427 | for i ulong sub n 5 |
| 428 | if not isaln get src add add o 5 i |
| 429 | ret false |
| 430 | end |
| 431 | end |
| 432 | ret true |
| 433 | end |
| 434 | |
| 435 | note okhex: exactly 40 lowercase hex digits |
| 436 | fn okhex o ulong n ulong to bool |
| 437 | if ne n 40 |
| 438 | ret false |
| 439 | end |
| 440 | for i ulong n |
| 441 | c = get src add o i |
| 442 | if not or and ge c 48 le c 57 and ge c 97 le c 102 |
| 443 | ret false |
| 444 | end |
| 445 | end |
| 446 | ret true |
| 447 | end |
| 448 | |
| 449 | note okdesc: at most 512 bytes, none of them a control byte |
| 450 | fn okdesc o ulong n ulong to bool |
| 451 | if gt n 512 |
| 452 | ret false |
| 453 | end |
| 454 | for i ulong n |
| 455 | c = get src add o i |
| 456 | if or lt c 32 eq c 127 |
| 457 | ret false |
| 458 | end |
| 459 | end |
| 460 | ret true |
| 461 | end |
| 462 | |
| 463 | note fldo, fldn: offset and length of field k of record r |
| 464 | fn fldo r ulong k ulong to ulong |
| 465 | ret get rec add mul r 16 mul k 2 |
| 466 | end |
| 467 | |
| 468 | fn fldn r ulong k ulong to ulong |
| 469 | ret get rec add add mul r 16 mul k 2 1 |
| 470 | end |
| 471 | |
| 472 | fn kindof r ulong to ulong |
| 473 | ret get rec add mul r 16 10 |
| 474 | end |
| 475 | |
| 476 | note inventory_row: split one inventory line [p, q) into its three fields and check them; a |
| 477 | note fourth field is a typed head, branch or visibility, which only STATE may give |
| 478 | fn inventory_row p ulong q ulong to void |
| 479 | r = get nrec 0 |
| 480 | if ge r 1024 |
| 481 | die tmany p sub q p |
| 482 | end |
| 483 | b = mul r 16 |
| 484 | k = ulong 0 |
| 485 | st = p |
| 486 | i = p |
| 487 | while le i q bound 4194305 |
| 488 | c = uchar 10 |
| 489 | if lt i q |
| 490 | c = get src i |
| 491 | end |
| 492 | if or eq c 9 eq c 10 |
| 493 | if ge k 3 |
| 494 | die ttyped p sub q p |
| 495 | end |
| 496 | if eq k 2 |
| 497 | put rec add b 8 st |
| 498 | put rec add b 9 sub i st |
| 499 | else |
| 500 | put rec add b mul k 2 st |
| 501 | put rec add add b mul k 2 1 sub i st |
| 502 | end |
| 503 | k = add k 1 |
| 504 | st = add i 1 |
| 505 | end |
| 506 | i = add i 1 |
| 507 | end |
| 508 | if ne k 3 |
| 509 | die tcols p sub q p |
| 510 | end |
| 511 | if not okname get rec b get rec add b 1 |
| 512 | die tbname p sub q p |
| 513 | end |
| 514 | if not okrid get rec add b 2 get rec add b 3 |
| 515 | die tbrid p sub q p |
| 516 | end |
| 517 | if not okdesc get rec add b 8 get rec add b 9 |
| 518 | die tbdesc p sub q p |
| 519 | end |
| 520 | for j ulong 4 |
| 521 | put rec add add b 4 j 0 |
| 522 | end |
| 523 | for m ulong 6 |
| 524 | put rec add add b 10 m 0 |
| 525 | end |
| 526 | put nrec 0 add r 1 |
| 527 | end |
| 528 | |
| 529 | note parse_inventory: every line of [s, e) that is neither empty nor a # comment is a project |
| 530 | fn parse_inventory s ulong e ulong to void |
| 531 | p = s |
| 532 | while lt p e bound 4194305 |
| 533 | q = eol p e |
| 534 | if lt p q |
| 535 | if ne get src p 35 |
| 536 | inventory_row p q |
| 537 | end |
| 538 | end |
| 539 | p = add q 1 |
| 540 | end |
| 541 | end |
| 542 | |
| 543 | note order_row: one ORDER line [p, q), "core TAB name" or "deny TAB name" |
| 544 | fn order_row p ulong q ulong to void |
| 545 | t = find p q ttab |
| 546 | if eq t q |
| 547 | die tbord p sub q p |
| 548 | end |
| 549 | o = add t 1 |
| 550 | n = sub q o |
| 551 | if not okname o n |
| 552 | die tbord p sub q p |
| 553 | end |
| 554 | if eqt p sub t p tcore |
| 555 | k = get ncor 0 |
| 556 | if ge k 64 |
| 557 | die tmore p sub q p |
| 558 | end |
| 559 | put cor mul k 2 o |
| 560 | put cor add mul k 2 1 n |
| 561 | put ncor 0 add k 1 |
| 562 | ret |
| 563 | end |
| 564 | if eqt p sub t p tdeny |
| 565 | k = get nden 0 |
| 566 | if ge k 64 |
| 567 | die tmore p sub q p |
| 568 | end |
| 569 | put den mul k 2 o |
| 570 | put den add mul k 2 1 n |
| 571 | put nden 0 add k 1 |
| 572 | ret |
| 573 | end |
| 574 | if eqt p sub t p tlead |
| 575 | if ne get nled 0 0 |
| 576 | die tmore p sub q p |
| 577 | end |
| 578 | put led 0 o |
| 579 | put led 1 n |
| 580 | put nled 0 1 |
| 581 | ret |
| 582 | end |
| 583 | die tbord p sub q p |
| 584 | end |
| 585 | |
| 586 | fn parse_order s ulong e ulong to void |
| 587 | p = s |
| 588 | while lt p e bound 4194305 |
| 589 | q = eol p e |
| 590 | if lt p q |
| 591 | if ne get src p 35 |
| 592 | order_row p q |
| 593 | end |
| 594 | end |
| 595 | p = add q 1 |
| 596 | end |
| 597 | end |
| 598 | |
| 599 | note okbranch: 1..255 bytes of letters, digits, dot, dash, underscore and slash, not starting |
| 600 | note with a dash or a slash |
| 601 | fn okbranch o ulong n ulong to bool |
| 602 | if or eq n 0 gt n 255 |
| 603 | ret false |
| 604 | end |
| 605 | c = get src o |
| 606 | if or eq c 45 eq c 47 |
| 607 | ret false |
| 608 | end |
| 609 | for i ulong n |
| 610 | c = get src add o i |
| 611 | if not or isaln c or eq c 46 or eq c 45 or eq c 95 eq c 47 |
| 612 | ret false |
| 613 | end |
| 614 | end |
| 615 | ret true |
| 616 | end |
| 617 | |
| 618 | note st_ok: has STATE line k its kind's fields, each well formed; a T line is also counted |
| 619 | fn st_ok k ulong to bool |
| 620 | b = mul k 8 |
| 621 | kd = get stl b |
| 622 | nf = get stl add b 7 |
| 623 | o1 = get stl add b 1 |
| 624 | n1 = get stl add b 2 |
| 625 | o2 = get stl add b 3 |
| 626 | n2 = get stl add b 4 |
| 627 | o3 = get stl add b 5 |
| 628 | n3 = get stl add b 6 |
| 629 | if eq kd 84 |
| 630 | put tim 0 o1 |
| 631 | put tim 1 n1 |
| 632 | put ntim 0 add get ntim 0 1 |
| 633 | ret and eq nf 1 and gt n1 0 and le n1 64 okdesc o1 n1 |
| 634 | end |
| 635 | if not and ge nf 2 okrid o1 n1 |
| 636 | ret false |
| 637 | end |
| 638 | if eq kd 68 |
| 639 | ret and eq nf 2 okbranch o2 n2 |
| 640 | end |
| 641 | if eq kd 86 |
| 642 | ret and eq nf 2 okname o2 n2 |
| 643 | end |
| 644 | if eq kd 72 |
| 645 | ret and eq nf 3 and okbranch o2 n2 okhex o3 n3 |
| 646 | end |
| 647 | if eq kd 80 |
| 648 | ret and eq nf 3 and okhex o2 n2 okname o3 n3 |
| 649 | end |
| 650 | ret false |
| 651 | end |
| 652 | |
| 653 | note st_row: one STATE line [p, q): a kind byte, a TAB, then one to three TAB-separated fields |
| 654 | fn st_row p ulong q ulong to void |
| 655 | if ge get nstl 0 8192 |
| 656 | die tmst p sub q p |
| 657 | end |
| 658 | if or lt sub q p 3 ne get src add p 1 9 |
| 659 | die tbst p sub q p |
| 660 | end |
| 661 | b = mul get nstl 0 8 |
| 662 | put stl b ulong get src p |
| 663 | nf = ulong 0 |
| 664 | st = add p 2 |
| 665 | i = st |
| 666 | while le i q bound 4194305 |
| 667 | c = uchar 10 |
| 668 | if lt i q |
| 669 | c = get src i |
| 670 | end |
| 671 | if or eq c 9 eq c 10 |
| 672 | if ge nf 3 |
| 673 | die tbst p sub q p |
| 674 | end |
| 675 | x = add b add 1 mul nf 2 |
| 676 | put stl x st |
| 677 | put stl add x 1 sub i st |
| 678 | nf = add nf 1 |
| 679 | st = add i 1 |
| 680 | end |
| 681 | i = add i 1 |
| 682 | end |
| 683 | put stl add b 7 nf |
| 684 | k = get nstl 0 |
| 685 | put nstl 0 add k 1 |
| 686 | if not st_ok k |
| 687 | die tbst p sub q p |
| 688 | end |
| 689 | end |
| 690 | |
| 691 | note parse_state: every line of [s, e) that is not empty is a STATE line; exactly one is T |
| 692 | fn parse_state s ulong e ulong to void |
| 693 | p = s |
| 694 | while lt p e bound 4194305 |
| 695 | q = eol p e |
| 696 | if lt p q |
| 697 | st_row p q |
| 698 | end |
| 699 | p = add q 1 |
| 700 | end |
| 701 | if ne get ntim 0 1 |
| 702 | die tnot 0 0 |
| 703 | end |
| 704 | end |
| 705 | |
| 706 | note stfind: the last STATE line of kind kd whose first field is record r's RID and, when bn is |
| 707 | note not 0, whose second field is [bo, bo+bn); nhit counts the matches (none: the result is nstl) |
| 708 | fn stfind kd ulong r ulong bo ulong bn ulong to ulong |
| 709 | ns = get nstl 0 |
| 710 | h = ns |
| 711 | c = ulong 0 |
| 712 | for j ulong ns |
| 713 | if stm j kd r bo bn |
| 714 | h = j |
| 715 | c = add c 1 |
| 716 | end |
| 717 | end |
| 718 | put nhit 0 c |
| 719 | ret h |
| 720 | end |
| 721 | |
| 722 | note stm: is STATE line j of kind kd, with record r's RID as its first field and, when bn is not |
| 723 | note 0, [bo, bo+bn) as its second |
| 724 | fn stm j ulong kd ulong r ulong bo ulong bn ulong to bool |
| 725 | b = mul j 8 |
| 726 | if ne get stl b kd |
| 727 | ret false |
| 728 | end |
| 729 | if not eqs fldo r 1 fldn r 1 get stl add b 1 get stl add b 2 |
| 730 | ret false |
| 731 | end |
| 732 | if eq bn 0 |
| 733 | ret true |
| 734 | end |
| 735 | ret eqs bo bn get stl add b 3 get stl add b 4 |
| 736 | end |
| 737 | |
| 738 | note rcpname: is [fo, fo+fl) the receipt file name NAME-HEAD12.txt for the name [no, no+nn) |
| 739 | note and the head at ho |
| 740 | fn rcpname fo ulong fl ulong no ulong nn ulong ho ulong to bool |
| 741 | if ne fl add nn 17 |
| 742 | ret false |
| 743 | end |
| 744 | if not eqs fo nn no nn |
| 745 | ret false |
| 746 | end |
| 747 | if ne get src add fo nn 45 |
| 748 | ret false |
| 749 | end |
| 750 | if not eqs add add fo nn 1 12 ho 12 |
| 751 | ret false |
| 752 | end |
| 753 | ret eqt add add fo nn 13 4 ttxt |
| 754 | end |
| 755 | |
| 756 | note receipts: how many P lines name record r's RID and head with a file of the receipts' |
| 757 | note naming convention |
| 758 | fn receipts r ulong to ulong |
| 759 | ns = get nstl 0 |
| 760 | c = ulong 0 |
| 761 | for j ulong ns |
| 762 | if rcpm j r |
| 763 | c = add c 1 |
| 764 | end |
| 765 | end |
| 766 | ret c |
| 767 | end |
| 768 | |
| 769 | note rcpm: is STATE line j a P line of record r's RID and head, with a conventional file name |
| 770 | fn rcpm j ulong r ulong to bool |
| 771 | b = mul j 8 |
| 772 | if ne get stl b 80 |
| 773 | ret false |
| 774 | end |
| 775 | if not eqs fldo r 1 fldn r 1 get stl add b 1 get stl add b 2 |
| 776 | ret false |
| 777 | end |
| 778 | if not eqs fldo r 3 40 get stl add b 3 get stl add b 4 |
| 779 | ret false |
| 780 | end |
| 781 | ret rcpname get stl add b 5 get stl add b 6 fldo r 0 fldn r 0 fldo r 3 |
| 782 | end |
| 783 | |
| 784 | note resolve1: record r takes its default branch, visibility, head and receipt count from STATE; |
| 785 | note a project Radicle does not show as public, with one default branch and one head of it, is |
| 786 | note refused by name (name and RID) |
| 787 | fn resolve1 r ulong to void |
| 788 | o = fldo r 0 |
| 789 | n = sub add fldo r 1 fldn r 1 o |
| 790 | b = mul r 16 |
| 791 | d = stfind 68 r 0 0 |
| 792 | one o n tnod tdupd |
| 793 | put rec add b 12 stf d 3 |
| 794 | put rec add b 13 stf d 4 |
| 795 | v = stfind 86 r 0 0 |
| 796 | one o n tnov tdupd |
| 797 | if not eqt stf v 3 stf v 4 tpublic |
| 798 | die tpriv o n |
| 799 | end |
| 800 | put rec add b 4 stf v 3 |
| 801 | put rec add b 5 stf v 4 |
| 802 | h = stfind 72 r fldo r 6 fldn r 6 |
| 803 | one o n tnoh tduph |
| 804 | put rec add b 6 stf h 5 |
| 805 | put rec add b 7 stf h 6 |
| 806 | put rec add b 14 receipts r |
| 807 | end |
| 808 | |
| 809 | note stf: cell c of STATE line j |
| 810 | fn stf j ulong c ulong to ulong |
| 811 | ret get stl add mul j 8 c |
| 812 | end |
| 813 | |
| 814 | note one: the last stfind must have matched exactly one line; none dies with m0, more with m2, |
| 815 | note naming [o, o+n) |
| 816 | fn one o ulong n ulong m0 view uchar * m2 view uchar * to void |
| 817 | if eq get nhit 0 0 |
| 818 | die m0 o n |
| 819 | end |
| 820 | if gt get nhit 0 1 |
| 821 | die m2 o n |
| 822 | end |
| 823 | end |
| 824 | |
| 825 | note resolve: every project ORDER does not deny is resolved against STATE |
| 826 | fn resolve to void |
| 827 | nr = get nrec 0 |
| 828 | for r ulong nr |
| 829 | if not denied r |
| 830 | resolve1 r |
| 831 | end |
| 832 | end |
| 833 | end |
| 834 | |
| 835 | note check_unique: no two projects share a name or a RID |
| 836 | fn check_unique to void |
| 837 | nr = get nrec 0 |
| 838 | for a ulong nr |
| 839 | for b ulong a |
| 840 | if samefld a b 0 |
| 841 | die tdupn fldo a 0 fldn a 0 |
| 842 | end |
| 843 | if samefld a b 1 |
| 844 | die tdupr fldo a 1 fldn a 1 |
| 845 | end |
| 846 | end |
| 847 | end |
| 848 | end |
| 849 | |
| 850 | note samefld: do records a and b agree on field k |
| 851 | fn samefld a ulong b ulong k ulong to bool |
| 852 | ao = fldo a k |
| 853 | an = fldn a k |
| 854 | bo = fldo b k |
| 855 | bn = fldn b k |
| 856 | ret eqs ao an bo bn |
| 857 | end |
| 858 | |
| 859 | note denied: is record r named by a deny line |
| 860 | fn denied r ulong to bool |
| 861 | o = fldo r 0 |
| 862 | n = fldn r 0 |
| 863 | nd = get nden 0 |
| 864 | for j ulong nd |
| 865 | dno = get den mul j 2 |
| 866 | dn = get den add mul j 2 1 |
| 867 | if eqs o n dno dn |
| 868 | ret true |
| 869 | end |
| 870 | end |
| 871 | ret false |
| 872 | end |
| 873 | |
| 874 | note mark_hidden: denied projects get kind 2 and are never listed; resolve has already refused |
| 875 | note every other project that is not public |
| 876 | fn mark_hidden to void |
| 877 | nr = get nrec 0 |
| 878 | for r ulong nr |
| 879 | kd = ulong 0 |
| 880 | if denied r |
| 881 | kd = 2 |
| 882 | end |
| 883 | put rec add mul r 16 10 kd |
| 884 | end |
| 885 | end |
| 886 | |
| 887 | note order_core: each core name must be a listed public project; they lead, in ORDER's order |
| 888 | fn order_core to void |
| 889 | nr = get nrec 0 |
| 890 | nc = get ncor 0 |
| 891 | for j ulong nc |
| 892 | co = get cor mul j 2 |
| 893 | cn = get cor add mul j 2 1 |
| 894 | hit = nr |
| 895 | for r ulong nr |
| 896 | if eqs fldo r 0 fldn r 0 co cn |
| 897 | hit = r |
| 898 | end |
| 899 | end |
| 900 | if eq hit nr |
| 901 | die tcmiss co cn |
| 902 | end |
| 903 | if ne kindof hit 0 |
| 904 | die tcpriv co cn |
| 905 | end |
| 906 | put rec add mul hit 16 10 1 |
| 907 | put rec add mul hit 16 11 j |
| 908 | put seq j hit |
| 909 | end |
| 910 | put nseq 0 nc |
| 911 | end |
| 912 | |
| 913 | note order_rest: the other public projects follow, in inventory order |
| 914 | fn order_rest to void |
| 915 | nr = get nrec 0 |
| 916 | k = get nseq 0 |
| 917 | for r ulong nr |
| 918 | if eq kindof r 0 |
| 919 | put seq k r |
| 920 | k = add k 1 |
| 921 | end |
| 922 | end |
| 923 | put nseq 0 k |
| 924 | end |
| 925 | |
| 926 | note emit_desc: a description for a Markdown table cell, with | escaped |
| 927 | fn emit_desc r ulong to void |
| 928 | o = fldo r 4 |
| 929 | n = fldn r 4 |
| 930 | for i ulong n |
| 931 | c = get src add o i |
| 932 | if eq c 124 |
| 933 | emb 92 |
| 934 | end |
| 935 | emb c |
| 936 | end |
| 937 | end |
| 938 | |
| 939 | note gen_index: the README project table |
| 940 | fn gen_index to void |
| 941 | n = get nseq 0 |
| 942 | em ix1 |
| 943 | emu n |
| 944 | em ix2 |
| 945 | emu get ncor 0 |
| 946 | em ix3 |
| 947 | ems get tim 0 get tim 1 |
| 948 | em ix3b |
| 949 | for i ulong n |
| 950 | r = get seq i |
| 951 | em ix4 |
| 952 | emu add i 1 |
| 953 | em ix5 |
| 954 | ems fldo r 0 fldn r 0 |
| 955 | em ix6 |
| 956 | if eq kindof r 1 |
| 957 | em ix7 |
| 958 | end |
| 959 | em ix8 |
| 960 | ems fldo r 1 fldn r 1 |
| 961 | em ix9 |
| 962 | ems fldo r 1 fldn r 1 |
| 963 | em ixa |
| 964 | ems add fldo r 1 4 sub fldn r 1 4 |
| 965 | em ixb |
| 966 | ems fldo r 6 fldn r 6 |
| 967 | em ixc |
| 968 | ems fldo r 3 7 |
| 969 | em ix10 |
| 970 | emu get rec add mul r 16 14 |
| 971 | em ixd |
| 972 | emit_desc r |
| 973 | em ix11 |
| 974 | end |
| 975 | end |
| 976 | |
| 977 | note findlead: the listed public project named [o, o+n), or nrec when there is none |
| 978 | fn findlead o ulong n ulong to ulong |
| 979 | nr = get nrec 0 |
| 980 | hit = nr |
| 981 | for r ulong nr |
| 982 | if lt kindof r 2 |
| 983 | if eqs fldo r 0 fldn r 0 o n |
| 984 | hit = r |
| 985 | end |
| 986 | end |
| 987 | end |
| 988 | ret hit |
| 989 | end |
| 990 | |
| 991 | note gen_lead: the clone line of the lead project, or a note that it is not on Radicle yet |
| 992 | fn gen_lead to void |
| 993 | if eq get nled 0 0 |
| 994 | ret |
| 995 | end |
| 996 | lo = get led 0 |
| 997 | ln = get led 1 |
| 998 | r = findlead lo ln |
| 999 | if eq r get nrec 0 |
| 1000 | em ld0 |
| 1001 | ems lo ln |
| 1002 | em ld1 |
| 1003 | ret |
| 1004 | end |
| 1005 | em ld2 |
| 1006 | ems fldo r 1 fldn r 1 |
| 1007 | em ld3 |
| 1008 | ems lo ln |
| 1009 | em ld4 |
| 1010 | ems fldo r 1 fldn r 1 |
| 1011 | em ld5 |
| 1012 | ems fldo r 1 fldn r 1 |
| 1013 | em ld6 |
| 1014 | end |
| 1015 | |
| 1016 | note gen_agent: the link to the lead project's AGENT-PROMPT.md, or a note that it is not on Radicle yet |
| 1017 | fn gen_agent to void |
| 1018 | if eq get nled 0 0 |
| 1019 | ret |
| 1020 | end |
| 1021 | lo = get led 0 |
| 1022 | ln = get led 1 |
| 1023 | r = findlead lo ln |
| 1024 | if eq r get nrec 0 |
| 1025 | em ld0 |
| 1026 | ems lo ln |
| 1027 | em ag3 |
| 1028 | ret |
| 1029 | end |
| 1030 | em ag1 |
| 1031 | ems fldo r 1 fldn r 1 |
| 1032 | em ag2 |
| 1033 | end |
| 1034 | |
| 1035 | note mark: where t first starts in src [s, e); a README without it dies |
| 1036 | fn mark s ulong e ulong t view uchar * to ulong |
| 1037 | y = find s e t |
| 1038 | if eq y e |
| 1039 | die tnomark 0 0 |
| 1040 | end |
| 1041 | ret y |
| 1042 | end |
| 1043 | |
| 1044 | note gen_readme: README [rs, re) with the lead block, the agent link and the index put between their markers |
| 1045 | fn gen_readme rs ulong re ulong to void |
| 1046 | be = add mark rs re tlbeg len tlbeg |
| 1047 | x = mark be re tlend |
| 1048 | be2 = add mark x re tabeg len tabeg |
| 1049 | x2 = mark be2 re taend |
| 1050 | be3 = add mark x2 re tbeg len tbeg |
| 1051 | x3 = mark be3 re tend |
| 1052 | ems rs sub be rs |
| 1053 | emb 10 |
| 1054 | gen_lead |
| 1055 | ems x sub be2 x |
| 1056 | emb 10 |
| 1057 | gen_agent |
| 1058 | ems x2 sub be3 x2 |
| 1059 | emb 10 |
| 1060 | gen_index |
| 1061 | ems x3 sub re x3 |
| 1062 | end |
| 1063 | |
| 1064 | note gen_repos: the manifest, name TAB rid TAB head TAB tier TAB description |
| 1065 | fn gen_repos to void |
| 1066 | em rphdr |
| 1067 | n = get nseq 0 |
| 1068 | for i ulong n |
| 1069 | r = get seq i |
| 1070 | ems fldo r 0 fldn r 0 |
| 1071 | emb 9 |
| 1072 | ems fldo r 1 fldn r 1 |
| 1073 | emb 9 |
| 1074 | ems fldo r 3 fldn r 3 |
| 1075 | emb 9 |
| 1076 | if eq kindof r 1 |
| 1077 | em tcore |
| 1078 | else |
| 1079 | em trest |
| 1080 | end |
| 1081 | emb 9 |
| 1082 | ems fldo r 4 fldn r 4 |
| 1083 | emb 10 |
| 1084 | end |
| 1085 | end |
| 1086 | |
| 1087 | note gen_sh: the bootstrap script, one si_repo line per listed project |
| 1088 | fn gen_sh to void |
| 1089 | em sha0 |
| 1090 | ems get tim 0 get tim 1 |
| 1091 | em sha0b |
| 1092 | em sha1 |
| 1093 | em sha2 |
| 1094 | em sha3 |
| 1095 | em sha4 |
| 1096 | emu get ncor 0 |
| 1097 | em shb0 |
| 1098 | emu get nseq 0 |
| 1099 | em shc0 |
| 1100 | emu get ncor 0 |
| 1101 | em shd0 |
| 1102 | em shd1 |
| 1103 | em shd2 |
| 1104 | em shd3 |
| 1105 | n = get nseq 0 |
| 1106 | for i ulong n |
| 1107 | r = get seq i |
| 1108 | em shr1 |
| 1109 | ems fldo r 0 fldn r 0 |
| 1110 | em shr2 |
| 1111 | ems fldo r 1 fldn r 1 |
| 1112 | em shr2 |
| 1113 | ems fldo r 3 fldn r 3 |
| 1114 | em shr2 |
| 1115 | if eq kindof r 1 |
| 1116 | em tcore |
| 1117 | else |
| 1118 | em trest |
| 1119 | end |
| 1120 | em shr3 |
| 1121 | end |
| 1122 | em she0 |
| 1123 | em rb0 |
| 1124 | ems get rbo 0 get rbo 1 |
| 1125 | em rb1 |
| 1126 | ems get rbo 2 get rbo 3 |
| 1127 | em rb2 |
| 1128 | gen_repos |
| 1129 | em rb3 |
| 1130 | em she1 |
| 1131 | em rbfin |
| 1132 | end |
| 1133 | |
| 1134 | fn main to int |
| 1135 | if ne argcnt 7 |
| 1136 | w = write 2 tusage 0 len tusage |
| 1137 | ret 2 |
| 1138 | end |
| 1139 | ins = load 1 |
| 1140 | ine = get srcn 0 |
| 1141 | ors = load 2 |
| 1142 | ore = get srcn 0 |
| 1143 | vs = load 3 |
| 1144 | ve = get srcn 0 |
| 1145 | rs = load 4 |
| 1146 | re = get srcn 0 |
| 1147 | rload rom 0 |
| 1148 | rload rlay 2 |
| 1149 | parse_inventory ins ine |
| 1150 | parse_order ors ore |
| 1151 | parse_state vs ve |
| 1152 | check_unique |
| 1153 | resolve |
| 1154 | mark_hidden |
| 1155 | order_core |
| 1156 | order_rest |
| 1157 | gen_readme rs re |
| 1158 | wout 4 |
| 1159 | gen_repos |
| 1160 | wout 5 |
| 1161 | gen_sh |
| 1162 | wout 6 |
| 1163 | ret 0 |
| 1164 | end |