Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/seed/omc/codereg.om # omega-mv Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance. Brought by drakestapleton Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / seed / omc / codereg.om` 599 lines ยท 9182 bytes Raw Blame History 1 note codereg.om -- error-code registry drift check (issue #797), compiled and run by seed/omc/gate15.sh. 2 note Arguments: REGISTRY OMC_SOURCE OMEGESE IRWASM_SOURCE RANLOG. Exit 0 agrees; 1 on drift, usage or unreadable input. 3 note A REGISTRY row is NS|CODE|STATUS|CASE|MEANING. NS omc and irwasm are separate namespaces: the same 4 note number means different things in each. STATUS emitted or io needs at least one emitting site in the 5 note namespace's source; unused needs none. Every site needs a row. An omc row names the gate15 case 6 note that must have refused with that code (RANLOG lines NAME CODE). OMEGESE must hold exactly one line 7 note | NS CODE | MEANING | per row and no other line of that shape. 8 global fb uchar `4194304` 9 global rg uchar 65536 10 global pth uchar 4096 11 global bars ulong 4 12 global st ulong 512 13 global mo ulong 512 14 global ml ulong 512 15 global co ulong 512 16 global cl ulong 512 17 global sc ulong 512 18 global dh ulong 512 19 global rh ulong 256 20 global ob uchar 512 21 global on ulong 1 22 text tm "FAIL codereg \nusage: codereg REGISTRY OMC_SOURCE OMEGESE IRWASM_SOURCE RANLOG\ncannot read argument\nmalformed registry row at line\nduplicate registry row\nemitting site without an emitted or io registry row\nemitted or io registry row without an emitting site\nOMEGESE row differs from the registry\nOMEGESE row count is not 1 for\ngate case refused with a code that has no emitted or io registry row\nregistry case did not refuse with its code in the gate\nmalformed OMEGESE registry row at line\nomc\nirwasm\nPASS codereg registry=\n sites=\n omegese=\n cases=\nemitted\nio\nunused\n-\nfail\nnfail\nunkfail\nlenval\nrefuse\nexit int\nnote\n| omc \n| irwasm \n | \n |" 23 24 fn ob_b c ulong to void 25 n = get on 0 26 if lt n 512 27 put ob n uchar c 28 put on 0 add n 1 29 end 30 end 31 32 fn ob_n v ulong to void 33 d = new uchar 20 0 34 k = ulong 0 35 x = v 36 for i ulong 20 37 put d k uchar add 48 rem x 10 38 k = add k 1 39 x = div x 10 40 if eq x 0 41 break 42 end 43 end 44 for j ulong k 45 ob_b ulong get d sub sub k j 1 46 end 47 end 48 49 note segat: offset of newline-separated segment k of tm. 50 fn segat k ulong to ulong 51 seg = ulong 0 52 for i ulong len tm 53 if eq seg k 54 ret i 55 end 56 if eq get tm i 10 57 seg = add seg 1 58 end 59 end 60 ret len tm 61 end 62 63 fn ob_s k ulong to void 64 t = segat k 65 for i ulong len tm 66 j = add t i 67 if ge j len tm 68 break 69 end 70 c = get tm j 71 if eq c 10 72 break 73 end 74 ob_b ulong c 75 end 76 end 77 78 fn ob_out fd int to void 79 n = get on 0 80 w = write fd ob 0 n 81 put on 0 0 82 end 83 84 note die: print FAIL, reason k; a 0 or 1 adds namespace and code b, a 2 adds number b. Exit 1. 85 fn die k ulong a ulong b ulong to void 86 ob_s 0 87 ob_s k 88 if lt a 2 89 ob_b 32 90 ob_s add 12 a 91 ob_b 32 92 ob_n b 93 end 94 if eq a 2 95 ob_b 32 96 ob_n b 97 end 98 ob_b 10 99 ob_out 2 100 exit 1 101 end 102 103 note load: argument idx into fb, at most cap bytes; returns the length. 104 fn load idx ulong cap ulong to ulong 105 r = argread idx pth 0 4096 106 if lt r 1 107 die 2 2 idx 108 end 109 fd = fopen pth 0 ulong r 524288 0 110 if lt fd 0 111 die 2 2 idx 112 end 113 n = ulong 0 114 note Every pass but the last adds at least one byte, and n = cap stops it: cap + 1 passes suffice. 115 for a ulong `4194305` 116 if eq n cap 117 die 2 2 idx 118 end 119 k = read int fd fb n sub cap n 120 if lt k 0 121 die 2 2 idx 122 end 123 if eq k 0 124 break 125 end 126 n = add n ulong k 127 end 128 c = fclose int fd 129 if lt c 0 130 die 2 2 idx 131 end 132 ret n 133 end 134 135 note prefix: length of segment k of tm when fb[p..e) begins with it, else 0. 136 fn prefix p ulong e ulong k ulong to ulong 137 t = segat k 138 m = ulong 0 139 for i ulong len tm 140 j = add t i 141 if ge j len tm 142 break 143 end 144 c = get tm j 145 if eq c 10 146 break 147 end 148 if ge add p i e 149 ret 0 150 end 151 if ne c get fb add p i 152 ret 0 153 end 154 m = add m 1 155 end 156 ret m 157 end 158 159 fn wordeq p ulong q ulong k ulong to bool 160 m = prefix p q k 161 if eq m 0 162 ret false 163 end 164 ret eq m sub q p 165 end 166 167 note sameat: rg[ro..ro+rl) equals fb[a..b). 168 fn sameat ro ulong rl ulong a ulong b ulong to bool 169 if ne rl sub b a 170 ret false 171 end 172 for i ulong rl 173 if ne get rg add ro i get fb add a i 174 ret false 175 end 176 end 177 ret true 178 end 179 180 fn eol s ulong n ulong to ulong 181 i = s 182 for a ulong `4194305` 183 if ge i n 184 ret n 185 end 186 if eq get fb i 10 187 ret i 188 end 189 i = add i 1 190 end 191 ret n 192 end 193 194 fn skipws s ulong e ulong to ulong 195 i = s 196 for a ulong `4194305` 197 if ge i e 198 ret e 199 end 200 c = get fb i 201 if and ne c 32 ne c 9 202 ret i 203 end 204 i = add i 1 205 end 206 ret e 207 end 208 209 note lastw: start of the last word in fb[p..e). 210 fn lastw p ulong e ulong to ulong 211 i = e 212 for a ulong `4194305` 213 if le i p 214 ret p 215 end 216 c = get fb sub i 1 217 if or eq c 32 eq c 9 218 ret i 219 end 220 i = sub i 1 221 end 222 ret i 223 end 224 225 fn wordend p ulong e ulong to ulong 226 i = p 227 for a ulong `4194305` 228 if ge i e 229 ret e 230 end 231 if eq get fb i 32 232 ret i 233 end 234 i = add i 1 235 end 236 ret e 237 end 238 239 fn nextbar p ulong e ulong to ulong 240 i = p 241 for a ulong 65537 242 if ge i e 243 ret e 244 end 245 if eq get fb i 124 246 ret i 247 end 248 i = add i 1 249 end 250 ret e 251 end 252 253 note numof: decimal 1..3 digits filling fb[p..q), else 0. 254 fn numof p ulong q ulong to ulong 255 if or ge p q gt sub q p 3 256 ret 0 257 end 258 v = ulong 0 259 for i ulong sub q p 260 c = get fb add p i 261 if or lt c 48 gt c 57 262 ret 0 263 end 264 v = add mul v 10 ulong sub c 48 265 end 266 ret v 267 end 268 269 fn isnote p ulong e ulong to bool 270 m = prefix p e 28 271 if eq m 0 272 ret false 273 end 274 q = add p m 275 if eq q e 276 ret true 277 end 278 c = get fb q 279 ret or eq c 32 eq c 9 280 end 281 282 fn regns s ulong ln ulong to ulong 283 b = get bars 0 284 if wordeq s b 12 285 ret 0 286 end 287 if wordeq s b 13 288 ret 1 289 end 290 die 3 2 ln 291 ret 2 292 end 293 294 fn regcode ln ulong to ulong 295 code = numof add get bars 0 1 get bars 1 296 if or eq code 0 gt code 255 297 die 3 2 ln 298 end 299 ret code 300 end 301 302 fn regsv ln ulong to ulong 303 p = add get bars 1 1 304 q = get bars 2 305 if wordeq p q 18 306 ret 1 307 end 308 if wordeq p q 19 309 ret 2 310 end 311 if wordeq p q 20 312 ret 3 313 end 314 die 3 2 ln 315 ret 0 316 end 317 318 note regcase: unused rows and irwasm rows carry no case; emitted and io omc rows name one. 319 fn regcase x ulong ns ulong sv ulong ln ulong to void 320 p = add get bars 2 1 321 q = get bars 3 322 if ge p q 323 die 3 2 ln 324 end 325 dash = wordeq p q 21 326 if and eq sv 3 not dash 327 die 3 2 ln 328 end 329 if and eq ns 1 not dash 330 die 3 2 ln 331 end 332 if and and eq ns 0 ne sv 3 dash 333 die 3 2 ln 334 end 335 put co x p 336 put cl x sub q p 337 end 338 339 fn regrow s ulong e ulong ln ulong to void 340 p = s 341 for i ulong 4 342 q = nextbar p e 343 if ge q e 344 die 3 2 ln 345 end 346 put bars i q 347 p = add q 1 348 end 349 if lt nextbar p e e 350 die 3 2 ln 351 end 352 if ge p e 353 die 3 2 ln 354 end 355 ns = regns s ln 356 code = regcode ln 357 x = add mul ns 256 code 358 if ne get st x 0 359 die 4 ns code 360 end 361 sv = regsv ln 362 regcase x ns sv ln 363 put st x sv 364 put mo x p 365 put ml x sub e p 366 end 367 368 fn regparse n ulong to ulong 369 s = ulong 0 370 ln = ulong 0 371 rows = ulong 0 372 for a ulong 65537 373 if ge s n 374 break 375 end 376 e = eol s n 377 ln = add ln 1 378 if gt e s 379 if not isnote s e 380 regrow s e ln 381 rows = add rows 1 382 end 383 end 384 s = add e 1 385 end 386 ret rows 387 end 388 389 note siteof: the code a source line emits. omc: fail, nfail or unkfail N as the whole line, lenval N 390 note at the end of a line, exit int N (N not 0). irwasm: refuse N as the whole line. Note lines never. 391 fn siteof s ulong e ulong ns ulong to ulong 392 p = skipws s e 393 if ge p e 394 ret 0 395 end 396 if isnote p e 397 ret 0 398 end 399 lw = lastw p e 400 if le lw p 401 ret 0 402 end 403 code = numof lw e 404 if or eq code 0 gt code 255 405 ret 0 406 end 407 pe = sub lw 1 408 pw = lastw p pe 409 if eq ns 1 410 if and eq pw p wordeq p pe 26 411 ret code 412 end 413 ret 0 414 end 415 if eq pw p 416 if or or wordeq p pe 22 wordeq p pe 23 wordeq p pe 24 417 ret code 418 end 419 end 420 if wordeq pw pe 25 421 ret code 422 end 423 if wordeq p pe 27 424 ret code 425 end 426 ret 0 427 end 428 429 fn scanln n ulong ns ulong to ulong 430 s = ulong 0 431 t = ulong 0 432 for a ulong `4194305` 433 if ge s n 434 break 435 end 436 e = eol s n 437 c = siteof s e ns 438 if ne c 0 439 x = add mul ns 256 c 440 put sc x add get sc x 1 441 t = add t 1 442 end 443 s = add e 1 444 end 445 ret t 446 end 447 448 fn sitechk to void 449 for x ulong 512 450 v = get st x 451 used = or eq v 1 eq v 2 452 if and gt get sc x 0 not used 453 die 5 div x 256 rem x 256 454 end 455 if and used eq get sc x 0 456 die 6 div x 256 rem x 256 457 end 458 end 459 end 460 461 fn docrow s ulong e ulong ln ulong to ulong 462 ns = ulong 0 463 m = prefix s e 29 464 if eq m 0 465 ns = 1 466 m = prefix s e 30 467 end 468 if eq m 0 469 ret 0 470 end 471 p = add s m 472 q = wordend p e 473 code = numof p q 474 if or eq code 0 gt code 255 475 die 11 2 ln 476 end 477 r = prefix q e 31 478 if eq r 0 479 die 11 2 ln 480 end 481 mb = add q r 482 if lt e add mb 2 483 die 11 2 ln 484 end 485 me = sub e 2 486 if ne prefix me e 32 2 487 die 11 2 ln 488 end 489 x = add mul ns 256 code 490 put dh x add get dh x 1 491 if eq get st x 0 492 die 7 ns code 493 end 494 if not sameat get mo x get ml x mb me 495 die 7 ns code 496 end 497 ret 1 498 end 499 500 fn docscan n ulong to ulong 501 s = ulong 0 502 ln = ulong 0 503 t = ulong 0 504 for a ulong `4194305` 505 if ge s n 506 break 507 end 508 e = eol s n 509 ln = add ln 1 510 t = add t docrow s e ln 511 s = add e 1 512 end 513 ret t 514 end 515 516 fn docchk to void 517 for x ulong 512 518 if and ne get st x 0 ne get dh x 1 519 die 8 div x 256 rem x 256 520 end 521 end 522 end 523 524 fn ranrow s ulong e ulong to void 525 lw = lastw s e 526 code = numof lw e 527 if or eq code 0 gt code 255 528 die 9 3 0 529 end 530 v = get st code 531 if and ne v 1 ne v 2 532 die 9 0 code 533 end 534 if le lw s 535 die 9 0 code 536 end 537 if sameat get co code get cl code s sub lw 1 538 put rh code 1 539 end 540 end 541 542 fn ranscan n ulong to ulong 543 s = ulong 0 544 t = ulong 0 545 for a ulong `4194305` 546 if ge s n 547 break 548 end 549 e = eol s n 550 if gt e s 551 ranrow s e 552 t = add t 1 553 end 554 s = add e 1 555 end 556 ret t 557 end 558 559 fn ranchk to void 560 for x ulong 256 561 v = get st x 562 if and or eq v 1 eq v 2 eq get rh x 0 563 die 10 0 x 564 end 565 end 566 end 567 568 fn main to int 569 if ne argcnt 6 570 die 1 3 0 571 end 572 n = load 1 65536 573 rows = regparse n 574 for i ulong n 575 put rg i get fb i 576 end 577 n = load 2 `4194304` 578 s0 = scanln n 0 579 n = load 4 `4194304` 580 s1 = scanln n 1 581 sitechk 582 n = load 3 `4194304` 583 d = docscan n 584 docchk 585 n = load 5 `4194304` 586 c = ranscan n 587 ranchk 588 ob_s 14 589 ob_n rows 590 ob_s 15 591 ob_n add s0 s1 592 ob_s 16 593 ob_n d 594 ob_s 17 595 ob_n c 596 ob_b 10 597 ob_out 1 598 ret 0 599 end