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 / board / src / 10-scan.om
| 1 | note synapse-board src/10-scan.om -- validate the three JSONL inputs and index what render needs. |
| 2 | note gcnt: 0 active 1 lapsed 2 inactive 3 repos-with-claims 4 conflicts 5 error 6 warn 7 info |
| 3 | note 8 map repos 9 inferred parents 10 findings (not conflicts) 11 claims seen |
| 4 | const SBMAXC ulong 65536 |
| 5 | const SBMAXM ulong 4096 |
| 6 | global gcnt ulong 16 |
| 7 | global gpool uchar 8388608 |
| 8 | global gpl ulong 1 |
| 9 | global gcoff ulong 65536 |
| 10 | global gtoff ulong 65536 |
| 11 | global gtln ulong 65536 |
| 12 | global gkoff ulong 65536 |
| 13 | global gkln ulong 65536 |
| 14 | global gkrk ulong 65536 |
| 15 | global glap ulong 65536 |
| 16 | global gord ulong 65536 |
| 17 | global gnc ulong 1 |
| 18 | global gmoff ulong 4096 |
| 19 | global gmno ulong 4096 |
| 20 | global gmnl ulong 4096 |
| 21 | global gmpo ulong 4096 |
| 22 | global gmpl ulong 4096 |
| 23 | global gmst ulong 4096 |
| 24 | global gmpar ulong 4096 |
| 25 | global gmvis ulong 4096 |
| 26 | global gnm ulong 1 |
| 27 | global gstk ulong 4096 |
| 28 | global gsdp ulong 4096 |
| 29 | text tfc "claims" |
| 30 | text tfm "map" |
| 31 | text tff "findings" |
| 32 | text kid "id" |
| 33 | text kagent "agent" |
| 34 | text ksess "session" |
| 35 | text ktgt "target" |
| 36 | text kmode "mode" |
| 37 | text kstate "state" |
| 38 | text kint "intent" |
| 39 | text kexp "expires" |
| 40 | text kact "active" |
| 41 | text kev "evidence" |
| 42 | text kkind "kind" |
| 43 | text ksev "severity" |
| 44 | text krepo "repo" |
| 45 | text kpr "pr" |
| 46 | text kpath "path" |
| 47 | text kdet "detail" |
| 48 | text koid "other_id" |
| 49 | text koag "other_agent" |
| 50 | text kpar "parent" |
| 51 | text kpst "parent_status" |
| 52 | text kpurp "purpose" |
| 53 | text karch "archived" |
| 54 | text kfork "fork" |
| 55 | text krule "infer_rule" |
| 56 | text vconf "conflict" |
| 57 | text verr "error" |
| 58 | text vwarn "warn" |
| 59 | text vinfo "info" |
| 60 | text vext "ext" |
| 61 | text vcnf "CONFIRMED" |
| 62 | text vinf "INFERRED" |
| 63 | text vroot "ROOT" |
| 64 | text vnone "NONE" |
| 65 | text emjs "malformed JSON object line" |
| 66 | text emlong "line longer than 65536 bytes" |
| 67 | text emid "claim needs string id and target" |
| 68 | text emrepo "map record needs string repo" |
| 69 | text emkind "finding needs string kind" |
| 70 | text emmany "too many records" |
| 71 | text empool "string pool full" |
| 72 | note sberr: "synapse-board: FILE:LINE: msg" on stderr; returns 65 |
| 73 | fn sberr w ulong ln ulong msg view uchar * to long |
| 74 | d = new uchar 24 0 |
| 75 | i = ulong 24 |
| 76 | x = ln |
| 77 | for it ulong 20 |
| 78 | i = sub i 1 |
| 79 | put d i uchar add rem x 10 48 |
| 80 | x = div x 10 |
| 81 | if eq x 0 |
| 82 | break |
| 83 | end |
| 84 | end |
| 85 | r = write 2 tme 0 len tme |
| 86 | if eq w 0 |
| 87 | r = write 2 tfc 0 len tfc |
| 88 | end |
| 89 | if eq w 1 |
| 90 | r = write 2 tfm 0 len tfm |
| 91 | end |
| 92 | if eq w 2 |
| 93 | r = write 2 tff 0 len tff |
| 94 | end |
| 95 | put d sub i 1 58 |
| 96 | r = write 2 d sub i 1 add sub 24 i 1 |
| 97 | put d 0 58 |
| 98 | put d 1 32 |
| 99 | r = write 2 d 0 2 |
| 100 | r = write 2 msg 0 len msg |
| 101 | r = write 2 tnl 0 len tnl |
| 102 | ret 65 |
| 103 | end |
| 104 | note sbpl: parse the line of input w at off into lb/tp; its length (0 = empty line), -1 too long, -2 malformed |
| 105 | fn sbpl w ulong off ulong lb edit uchar 65536 tp edit uint 16400 to long |
| 106 | n = sbline w off lb |
| 107 | if lt n 0 |
| 108 | ret -1 |
| 109 | end |
| 110 | if eq n 0 |
| 111 | ret 0 |
| 112 | end |
| 113 | r = js_init tp 65536 64 |
| 114 | r = js_parse lb tp ulong n |
| 115 | if lt r 0 |
| 116 | ret -2 |
| 117 | end |
| 118 | if ne js_type tp 0 jsobj |
| 119 | ret -2 |
| 120 | end |
| 121 | ret n |
| 122 | end |
| 123 | note sbpool: append sb[0..n) to the pool; its offset, or SBOCAP when the pool is full |
| 124 | fn sbpool sb view uchar 65536 n ulong to ulong |
| 125 | p = get gpl 0 |
| 126 | if gt add p n SBOCAP |
| 127 | ret SBOCAP |
| 128 | end |
| 129 | for i ulong n |
| 130 | put gpool add p i get sb i |
| 131 | end |
| 132 | put gpl 0 add p n |
| 133 | ret p |
| 134 | end |
| 135 | fn sbeqv sb view uchar 65536 n long t view uchar * to bool |
| 136 | if lt n 0 |
| 137 | ret false |
| 138 | end |
| 139 | if ne ulong n len t |
| 140 | ret false |
| 141 | end |
| 142 | for i ulong len t |
| 143 | if ne get sb i get t i |
| 144 | ret false |
| 145 | end |
| 146 | end |
| 147 | ret true |
| 148 | end |
| 149 | fn sbinc i ulong to void |
| 150 | put gcnt i add get gcnt i 1 |
| 151 | end |
| 152 | note sbtsless: whether string sb[0..n) sorts before the now timestamp (byte order) |
| 153 | fn sbtsless sb view uchar 65536 n ulong to bool |
| 154 | m = get gnowl 0 |
| 155 | for i ulong 64 |
| 156 | if or ge i n ge i m |
| 157 | ret lt n m |
| 158 | end |
| 159 | a = get sb i |
| 160 | b = get gnow i |
| 161 | if ne a b |
| 162 | ret lt a b |
| 163 | end |
| 164 | end |
| 165 | ret false |
| 166 | end |
| 167 | note ======== findings: counts by kind conflict / severity |
| 168 | fn sbscanf to long |
| 169 | lb = new uchar 65536 0 |
| 170 | tp = new uint 16400 0 |
| 171 | sb = new uchar 65536 0 |
| 172 | tot = get glen 2 |
| 173 | off = ulong 0 |
| 174 | ln = ulong 0 |
| 175 | for it ulong SBLINES |
| 176 | if ge off tot |
| 177 | ret 0 |
| 178 | end |
| 179 | ln = add ln 1 |
| 180 | n = sbpl 2 off lb tp |
| 181 | if eq n -1 |
| 182 | ret sberr 2 ln emlong |
| 183 | end |
| 184 | if eq n -2 |
| 185 | ret sberr 2 ln emjs |
| 186 | end |
| 187 | if gt n 0 |
| 188 | k = sbgets lb tp sb kkind |
| 189 | if lt k 0 |
| 190 | ret sberr 2 ln emkind |
| 191 | end |
| 192 | if sbeqv sb k vconf |
| 193 | sbinc 4 |
| 194 | else |
| 195 | sbinc 10 |
| 196 | k = sbgets lb tp sb ksev |
| 197 | if sbeqv sb k verr |
| 198 | sbinc 5 |
| 199 | end |
| 200 | if sbeqv sb k vwarn |
| 201 | sbinc 6 |
| 202 | end |
| 203 | if sbeqv sb k vinfo |
| 204 | sbinc 7 |
| 205 | end |
| 206 | end |
| 207 | end |
| 208 | off = add add off ulong n 1 |
| 209 | end |
| 210 | ret sberr 2 ln emmany |
| 211 | end |
| 212 | note sbrkey: repo grouping key of target sb[0..n) stored at pool offset p: sets gkoff/gkln/gkrk of claim c |
| 213 | note rank 0 a repo (repo:R, branch:R#x, path:R:x, pr:R#n), 1 ext:, 2 unparsed |
| 214 | fn sbrkey sb view uchar 65536 n ulong p ulong c ulong to void |
| 215 | put gkrk c 2 |
| 216 | put gkoff c p |
| 217 | put gkln c 0 |
| 218 | q = n |
| 219 | for i ulong n |
| 220 | if eq get sb i 58 |
| 221 | q = i |
| 222 | break |
| 223 | end |
| 224 | end |
| 225 | if ge q n |
| 226 | ret |
| 227 | end |
| 228 | if and eq q 3 and eq get sb 0 101 and eq get sb 1 120 eq get sb 2 116 |
| 229 | put gkrk c 1 |
| 230 | ret |
| 231 | end |
| 232 | e = n |
| 233 | for j ulong sub n add q 1 |
| 234 | k = add add q 1 j |
| 235 | c2 = get sb k |
| 236 | if or eq c2 35 eq c2 58 |
| 237 | e = k |
| 238 | break |
| 239 | end |
| 240 | end |
| 241 | if le e add q 1 |
| 242 | ret |
| 243 | end |
| 244 | put gkrk c 0 |
| 245 | put gkoff c add add p q 1 |
| 246 | put gkln c sub e add q 1 |
| 247 | end |
| 248 | note ======== claims: active claims indexed; inactive counted |
| 249 | fn sbscanc to long |
| 250 | lb = new uchar 65536 0 |
| 251 | tp = new uint 16400 0 |
| 252 | sb = new uchar 65536 0 |
| 253 | tot = get glen 0 |
| 254 | off = ulong 0 |
| 255 | ln = ulong 0 |
| 256 | for it ulong SBLINES |
| 257 | if ge off tot |
| 258 | ret 0 |
| 259 | end |
| 260 | ln = add ln 1 |
| 261 | n = sbpl 0 off lb tp |
| 262 | if eq n -1 |
| 263 | ret sberr 0 ln emlong |
| 264 | end |
| 265 | if eq n -2 |
| 266 | ret sberr 0 ln emjs |
| 267 | end |
| 268 | if gt n 0 |
| 269 | k = sbgets lb tp sb kid |
| 270 | t = sbgets lb tp sb ktgt |
| 271 | if or le k 0 le t 0 |
| 272 | ret sberr 0 ln emid |
| 273 | end |
| 274 | sbinc 11 |
| 275 | if sbgetb lb tp kact |
| 276 | c = get gnc 0 |
| 277 | if ge c SBMAXC |
| 278 | ret sberr 0 ln emmany |
| 279 | end |
| 280 | p = sbpool sb ulong t |
| 281 | if eq p SBOCAP |
| 282 | ret sberr 0 ln empool |
| 283 | end |
| 284 | put gcoff c off |
| 285 | put gtoff c p |
| 286 | put gtln c ulong t |
| 287 | sbrkey sb ulong t p c |
| 288 | put glap c 0 |
| 289 | sbinc 0 |
| 290 | e = sbgets lb tp sb kexp |
| 291 | if gt e 0 |
| 292 | if sbtsless sb ulong e |
| 293 | put glap c 1 |
| 294 | sbinc 1 |
| 295 | end |
| 296 | end |
| 297 | put gord c c |
| 298 | put gnc 0 add c 1 |
| 299 | else |
| 300 | sbinc 2 |
| 301 | end |
| 302 | end |
| 303 | off = add add off ulong n 1 |
| 304 | end |
| 305 | ret sberr 0 ln emmany |
| 306 | end |
| 307 | note sbkcmp: claim a sorts before claim b (rank, repo key bytes, file order) |
| 308 | fn sbkcmp a ulong b ulong to bool |
| 309 | ra = get gkrk a |
| 310 | rb = get gkrk b |
| 311 | if ne ra rb |
| 312 | ret lt ra rb |
| 313 | end |
| 314 | la = get gkln a |
| 315 | lb = get gkln b |
| 316 | oa = get gkoff a |
| 317 | ob = get gkoff b |
| 318 | for i ulong 4096 |
| 319 | if or ge i la ge i lb |
| 320 | if ne la lb |
| 321 | ret lt la lb |
| 322 | end |
| 323 | ret lt a b |
| 324 | end |
| 325 | ca = get gpool add oa i |
| 326 | cb = get gpool add ob i |
| 327 | if ne ca cb |
| 328 | ret lt ca cb |
| 329 | end |
| 330 | end |
| 331 | ret lt a b |
| 332 | end |
| 333 | fn sbkeyeq a ulong b ulong to bool |
| 334 | if ne get gkrk a get gkrk b |
| 335 | ret false |
| 336 | end |
| 337 | la = get gkln a |
| 338 | if ne la get gkln b |
| 339 | ret false |
| 340 | end |
| 341 | oa = get gkoff a |
| 342 | ob = get gkoff b |
| 343 | for i ulong la |
| 344 | if ne get gpool add oa i get gpool add ob i |
| 345 | ret false |
| 346 | end |
| 347 | end |
| 348 | ret true |
| 349 | end |
| 350 | note sbsortc: insertion sort of gord, then count distinct rank-0 repos |
| 351 | fn sbsortc to void |
| 352 | n = get gnc 0 |
| 353 | for i ulong n |
| 354 | x = get gord i |
| 355 | j = i |
| 356 | while gt j 0 bound 65536 |
| 357 | y = get gord sub j 1 |
| 358 | if sbkcmp y x |
| 359 | break |
| 360 | end |
| 361 | put gord j y |
| 362 | j = sub j 1 |
| 363 | end |
| 364 | put gord j x |
| 365 | end |
| 366 | for i2 ulong n |
| 367 | c = get gord i2 |
| 368 | if eq get gkrk c 0 |
| 369 | if eq i2 0 |
| 370 | sbinc 3 |
| 371 | else |
| 372 | if not sbkeyeq get gord sub i2 1 c |
| 373 | sbinc 3 |
| 374 | end |
| 375 | end |
| 376 | end |
| 377 | end |
| 378 | end |
| 379 | note sbpeq: pool strings equal ignoring ASCII case |
| 380 | fn sbpeq ao ulong al ulong bo ulong bl ulong to bool |
| 381 | if ne al bl |
| 382 | ret false |
| 383 | end |
| 384 | for i ulong al |
| 385 | a = get gpool add ao i |
| 386 | b = get gpool add bo i |
| 387 | if and ge a 65 le a 90 |
| 388 | a = add a 32 |
| 389 | end |
| 390 | if and ge b 65 le b 90 |
| 391 | b = add b 32 |
| 392 | end |
| 393 | if ne a b |
| 394 | ret false |
| 395 | end |
| 396 | end |
| 397 | ret true |
| 398 | end |
| 399 | note ======== map: records indexed, parents resolved within the map |
| 400 | note Parse one row separately so stream state does not occupy the row parser's registers. |
| 401 | fn sbmaprow lb view uchar 65536 tp view uint 16400 sb edit uchar 65536 off ulong ln ulong to long |
| 402 | k = sbgets lb tp sb krepo |
| 403 | if le k 0 |
| 404 | ret sberr 1 ln emrepo |
| 405 | end |
| 406 | m = get gnm 0 |
| 407 | if ge m SBMAXM |
| 408 | ret sberr 1 ln emmany |
| 409 | end |
| 410 | p = sbpool sb ulong k |
| 411 | if eq p SBOCAP |
| 412 | ret sberr 1 ln empool |
| 413 | end |
| 414 | put gmoff m off |
| 415 | put gmno m p |
| 416 | put gmnl m ulong k |
| 417 | put gmpl m 0 |
| 418 | put gmpar m jsnone |
| 419 | put gmvis m 0 |
| 420 | k = sbgets lb tp sb kpar |
| 421 | if gt k 0 |
| 422 | q = ulong k |
| 423 | for i ulong ulong k |
| 424 | if eq get sb i 64 |
| 425 | q = i |
| 426 | break |
| 427 | end |
| 428 | end |
| 429 | p = sbpool sb q |
| 430 | if eq p SBOCAP |
| 431 | ret sberr 1 ln empool |
| 432 | end |
| 433 | put gmpo m p |
| 434 | put gmpl m q |
| 435 | end |
| 436 | k = sbgets lb tp sb kpst |
| 437 | st = ulong 4 |
| 438 | if sbeqv sb k vcnf |
| 439 | st = 0 |
| 440 | end |
| 441 | if sbeqv sb k vinf |
| 442 | st = 1 |
| 443 | sbinc 9 |
| 444 | end |
| 445 | if sbeqv sb k vroot |
| 446 | st = 2 |
| 447 | end |
| 448 | if sbeqv sb k vnone |
| 449 | st = 3 |
| 450 | end |
| 451 | put gmst m st |
| 452 | sbinc 8 |
| 453 | put gnm 0 add m 1 |
| 454 | ret 0 |
| 455 | end |
| 456 | fn sbscanm to long |
| 457 | lb = new uchar 65536 0 |
| 458 | tp = new uint 16400 0 |
| 459 | sb = new uchar 65536 0 |
| 460 | tot = get glen 1 |
| 461 | off = ulong 0 |
| 462 | ln = ulong 0 |
| 463 | for it ulong SBLINES |
| 464 | if ge off tot |
| 465 | ret sbresm |
| 466 | end |
| 467 | ln = add ln 1 |
| 468 | n = sbpl 1 off lb tp |
| 469 | if eq n -1 |
| 470 | ret sberr 1 ln emlong |
| 471 | end |
| 472 | if eq n -2 |
| 473 | ret sberr 1 ln emjs |
| 474 | end |
| 475 | if gt n 0 |
| 476 | code = sbmaprow lb tp sb off ln |
| 477 | if ne code 0 |
| 478 | ret code |
| 479 | end |
| 480 | end |
| 481 | off = add add off ulong n 1 |
| 482 | end |
| 483 | ret sberr 1 ln emmany |
| 484 | end |
| 485 | fn sbresm to long |
| 486 | n = get gnm 0 |
| 487 | for i ulong n |
| 488 | pl = get gmpl i |
| 489 | if gt pl 0 |
| 490 | for j ulong n |
| 491 | if ne i j |
| 492 | if sbpeq get gmpo i pl get gmno j get gmnl j |
| 493 | put gmpar i j |
| 494 | break |
| 495 | end |
| 496 | end |
| 497 | end |
| 498 | end |
| 499 | end |
| 500 | ret 0 |
| 501 | end |