omega-mv
Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.
Brought by drakestapleton
omega-mv / protocol / synapse / map / src / 75-publish.om
| 1 | note ======== new --publish: create the child on GitHub and open the parent's draft PR ======== |
| 2 | note Every step is one argv run as /usr/bin/env HOME=$HOME PATH=$HOME/.local/bin:/usr/bin:/bin ARGV... |
| 3 | note (execprog: empty environment, no PATH search), with the child's stdout sent to stderr so stdout |
| 4 | note stays JSONL. --dry-run prints {"argv":[...]} (and {"edit":..,"line":..} for the README step) |
| 5 | note instead of running anything. The first failing step stops the run: {"ok":false,...}, exit 70. |
| 6 | note Its globals, consts and texts are declared in 70-new.om: sm_new reads them, and omc needs a global, |
| 7 | note const or text declared before its first use. |
| 8 | |
| 9 | note sm_cat: pool slice for text a + slice (o, n) + text b; length in SSLEN |
| 10 | fn sm_cat a view uchar * o ulong n ulong b view uchar * to ulong |
| 11 | s = get gst SPOOL |
| 12 | z = sm_pt a |
| 13 | z = sm_pcp o n |
| 14 | z = sm_pt b |
| 15 | put gst SSLEN sub get gst SPOOL s |
| 16 | ret s |
| 17 | end |
| 18 | |
| 19 | note sm_pkenv: start a packed argv with the env wrapper; returns the next offset |
| 20 | fn sm_pkenv to ulong |
| 21 | put gpk 0 0 |
| 22 | put gpk 1 0 |
| 23 | put gst SPKN 0 |
| 24 | p = sm_pktx 2 tenv |
| 25 | k = sm_envkv thomee |
| 26 | if eq k SNONE |
| 27 | p = sm_pktx p tdefhome |
| 28 | p = sm_pktx p tdefpath |
| 29 | ret p |
| 30 | end |
| 31 | kn = get gst SSLEN |
| 32 | p = sm_pkadd p k kn |
| 33 | h = add k len thomee |
| 34 | hn = sub kn len thomee |
| 35 | q = sm_cat tpathk h hn tpathsfx |
| 36 | p = sm_pkadd p q get gst SSLEN |
| 37 | ret p |
| 38 | end |
| 39 | |
| 40 | fn sm_pkg p ulong k ulong to ulong |
| 41 | ret sm_pkadd p get gst k get gst add k 1 |
| 42 | end |
| 43 | |
| 44 | note sm_pkrun: run gpk (records up to offset p), stdout to stderr; exit status, 256 + signal, or 512 |
| 45 | fn sm_pkrun p ulong to ulong |
| 46 | st = new uchar 4 0 |
| 47 | if ne get gst SOVF 0 |
| 48 | ret 512 |
| 49 | end |
| 50 | r = sm_flush 1 |
| 51 | pid = fork |
| 52 | if lt pid 0 |
| 53 | ret 512 |
| 54 | end |
| 55 | if eq pid 0 |
| 56 | d = dupfd 2 1 0 |
| 57 | x = execprog gpk 0 p |
| 58 | exit 127 |
| 59 | end |
| 60 | w = waitpid int pid st 0 4 0 |
| 61 | if lt w 0 |
| 62 | ret 512 |
| 63 | end |
| 64 | s = ulong get st 0 |
| 65 | if ne s 0 |
| 66 | ret add 256 and s 127 |
| 67 | end |
| 68 | ret ulong get st 1 |
| 69 | end |
| 70 | |
| 71 | fn sm_oargv to void |
| 72 | sm_ob 91 |
| 73 | n = get gst SPKN |
| 74 | for i ulong n |
| 75 | if ge i 3 |
| 76 | if gt i 3 |
| 77 | sm_ob 44 |
| 78 | end |
| 79 | i2 = mul i 2 |
| 80 | ao = get garv i2 |
| 81 | al = get garv add i2 1 |
| 82 | sm_oq ao al |
| 83 | end |
| 84 | end |
| 85 | sm_ob 93 |
| 86 | end |
| 87 | |
| 88 | note sm_step: run (or print) the packed argv; a failure prints the error record and exits 70 |
| 89 | fn sm_step k ulong p ulong to void |
| 90 | if ne get gst SDRY 0 |
| 91 | sm_ob 123 |
| 92 | sm_ok tkargv |
| 93 | sm_oargv |
| 94 | sm_ob 125 |
| 95 | sm_ob 10 |
| 96 | ret |
| 97 | end |
| 98 | c = sm_pkrun p |
| 99 | if ne c 0 |
| 100 | sm_ob 123 |
| 101 | sm_ok tkok |
| 102 | sm_obool false |
| 103 | sm_okc tkstep |
| 104 | sm_on k |
| 105 | sm_okc tkargv |
| 106 | sm_oargv |
| 107 | sm_okc tkstat |
| 108 | sm_on c |
| 109 | sm_ob 125 |
| 110 | sm_ob 10 |
| 111 | sm_die 70 |
| 112 | end |
| 113 | end |
| 114 | |
| 115 | note git -C <slice k> ... prefix |
| 116 | fn sm_pkgit k ulong to ulong |
| 117 | p = sm_pkenv |
| 118 | p = sm_pktx p tgit |
| 119 | p = sm_pktx p tdashc |
| 120 | ret sm_pkg p k |
| 121 | end |
| 122 | |
| 123 | fn sm_pkid p ulong to ulong |
| 124 | p = sm_pktx p tdashcc |
| 125 | p = sm_pktx p tuname |
| 126 | p = sm_pktx p tdashcc |
| 127 | ret sm_pktx p tumail |
| 128 | end |
| 129 | |
| 130 | note sm_pubset: slices used by the steps (child dir, owner/repo of parent, clone dir, branch, line) |
| 131 | fn sm_pubset to void |
| 132 | d = sm_apool get gst SNDI |
| 133 | dn = get gst SSLEN |
| 134 | put gst SCHO d |
| 135 | put gst SCHL dn |
| 136 | po = get gst SNPO |
| 137 | q = sm_pfind po get gst SNPL 64 |
| 138 | put gst SPRO po |
| 139 | put gst SPRL q |
| 140 | c = sm_cat part tempty 0 0 d dn tparsfx |
| 141 | put gst SCLO c |
| 142 | put gst SCLL get gst SSLEN |
| 143 | b = sm_cat tconn get gst SNNO get gst SNNL part tempty 0 0 |
| 144 | put gst SBRO b |
| 145 | put gst SBRL get gst SSLEN |
| 146 | w = sm_pfind po q 47 |
| 147 | f = get gst SPOOL |
| 148 | z = sm_pcp po w |
| 149 | sm_pb 47 |
| 150 | z = sm_pcp get gst SNNO get gst SNNL |
| 151 | put gst SFNO f |
| 152 | put gst SFNL sub get gst SPOOL f |
| 153 | s = get gst SPOOL |
| 154 | sm_pb 45 |
| 155 | sm_pb 32 |
| 156 | sm_pb 91 |
| 157 | z = sm_pcp get gst SNNO get gst SNNL |
| 158 | z = sm_pt tr2 |
| 159 | z = sm_pcp f get gst SFNL |
| 160 | z = sm_pt tp3 |
| 161 | z = sm_pcp get gst SNUO get gst SNUL |
| 162 | put gst SLNO s |
| 163 | put gst SLNL sub get gst SPOOL s |
| 164 | end |
| 165 | |
| 166 | note sm_ishead: line at offset i of gfile starts with t |
| 167 | fn sm_ishead i ulong n ulong t view uchar * to bool |
| 168 | if gt add i len t n |
| 169 | ret false |
| 170 | end |
| 171 | for j ulong len t |
| 172 | if ne get gfile add i j get t j |
| 173 | ret false |
| 174 | end |
| 175 | end |
| 176 | ret true |
| 177 | end |
| 178 | |
| 179 | note sm_rdapp: copy gfile (n bytes) to output, then append the Connected repos section and the line |
| 180 | fn sm_rdapp n ulong to void |
| 181 | for j ulong n |
| 182 | sm_ob get gfile j |
| 183 | end |
| 184 | lastc = uchar 10 |
| 185 | if gt n 0 |
| 186 | lastc = get gfile sub n 1 |
| 187 | end |
| 188 | if ne lastc 10 |
| 189 | sm_ob 10 |
| 190 | end |
| 191 | sm_ot tconnhb |
| 192 | sm_op get gst SLNO get gst SLNL |
| 193 | sm_ob 10 |
| 194 | end |
| 195 | |
| 196 | note sm_rdins: copy gfile with the line inserted at the end of the section starting at h (scan stopped at i) |
| 197 | fn sm_rdins h ulong i ulong n ulong to void |
| 198 | jj = i |
| 199 | if gt jj n |
| 200 | jj = n |
| 201 | end |
| 202 | lo = add h len tconnh |
| 203 | for it ulong jj |
| 204 | if not and gt jj lo eq get gfile sub jj 1 10 |
| 205 | break |
| 206 | end |
| 207 | jj = sub jj 1 |
| 208 | end |
| 209 | for k ulong jj |
| 210 | sm_ob get gfile k |
| 211 | end |
| 212 | sm_ob 10 |
| 213 | sm_op get gst SLNO get gst SLNL |
| 214 | for kk ulong sub n jj |
| 215 | sm_ob get gfile add jj kk |
| 216 | end |
| 217 | end |
| 218 | |
| 219 | note sm_rdedit: add the README line under "## Connected repos" in the clone (section created if absent) |
| 220 | fn sm_rdedit to void |
| 221 | sm_pclr |
| 222 | sm_ppool get gst SCLO get gst SCLL |
| 223 | sm_pc 47 |
| 224 | sm_ptx treadme |
| 225 | x = sm_rdfile |
| 226 | if lt x 0 |
| 227 | sm_ob 123 |
| 228 | sm_ok tkok |
| 229 | sm_obool false |
| 230 | sm_okc tkedit |
| 231 | q = sm_ppath |
| 232 | sm_oq q get gst SSLEN |
| 233 | sm_okc tkstat |
| 234 | sm_on ulong sub 0 x |
| 235 | sm_ob 125 |
| 236 | sm_ob 10 |
| 237 | sm_die 70 |
| 238 | end |
| 239 | r = sm_flush 1 |
| 240 | n = get gst SFLEN |
| 241 | h = SNONE |
| 242 | i = ulong 0 |
| 243 | for it ulong n |
| 244 | if ge i n |
| 245 | break |
| 246 | end |
| 247 | if and eq h SNONE sm_ishead i n tconnh |
| 248 | h = i |
| 249 | else |
| 250 | if and ne h SNONE and gt i h eq get gfile i 35 |
| 251 | break |
| 252 | end |
| 253 | end |
| 254 | e = sm_pfind2 i n |
| 255 | i = add e 1 |
| 256 | end |
| 257 | if eq h SNONE |
| 258 | sm_rdapp n |
| 259 | else |
| 260 | sm_rdins h i n |
| 261 | end |
| 262 | w = sm_wratom |
| 263 | if lt w 0 |
| 264 | sm_err tnwrite |
| 265 | wr = write 2 gpath 0 get gst SPLEN |
| 266 | sm_errnl |
| 267 | sm_die 70 |
| 268 | end |
| 269 | end |
| 270 | |
| 271 | note sm_pfind2: offset of the next '\n' in gfile from i (n when none) |
| 272 | fn sm_pfind2 i ulong n ulong to ulong |
| 273 | if ge i n |
| 274 | ret n |
| 275 | end |
| 276 | for k ulong sub n i |
| 277 | j = add i k |
| 278 | if eq get gfile j 10 |
| 279 | ret j |
| 280 | end |
| 281 | end |
| 282 | ret n |
| 283 | end |
| 284 | |
| 285 | fn sm_ppath to ulong |
| 286 | s = get gst SPOOL |
| 287 | for i ulong get gst SPLEN |
| 288 | sm_pb get gpath i |
| 289 | end |
| 290 | put gst SSLEN sub get gst SPOOL s |
| 291 | ret s |
| 292 | end |
| 293 | |
| 294 | fn sm_publish to void |
| 295 | sm_pubset |
| 296 | p = sm_pkgit SCHO |
| 297 | p = sm_pktx p tinit |
| 298 | p = sm_pktx p tdashb |
| 299 | p = sm_pktx p tmain |
| 300 | sm_step 1 p |
| 301 | p = sm_pkgit SCHO |
| 302 | p = sm_pktx p tadd |
| 303 | p = sm_pktx p tdasha |
| 304 | sm_step 2 p |
| 305 | p = sm_pkgit SCHO |
| 306 | p = sm_pkid p |
| 307 | p = sm_pktx p tcommit |
| 308 | p = sm_pktx p tdashs |
| 309 | p = sm_pktx p tdashm |
| 310 | m = sm_cat tmsg1 get gst SNNO get gst SNNL tmsg1b |
| 311 | p = sm_pkadd p m get gst SSLEN |
| 312 | sm_step 3 p |
| 313 | p = sm_pkenv |
| 314 | p = sm_pktx p tgh |
| 315 | p = sm_pktx p trepo |
| 316 | p = sm_pktx p tcreate |
| 317 | p = sm_pkg p SFNO |
| 318 | p = sm_pktx p tpublic |
| 319 | p = sm_pktx p tdescr |
| 320 | p = sm_pkg p SNUO |
| 321 | p = sm_pktx p tsource |
| 322 | p = sm_pkg p SCHO |
| 323 | p = sm_pktx p tpush |
| 324 | sm_step 4 p |
| 325 | p = sm_pkenv |
| 326 | p = sm_pktx p tgit |
| 327 | p = sm_pktx p tclone |
| 328 | u = sm_cat tghurl get gst SPRO get gst SPRL part tempty 0 0 |
| 329 | p = sm_pkadd p u get gst SSLEN |
| 330 | p = sm_pkg p SCLO |
| 331 | sm_step 5 p |
| 332 | p = sm_pkgit SCLO |
| 333 | p = sm_pktx p tchkout |
| 334 | p = sm_pktx p tdashb |
| 335 | p = sm_pkg p SBRO |
| 336 | sm_step 6 p |
| 337 | if ne get gst SDRY 0 |
| 338 | sm_ob 123 |
| 339 | sm_ok tkedit |
| 340 | e = sm_cat part tempty 0 0 get gst SCLO get gst SCLL tsreadme |
| 341 | el = get gst SSLEN |
| 342 | sm_oq e el |
| 343 | sm_okc tkline |
| 344 | sm_oq get gst SLNO get gst SLNL |
| 345 | sm_ob 125 |
| 346 | sm_ob 10 |
| 347 | else |
| 348 | sm_rdedit |
| 349 | end |
| 350 | p = sm_pkgit SCLO |
| 351 | p = sm_pktx p tadd |
| 352 | p = sm_pktx p treadme |
| 353 | sm_step 8 p |
| 354 | p = sm_pkgit SCLO |
| 355 | p = sm_pkid p |
| 356 | p = sm_pktx p tcommit |
| 357 | p = sm_pktx p tdashs |
| 358 | p = sm_pktx p tdashm |
| 359 | m = sm_cat tmsg2 get gst SNNO get gst SNNL part tempty 0 0 |
| 360 | p = sm_pkadd p m get gst SSLEN |
| 361 | sm_step 9 p |
| 362 | p = sm_pkgit SCLO |
| 363 | p = sm_pktx p tpush |
| 364 | p = sm_pktx p tdashu |
| 365 | p = sm_pktx p torigin |
| 366 | p = sm_pkg p SBRO |
| 367 | sm_step 10 p |
| 368 | p = sm_pkenv |
| 369 | p = sm_pktx p tgh |
| 370 | p = sm_pktx p tpr |
| 371 | p = sm_pktx p tcreate |
| 372 | p = sm_pktx p tdraft |
| 373 | p = sm_pktx p tdashr |
| 374 | p = sm_pkadd p get gst SPRO get gst SPRL |
| 375 | p = sm_pktx p thead |
| 376 | p = sm_pkg p SBRO |
| 377 | p = sm_pktx p ttitle |
| 378 | t = sm_cat tconnt get gst SNNO get gst SNNL part tempty 0 0 |
| 379 | p = sm_pkadd p t get gst SSLEN |
| 380 | p = sm_pktx p tbodyf |
| 381 | b = sm_cat part tempty 0 0 get gst SCHO get gst SCHL tsppr |
| 382 | p = sm_pkadd p b get gst SSLEN |
| 383 | sm_step 11 p |
| 384 | if eq get gst SDRY 0 |
| 385 | sm_ob 123 |
| 386 | sm_ok tkpub |
| 387 | sm_obool true |
| 388 | sm_okc tkrepo |
| 389 | sm_oq get gst SFNO get gst SFNL |
| 390 | sm_okc tkbr |
| 391 | sm_oq get gst SBRO get gst SBRL |
| 392 | sm_ob 125 |
| 393 | sm_ob 10 |
| 394 | end |
| 395 | end |