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/aienos.com/blob/main/om/site/json.om # aienos.com Source of www.aienos.com, served from my own hardware Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aienos.com / om / site / json.om` 698 lines ยท 14874 bytes Raw Blame History 1 note Strict JSON DOM for site source data. No float conversion: numbers retain input spelling. 2 note sj_load replaces all nodes; only render/copy values before the next load. Node 0 is missing. 3 note Kinds: object 1, array 2, string 3, number 4, true 5, false 6, null 7. 4 note Object children are value nodes carrying decoded keys; arrays carry no key. Duplicate keys 5 note remain in source order; sj_find selects the last occurrence, matching serde_json source behavior. 6 note sj_first/sj_next/sj_len iterate immediate children, never keys or descendants. 7 note sj_emit emits escaped decoded strings, lexical numbers or canonical literals, not containers. 8 note sj_href is string-only. sj_string copies decoded bytes without a terminator, refusing short dst. 9 note sj_size/byte/slice/prefix/same operate on strings; sj_key escapes an object member key. 10 note sj_kind/first/next/len accept missing 0 as empty; sj_eq/prefix return false on missing/non-string. 11 note Other string/emission APIs refuse missing/wrong kind. sj_find returns 0 for a missing parent. 12 note Capacity decision at baseline `3d36bd7`: wc -c measured facts 5128, agent-repos 22213, 13 note project-progress 30538, cudaplusplus 11108, machines 13530, models 1900, omega 21057, 14 note research_status 37411 bytes. Input and decoded pools each `4194304` bytes (dist/now.json, which 15 note the verifier reads back, measured `1412937` bytes at 2026-11-06); 65535 live nodes (now.json 14468); 16 note nesting at most 128. Each limit is a named refusal, never truncation. No external runtime. 17 note UTF-8 validator adapts om/hive-render/render.om utf8; string grammar is general RFC 8259. 18 note WolframLanguageEvaluator: {0xd800,0xdbff,0xdc00,0xdfff,0x10ffff} expressed using 19 note FromDigits[...,16] returned {55296,56319,56320,57343,`1114111`}; 2^10=1024,2^16=65536. 20 note Evaluator: (55357-55296)*1024+(56832-56320)+65536 -> 128512; 21 note ToCharacterCode[FromCharacterCode[128512],"UTF8"] -> {240,159,152,128}. 22 note Integration cases/instructions (NOT_RUN): compose om2 + runtime + json + test main; compile 23 note with the owner's pinned OM-2 compiler only after all lanes land. Run each refusal in a fresh 24 note process and assert status 70, named stderr, no successful sj_load return. Capture bytes, not floats. 25 note Accept: whitespace around {"s":"<&\"'\\\/\b\f\n\r\t\u0000\u00E9\uD83D\uDE00","n":-0.123E+004,"a":[true,false,null,[],{}]}. 26 note Assert sj_string preserves NUL and UTF-8; sj_emit escapes markup and keeps -0.123E+004 exactly. 27 note Accept numeric roots 0,-0,1,1.0,1e0,1E-`999999999999999999999`; last duplicate key wins. 28 note Accept unescaped non-ASCII including Chinese and emoji; equivalent escaped/raw keys compare equal. 29 note Refuse: empty input, BOM, trailing bytes, two roots, NaN, Infinity, +1, 01, -01, 1., .1, 30 note 1e, 1e+, -, tru, nullx, [1,], {"a":1,}, missing colon/comma, raw string control, unknown escape, 31 note lone high/low surrogate, high followed by non-low, truncated escape, overlong UTF-8, surrogate 32 note UTF-8, invalid continuation, truncated sequence and values above U+10FFFF. Test every byte cutoff. 33 note Boundary cases: exactly `4194304` bytes valid with padding accepted; one more refused JSON_CAPACITY; 34 note 65535 total nodes accepted when byte cap permits, next refused JSON_NODES; depth 128 accepted, 35 note depth 129 refused JSON_DEPTH. Check missing/invalid indices and short sj_string destination. 36 note Load every current registry/data JSON afresh. Negative control: change expected escaped bytes, 37 note require test failure. Partial read fixture must deliver input in pieces, not only regular files. 38 text sjesyn "JSON_SYNTAX" 39 text sjeutf "JSON_UTF8" 40 text sjeun "JSON_UNICODE" 41 text sjecap "JSON_CAPACITY" 42 text sjenod "JSON_NODES" 43 text sjedep "JSON_DEPTH" 44 text sjeknd "JSON_KIND" 45 text sjeidx "JSON_INDEX" 46 text sjeio "JSON_READ" 47 text sjetrue "true" 48 text sjefalse "false" 49 text sjenull "null" 50 global sjin uchar `4194304` 51 global sjdec uchar `4194304` 52 global sjst ulong 4 53 global sjtyp uchar 65536 54 global sjoff uint 65536 55 global sjcnt uint 65536 56 global sjko uint 65536 57 global sjkl uint 65536 58 global sjhas uchar 65536 59 global sjfst uint 65536 60 global sjnxt uint 65536 61 global sjnum uint 65536 62 note sjst: cursor, input length, decoded length, next free node (starts at 1). 63 fn sj_peek to uchar 64 if ge get sjst 0 get sjst 1 65 ret 0 66 end 67 ret get sjin get sjst 0 68 end 69 fn sj_take c uchar to void 70 if ge get sjst 0 get sjst 1 71 sr_fail sjesyn 72 end 73 if ne sj_peek c 74 sr_fail sjesyn 75 end 76 put sjst 0 add get sjst 0 1 77 end 78 fn sj_ws to void 79 while lt get sjst 0 get sjst 1 bound 262144 80 c = sj_peek 81 if not or or eq c 32 eq c 9 or eq c 10 eq c 13 82 ret 83 end 84 put sjst 0 add get sjst 0 1 85 end 86 end 87 fn sj_decbyte c uchar to void 88 if ge get sjst 2 len sjdec 89 sr_fail sjecap 90 end 91 put sjdec get sjst 2 c 92 put sjst 2 add get sjst 2 1 93 end 94 fn sj_codepoint cp ulong to void 95 if or gt cp `1114111` and ge cp 55296 le cp 57343 96 sr_fail sjeun 97 end 98 if lt cp 128 99 sj_decbyte uchar cp 100 ret 101 end 102 if lt cp 2048 103 sj_decbyte uchar or ulong 192 shr cp 6 104 else 105 if lt cp 65536 106 sj_decbyte uchar or ulong 224 shr cp 12 107 else 108 sj_decbyte uchar or ulong 240 shr cp 18 109 sj_decbyte uchar or ulong 128 and shr cp 12 63 110 end 111 sj_decbyte uchar or ulong 128 and shr cp 6 63 112 end 113 sj_decbyte uchar or ulong 128 and cp 63 114 end 115 fn sj_hex4 to ulong 116 v = ulong 0 117 for j ulong 4 118 c = sj_peek 119 if and ge c 48 le c 57 120 v = add mul v 16 ulong sub c 48 121 else 122 if and ge c 65 le c 70 123 v = add mul v 16 add ulong sub c 65 10 124 else 125 if and ge c 97 le c 102 126 v = add mul v 16 add ulong sub c 97 10 127 else 128 sr_fail sjeun 129 end 130 end 131 end 132 put sjst 0 add get sjst 0 1 133 end 134 ret v 135 end 136 fn sj_unicode to void 137 cp = sj_hex4 138 if and ge cp 55296 le cp 56319 139 sj_take 92 140 sj_take 117 141 low = sj_hex4 142 if or lt low 56320 gt low 57343 143 sr_fail sjeun 144 end 145 cp = add add mul sub cp 55296 1024 sub low 56320 65536 146 end 147 sj_codepoint cp 148 end 149 fn sj_escape to void 150 c = sj_peek 151 if eq c 0 152 sr_fail sjesyn 153 end 154 put sjst 0 add get sjst 0 1 155 if eq c 117 156 sj_unicode 157 ret 158 end 159 if or or eq c 34 eq c 92 eq c 47 160 sj_decbyte c 161 ret 162 end 163 if eq c 98 164 sj_decbyte 8 165 ret 166 end 167 if eq c 102 168 sj_decbyte 12 169 ret 170 end 171 if eq c 110 172 sj_decbyte 10 173 ret 174 end 175 if eq c 114 176 sj_decbyte 13 177 ret 178 end 179 if eq c 116 180 sj_decbyte 9 181 ret 182 end 183 sr_fail sjesyn 184 end 185 fn sj_utf8 lead uchar to void 186 need = ulong 0 187 cp = ulong 0 188 low = ulong 0 189 if and ge lead 194 le lead 223 190 need = 1 191 cp = ulong and lead 31 192 low = 128 193 else 194 if and ge lead 224 le lead 239 195 need = 2 196 cp = ulong and lead 15 197 low = 2048 198 else 199 if and ge lead 240 le lead 244 200 need = 3 201 cp = ulong and lead 7 202 low = 65536 203 else 204 sr_fail sjeutf 205 end 206 end 207 end 208 for j ulong need 209 c = sj_peek 210 if or lt c 128 gt c 191 211 sr_fail sjeutf 212 end 213 cp = add mul cp 64 ulong and c 63 214 put sjst 0 add get sjst 0 1 215 end 216 if or lt cp low gt cp `1114111` 217 sr_fail sjeutf 218 end 219 if and ge cp 55296 le cp 57343 220 sr_fail sjeutf 221 end 222 sj_codepoint cp 223 end 224 fn sj_parse_string to ulong 225 sj_take 34 226 start = get sjst 2 227 while lt get sjst 0 get sjst 1 bound 262144 228 c = sj_peek 229 put sjst 0 add get sjst 0 1 230 if eq c 34 231 ret start 232 end 233 if lt c 32 234 sr_fail sjesyn 235 end 236 if eq c 92 237 sj_escape 238 else 239 if ge c 128 240 sj_utf8 c 241 else 242 sj_decbyte c 243 end 244 end 245 end 246 sr_fail sjesyn 247 ret 0 248 end 249 fn sj_digit to bool 250 c = sj_peek 251 ret and ge c 48 le c 57 252 end 253 fn sj_digits to void 254 if not sj_digit 255 sr_fail sjesyn 256 end 257 while sj_digit bound 262144 258 put sjst 0 add get sjst 0 1 259 end 260 end 261 fn sj_number node ulong to void 262 put sjtyp node 4 263 put sjoff node uint get sjst 0 264 if eq sj_peek 45 265 sj_take 45 266 end 267 if eq sj_peek 48 268 sj_take 48 269 else 270 sj_digits 271 end 272 if eq sj_peek 46 273 sj_take 46 274 sj_digits 275 end 276 if or eq sj_peek 101 eq sj_peek 69 277 put sjst 0 add get sjst 0 1 278 if or eq sj_peek 43 eq sj_peek 45 279 put sjst 0 add get sjst 0 1 280 end 281 sj_digits 282 end 283 put sjcnt node uint sub get sjst 0 ulong get sjoff node 284 end 285 fn sj_literal s view uchar * to void 286 for j ulong len s 287 sj_take get s j 288 end 289 end 290 fn sj_alloc to ulong 291 node = get sjst 3 292 if ge node len sjtyp 293 sr_fail sjenod 294 end 295 put sjst 3 add node 1 296 put sjtyp node 0 297 put sjoff node 0 298 put sjcnt node 0 299 put sjko node 0 300 put sjkl node 0 301 put sjhas node 0 302 put sjfst node 0 303 put sjnxt node 0 304 put sjnum node 0 305 ret node 306 end 307 fn sj_append parent ulong prev ulong child ulong to void 308 if eq prev 0 309 put sjfst parent uint child 310 else 311 put sjnxt prev uint child 312 end 313 put sjnum parent add get sjnum parent 1 314 end 315 fn sj_array node ulong depth ulong to void 316 put sjtyp node 2 317 sj_take 91 318 sj_ws 319 if eq sj_peek 93 320 sj_take 93 321 ret 322 end 323 prev = ulong 0 324 while true bound 65536 325 child = sj_value add depth 1 326 sj_append node prev child 327 prev = child 328 sj_ws 329 if eq sj_peek 93 330 sj_take 93 331 ret 332 end 333 sj_take 44 334 sj_ws 335 end 336 end 337 fn sj_object node ulong depth ulong to void 338 put sjtyp node 1 339 sj_take 123 340 sj_ws 341 if eq sj_peek 125 342 sj_take 125 343 ret 344 end 345 prev = ulong 0 346 while true bound 65536 347 start = sj_parse_string 348 cnt = sub get sjst 2 start 349 sj_ws 350 sj_take 58 351 child = sj_value add depth 1 352 put sjko child uint start 353 put sjkl child uint cnt 354 put sjhas child 1 355 sj_append node prev child 356 prev = child 357 sj_ws 358 if eq sj_peek 125 359 sj_take 125 360 ret 361 end 362 sj_take 44 363 sj_ws 364 end 365 end 366 fn sj_value depth ulong to ulong 367 if gt depth 128 368 sr_fail sjedep 369 end 370 sj_ws 371 node = sj_alloc 372 c = sj_peek 373 if eq c 123 374 sj_object node depth 375 ret node 376 end 377 if eq c 91 378 sj_array node depth 379 ret node 380 end 381 if eq c 34 382 start = sj_parse_string 383 put sjtyp node 3 384 put sjoff node uint start 385 put sjcnt node uint sub get sjst 2 start 386 ret node 387 end 388 if eq c 116 389 sj_literal sjetrue 390 put sjtyp node 5 391 ret node 392 end 393 if eq c 102 394 sj_literal sjefalse 395 put sjtyp node 6 396 ret node 397 end 398 if eq c 110 399 sj_literal sjenull 400 put sjtyp node 7 401 ret node 402 end 403 if or eq c 45 sj_digit 404 sj_number node 405 ret node 406 end 407 sr_fail sjesyn 408 ret 0 409 end 410 fn sj_read fd int to void 411 probe = new uchar 1 0 412 put sjst 1 0 413 while lt get sjst 1 len sjin bound 262144 414 k = read fd sjin get sjst 1 sub len sjin get sjst 1 415 if lt k 0 416 sr_fail sjeio 417 end 418 if eq k 0 419 ret 420 end 421 put sjst 1 add get sjst 1 ulong k 422 end 423 k = read fd probe 0 1 424 if lt k 0 425 sr_fail sjeio 426 end 427 if ne k 0 428 sr_fail sjecap 429 end 430 end 431 fn sj_parse to ulong 432 put sjst 0 0 433 put sjst 2 0 434 put sjst 3 1 435 root = sj_value 0 436 sj_ws 437 if ne get sjst 0 get sjst 1 438 sr_fail sjesyn 439 end 440 ret root 441 end 442 fn sj_load path view uchar * to ulong 443 sr_path path 444 fd = fopen path 0 len path 0 0 445 if lt fd 0 446 sr_fail sjeio 447 end 448 sj_read int fd 449 sr_fclose int fd 450 ret sj_parse 451 end 452 note sj_loadat parses exactly cnt bytes starting at off; outside-file ranges fail JSON_READ. 453 note Bytes before/after the slice are not JSON input. cnt shares the normal JSON_CAPACITY bound. 454 note Integration cases NOT_RUN: prefix+valid JSON+suffix exact slice succeeds; include suffix fails; 455 note short file, unseekable file, empty slice and oversized slice refuse; fragmented reads succeed. 456 fn sj_loadat path view uchar * off ulong cnt ulong to ulong 457 sr_path path 458 if or gt cnt len sjin gt off `9223372036854775807` 459 sr_fail sjecap 460 end 461 fd = fopen path 0 len path 0 0 462 if lt fd 0 463 sr_fail sjeio 464 end 465 k = fseek int fd long off 0 466 if ne k long off 467 sr_fail sjeio 468 end 469 put sjst 1 0 470 while lt get sjst 1 cnt bound 262144 471 k = read int fd sjin get sjst 1 sub cnt get sjst 1 472 if le k 0 473 sr_fail sjeio 474 end 475 put sjst 1 add get sjst 1 ulong k 476 end 477 sr_fclose int fd 478 ret sj_parse 479 end 480 note sj_numsize/numbyte expose kind4 lexical bytes; no conversion or rounding occurs. 481 note Integration cases NOT_RUN: -0.123E+004 byte comparison, wrong kind and past-end refusal. 482 fn sj_numsize node ulong to ulong 483 sj_check node 484 if ne get sjtyp node 4 485 sr_fail sjeknd 486 end 487 ret ulong get sjcnt node 488 end 489 fn sj_numbyte node ulong index ulong to uchar 490 cnt = sj_numsize node 491 if ge index cnt 492 sr_fail sjeidx 493 end 494 ret get sjin add ulong get sjoff node index 495 end 496 note sj_keyis compares the decoded member key; array items/root/missing return false. 497 note Integration cases NOT_RUN: escaped equivalent key true; root/array item/other key false. 498 fn sj_keyis node ulong key view uchar * to bool 499 if eq node 0 500 ret false 501 end 502 sj_check node 503 if eq get sjhas node 0 504 ret false 505 end 506 ret sj_dec_equal ulong get sjko node ulong get sjkl node key 507 end 508 fn sj_check node ulong to void 509 if or eq node 0 ge node get sjst 3 510 sr_fail sjeidx 511 end 512 end 513 fn sj_kind node ulong to uchar 514 if eq node 0 515 ret 0 516 end 517 sj_check node 518 ret get sjtyp node 519 end 520 fn sj_first node ulong to ulong 521 if eq node 0 522 ret 0 523 end 524 sj_check node 525 ret ulong get sjfst node 526 end 527 fn sj_next node ulong to ulong 528 if eq node 0 529 ret 0 530 end 531 sj_check node 532 ret ulong get sjnxt node 533 end 534 fn sj_len node ulong to ulong 535 if eq node 0 536 ret 0 537 end 538 sj_check node 539 ret ulong get sjnum node 540 end 541 fn sj_string_check node ulong to void 542 sj_check node 543 if ne get sjtyp node 3 544 sr_fail sjeknd 545 end 546 end 547 fn sj_dec_equal off ulong cnt ulong s view uchar * to bool 548 if ne cnt len s 549 ret false 550 end 551 for j ulong cnt 552 if ne get sjdec add off j get s j 553 ret false 554 end 555 end 556 ret true 557 end 558 fn sj_find node ulong key view uchar * to ulong 559 if eq node 0 560 ret 0 561 end 562 sj_check node 563 if ne get sjtyp node 1 564 sr_fail sjeknd 565 end 566 child = sj_first node 567 found = ulong 0 568 while ne child 0 bound 65536 569 if sj_dec_equal ulong get sjko child ulong get sjkl child key 570 found = child 571 end 572 child = sj_next child 573 end 574 ret found 575 end 576 fn sj_eq node ulong s view uchar * to bool 577 if eq node 0 578 ret false 579 end 580 sj_check node 581 if ne get sjtyp node 3 582 ret false 583 end 584 ret sj_dec_equal ulong get sjoff node ulong get sjcnt node s 585 end 586 fn sj_size node ulong to ulong 587 sj_string_check node 588 ret ulong get sjcnt node 589 end 590 fn sj_byte node ulong index ulong to uchar 591 sj_string_check node 592 if ge index ulong get sjcnt node 593 sr_fail sjeidx 594 end 595 ret get sjdec add ulong get sjoff node index 596 end 597 fn sj_string node ulong dst edit uchar * to ulong 598 cnt = sj_size node 599 if gt cnt len dst 600 sr_fail sjecap 601 end 602 for j ulong cnt 603 put dst j get sjdec add ulong get sjoff node j 604 end 605 ret cnt 606 end 607 fn sj_prefix node ulong s view uchar * to bool 608 if eq node 0 609 ret false 610 end 611 sj_check node 612 if ne get sjtyp node 3 613 ret false 614 end 615 if gt len s ulong get sjcnt node 616 ret false 617 end 618 for j ulong len s 619 if ne get s j get sjdec add ulong get sjoff node j 620 ret false 621 end 622 end 623 ret true 624 end 625 fn sj_same a ulong b ulong to bool 626 sj_string_check a 627 sj_string_check b 628 cnt = get sjcnt a 629 if ne cnt get sjcnt b 630 ret false 631 end 632 a = ulong get sjoff a 633 b = ulong get sjoff b 634 for j ulong ulong cnt 635 x = get sjdec add a j 636 y = get sjdec add b j 637 if ne x y 638 ret false 639 end 640 end 641 ret true 642 end 643 fn sj_dec_emit off ulong cnt ulong to void 644 for j ulong cnt 645 jc8 = get sjdec add off j 646 jd8 = jc8 647 if lt add j 1 cnt 648 jd8 = get sjdec add add off j 1 649 end 650 sr_escref jc8 jd8 651 end 652 end 653 fn sj_slice node ulong start ulong to void 654 cnt = sj_size node 655 if gt start cnt 656 sr_fail sjeidx 657 end 658 sj_dec_emit add ulong get sjoff node start sub cnt start 659 end 660 fn sj_key node ulong to void 661 sj_check node 662 if eq get sjhas node 0 663 sr_fail sjeknd 664 end 665 sj_dec_emit ulong get sjko node ulong get sjkl node 666 end 667 fn sj_emit node ulong to void 668 kind = sj_kind node 669 if eq kind 3 670 sj_dec_emit ulong get sjoff node ulong get sjcnt node 671 ret 672 end 673 if eq kind 4 674 for j ulong ulong get sjcnt node 675 sr_byte get sjin add ulong get sjoff node j 676 end 677 ret 678 end 679 if eq kind 5 680 sr_raw sjetrue 681 ret 682 end 683 if eq kind 6 684 sr_raw sjefalse 685 ret 686 end 687 if eq kind 7 688 sr_raw sjenull 689 ret 690 end 691 sr_fail sjeknd 692 end 693 fn sj_href node ulong to void 694 sj_string_check node 695 buf = new uchar 4096 0 696 n = sj_string node buf 697 gh_url part buf 0 n 698 end