interplane.Get Omega
Read in your language

aienos.com

Source of www.aienos.com, served from my own hardware

Brought by drakestapleton

branch main Branches Tags History

aienos.com / om / site / json.om

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