interplane.Get Omega
Read in your language

cortex

aien-dev/cortex

Brought by drakestapleton

branch main Branches Tags History

cortex / om / json.om

1983 lines · 34279 bytes Raw Blame History
1note om/json.om - JsonNum module (owner JsonNum). Seeded Omega, OM-2 unit; f64.om and uni_rust.om first.
2note Reproduces serde_json 1.0.151 (features std + raw_value; NOT float_roundtrip / arbitrary_precision /
3note preserve_order): from_slice::<Value> acceptance, error text + category, serde_path_to_error 0.1.20
4note paths, compact serializer (to_string), canonical re-serialization (objects = BTreeMap, keys by bytes,
5note last duplicate wins). Verified by tests/json/run.sh (evidence/json/run.log).
6note INPUT jin uchar 12582912: document at jin[0 .. jinl) (<= 4194304 bytes; the rest is scratch for
7note RawValue re-parses and js_canon_buf). jinl ulong 1. jes uchar 4194304 for js_canon_buf /
8note js_esc_buf. jrvm uchar 1: 0 (default) Value semantics: an object whose FIRST key is
9note "$serde_json::private::RawValue" is replaced by from_str(its string value); 1 = keep it as a
10note plain object (what a typed struct sees).
11note PARSE js_parse to bool (with end(): trailing non-whitespace = error); js_parsep to bool (prefix:
12note first value only, trailing bytes ignored - axum Json). Root -> jroot (ulong 1).
13note ERROR jem uchar 1024 / jeml: exact serde Display text "<msg> at line L column C"; jecat uchar 1:
14note 1 Eof, 2 Syntax, 3 Data (custom: RawValue cases), 9 capacity (ours, "capacity exceeded").
15note Partial tree on failure: every completed node stays valid; containers still open are
16note incomplete (js_done false); js_pend n = member being read when the error hit (an
17note incomplete container, placeholder kind 9 key read/no value, 10 value started and failed,
18note 11 next_key failed) or jnone. js_path appends the serde_path_to_error path, false if empty.
19note NODES jnone = 18446744073709551615. js_kind n -> 0 null 1 false 2 true 3 u64 4 i64 5 f64 6 string
20note 7 array 8 object (9..11 placeholders). js_len n completed members (document order,
21note duplicates kept), js_child n i, js_find obj key (view uchar *; last duplicate = BTreeMap),
22note js_key m / js_str n -> decoded bytes in jsv (uchar 12582912) / jsvl, js_num n -> u64 value,
23note i64 two's complement or f64 bits, js_spos/js_epos n -> absolute jin index of first byte /
24note after last byte, js_kend m -> index after the member key's closing quote.
25note POSITION js_line idx / js_col idx (serde position_of_index, main document); serde's invalid-type
26note position is js_epos for scalars and strings, js_spos for arrays/objects; a struct visitor's
27note own error (duplicate field, missing field) is at js_vpos idx (duplicate: js_vpos (js_kend m),
28note missing: js_epos object). js_dbg_str n appends Rust {:?} of a string node to job.
29note OUTPUT job / jobl / jobx (f64.om). js_canon n: serde_json::to_string of the subtree; js_canon_buf
30note off n: canonical text of jes[off .. off+n) (from_str), appends nothing and returns false if
31note rejected, keeps the current tree. js_esc_txt s / js_esc_buf off n: quoted escaped string.
32note Capacities: 3145728 nodes, 9437184 child slots, 12582912 pool bytes; exceeding them = category 9.
33const jncap ulong 3145728
34const jincap ulong 12582912
35const jspcap ulong 12582912
36const jclcap ulong 9437184
37const jstcap ulong 6291456
38global jin uchar 12582912
39global jinl ulong 1
40global jes uchar 4194304
41global jroot ulong 1
42global jem uchar 1024
43global jeml ulong 1
44global jecat uchar 1
45global jsv uchar 12582912
46global jsvl ulong 1
47global jrvm uchar 1
48global jnk uchar 3145728
49global jnv ulong 3145728
50global jnl uint 3145728
51global jns uint 3145728
52global jne uint 3145728
53global jnko uint 3145728
54global jnkl uint 3145728
55global jnkq uint 3145728
56global jnn ulong 1
57global jcl uint 9437184
58global jcln ulong 1
59global jst uint 6291456
60global jstn ulong 1
61global jsp uchar 12582912
62global jspn ulong 1
63global jpi ulong 1
64global jpe ulong 1
65global jpb ulong 1
66global jpd ulong 1
67global jinu ulong 1
68global jqk uchar 1
69global jqv ulong 1
70global jqo ulong 1
71global jql ulong 1
72global jqh ulong 1
73global jsav ulong 16
74global jfail uchar 1
75global jrvs uchar 1
76text jtmsg "EOF while parsing a list|EOF while parsing an object|EOF while parsing a string|EOF while parsing a value|expected `:`|expected `,` or `]`|expected `,` or `}`|expected ident|expected value|invalid escape|invalid number|number out of range|invalid unicode code point|control character (\\u0000-\\u001F) found while parsing a string|key must be a string|lone leading surrogate in hex escape|trailing comma|trailing characters|unexpected end of hex escape|recursion limit exceeded|"
77text jtatl " at line "
78text jtcol " column "
79text jtull "ull"
80text jtrue "rue"
81text jtalse "alse"
82text jtfalse "false"
83text jttrue "true"
84text jtrawk "$serde_json::private::RawValue"
85text jtinv "invalid type: "
86text jtexp ", expected raw value"
87text jtbool "boolean `"
88text jtint "integer `"
89text jtflt "floating point `"
90text jtseq "sequence"
91text jtmap "map"
92text jtcap "capacity exceeded"
93note ---- error reporting (serde_json Error Display: "<code> at line L column C") ----
94fn js_ejm c uchar to void
95n = get jeml 0
96if lt n 1024
97put jem n c
98put jeml 0 add n 1
99end
100end
101fn js_ejt s view uchar * to void
102for i ulong len s
103js_ejm get s i
104end
105end
106fn js_ejn v ulong to void
107num_u64 v
108for i ulong get jfbl 0
109js_ejm get jfb i
110end
111end
112note append " at line L column C" for absolute index idx of the current region (serde position_of_index)
113fn js_epos_txt idx ulong to void
114b = get jpb 0
115js_ejt jtatl
116js_ejn js_lnb b idx
117js_ejt jtcol
118js_ejn sub idx js_solb b idx
119end
120note serde ErrorCode text for code 1..20
121fn js_ecode c uchar to void
122k = uchar 1
123for i ulong len jtmsg
124b = get jtmsg i
125if eq b 124
126k = add k 1
127if gt k c
128ret
129end
130else
131if eq k c
132js_ejm b
133end
134end
135end
136end
137note Error::syntax(code, position_of_index(idx)); returns false
138fn js_erri c uchar idx ulong to void
139put jeml 0 0
140js_ecode c
141js_epos_txt idx
142put jecat 0 2
143if le c 4
144put jecat 0 1
145end
146put jfail 0 1
147end
148note self.error(): position of the current index
149fn js_eerr c uchar to void
150js_erri c get jpi 0
151end
152note self.peek_error(): min(len, index + 1)
153fn js_perr c uchar to void
154i = add get jpi 0 1
155if gt i get jpe 0
156i = get jpe 0
157end
158js_erri c i
159end
160fn js_ecap to void
161put jeml 0 0
162js_ejt jtcap
163put jecat 0 9
164put jfail 0 1
165end
166note ---- reader helpers ----
167note skip ' ' '\n' '\t' '\r'; returns the next byte or 256 at the end
168fn js_ws to uint
169i = get jpi 0
170e = get jpe 0
171for b ulong 4000
172for t ulong 4000
173if ge i e
174put jpi 0 i
175ret 256
176end
177c = get jin i
178if and ne c 32 and ne c 10 and ne c 9 ne c 13
179put jpi 0 i
180ret uint c
181end
182i = add i 1
183end
184end
185put jpi 0 i
186ret 256
187end
188fn js_peek to uint
189i = get jpi 0
190if ge i get jpe 0
191ret 256
192end
193ret uint get jin i
194end
195fn js_ident s view uchar * to bool
196for k ulong len s
197i = get jpi 0
198if ge i get jpe 0
199js_eerr 4
200ret false
201end
202c = get jin i
203put jpi 0 add i 1
204if ne c get s k
205js_eerr 8
206ret false
207end
208end
209ret true
210end
211note ---- numbers (serde_json 1.0.151 de.rs, default features) -> jqk (3 u64, 4 i64, 5 f64), jqv ----
212fn js_nf pos bool sig ulong ex long to bool
213if not num_parts pos sig ex
214js_eerr 12
215ret false
216end
217put jqk 0 5
218put jqv 0 get jfr 0
219ret true
220end
221note i32 saturating start +/- exp
222fn js_nexp pos bool sig ulong st long to bool
223put jpi 0 add get jpi 0 1
224pe = true
225c = js_peek
226if eq c 43
227put jpi 0 add get jpi 0 1
228else
229if eq c 45
230put jpi 0 add get jpi 0 1
231pe = false
232end
233end
234i = get jpi 0
235if ge i get jpe 0
236js_eerr 4
237ret false
238end
239c = uint get jin i
240put jpi 0 add get jpi 0 1
241if not and ge c 48 le c 57
242js_eerr 11
243ret false
244end
245ex = long sub c 48
246for b ulong 4000
247for t ulong 4000
248c = js_peek
249if not and ge c 48 le c 57
250if not pe
251ex = neg ex
252end
253ex = add st ex
254if gt ex 2147483647
255ex = 2147483647
256end
257if lt ex -2147483648
258ex = -2147483648
259end
260ret js_nf pos sig ex
261end
262put jpi 0 add get jpi 0 1
263d = long sub c 48
264if ge ex 214748364
265if or gt ex 214748364 gt d 7
266ret js_nexo pos eq sig 0 pe
267end
268end
269ex = add mul ex 10 d
270end
271end
272js_ecap
273ret false
274end
275fn js_nexo pos bool zero bool pe bool to bool
276if and not zero pe
277js_eerr 12
278ret false
279end
280for b ulong 4000
281for t ulong 4000
282c = js_peek
283if not and ge c 48 le c 57
284put jqk 0 5
285put jqv 0 0
286if not pos
287put jqv 0 9223372036854775808
288end
289ret true
290end
291put jpi 0 add get jpi 0 1
292end
293end
294js_ecap
295ret false
296end
297note serde overflow!(sig * 10 + d, u64::MAX)
298fn js_ndec pos bool sig ulong eb long to bool
299put jpi 0 add get jpi 0 1
300ea = long 0
301for b ulong 4000
302for t ulong 4000
303c = js_peek
304if not and ge c 48 le c 57
305if eq ea 0
306if eq c 256
307js_perr 4
308ret false
309end
310js_perr 11
311ret false
312end
313if or eq c 101 eq c 69
314ret js_nexp pos sig add eb ea
315end
316ret js_nf pos sig add eb ea
317end
318d = ulong sub c 48
319if ge sig 1844674407370955161
320if or gt sig 1844674407370955161 gt d 5
321ret js_ndov pos sig add eb ea
322end
323end
324put jpi 0 add get jpi 0 1
325sig = add mul sig 10 d
326ea = sub ea 1
327end
328end
329js_ecap
330ret false
331end
332fn js_ndov pos bool sig ulong ex long to bool
333for b ulong 4000
334for t ulong 4000
335c = js_peek
336if not and ge c 48 le c 57
337if or eq c 101 eq c 69
338ret js_nexp pos sig ex
339end
340ret js_nf pos sig ex
341end
342put jpi 0 add get jpi 0 1
343end
344end
345js_ecap
346ret false
347end
348fn js_nlong pos bool sig ulong to bool
349ex = long 0
350for b ulong 4000
351for t ulong 4000
352c = js_peek
353if and ge c 48 le c 57
354put jpi 0 add get jpi 0 1
355ex = add ex 1
356else
357if eq c 46
358ret js_ndec pos sig ex
359end
360if or eq c 101 eq c 69
361ret js_nexp pos sig ex
362end
363ret js_nf pos sig ex
364end
365end
366end
367js_ecap
368ret false
369end
370fn js_nnum pos bool sig ulong to bool
371c = js_peek
372if eq c 46
373ret js_ndec pos sig 0
374end
375if or eq c 101 eq c 69
376ret js_nexp pos sig 0
377end
378if pos
379put jqk 0 3
380put jqv 0 sig
381ret true
382end
383if or eq sig 0 gt sig 9223372036854775808
384put jqk 0 5
385put jqv 0 bitcast ulong neg f64 sig
386ret true
387end
388put jqk 0 4
389put jqv 0 sub 0 sig
390ret true
391end
392note parse_integer (after an optional '-' was eaten)
393fn js_nint pos bool to bool
394i = get jpi 0
395if ge i get jpe 0
396js_eerr 4
397ret false
398end
399c = uint get jin i
400put jpi 0 add get jpi 0 1
401if eq c 48
402if and ge js_peek 48 le js_peek 57
403js_perr 11
404ret false
405end
406ret js_nnum pos 0
407end
408if not and ge c 48 le c 57
409js_eerr 11
410ret false
411end
412sig = ulong sub c 48
413for b ulong 4000
414for t ulong 4000
415c = js_peek
416if not and ge c 48 le c 57
417ret js_nnum pos sig
418end
419d = ulong sub c 48
420if ge sig 1844674407370955161
421if or gt sig 1844674407370955161 gt d 5
422ret js_nlong pos sig
423end
424end
425put jpi 0 add get jpi 0 1
426sig = add mul sig 10 d
427end
428end
429js_ecap
430ret false
431end
432note ---- strings: SliceRead::parse_str (validate = true); decoded bytes appended to jsp -> jqo/jql ----
433fn js_spush c uchar to void
434n = get jspn 0
435put jsp n c
436put jspn 0 add n 1
437end
438fn js_scp v uint to void
439if lt v 128
440js_spush uchar v
441ret
442end
443if lt v 2048
444js_spush uchar or 192 shr v 6
445js_spush uchar or 128 and v 63
446ret
447end
448if lt v 65536
449js_spush uchar or 224 shr v 12
450js_spush uchar or 128 and shr v 6 63
451js_spush uchar or 128 and v 63
452ret
453end
454js_spush uchar or 240 shr v 18
455js_spush uchar or 128 and shr v 12 63
456js_spush uchar or 128 and shr v 6 63
457js_spush uchar or 128 and v 63
458end
459note decode_hex_escape -> jqh
460fn js_hex4 to bool
461i = get jpi 0
462e = get jpe 0
463if lt sub e i 4
464put jpi 0 e
465js_eerr 3
466ret false
467end
468put jpi 0 add i 4
469v = uint 0
470bad = false
471for k ulong 4
472c = uint get jin add i k
473h = uint 99
474if and ge c 48 le c 57
475h = sub c 48
476end
477if and ge c 65 le c 70
478h = sub c 55
479end
480if and ge c 97 le c 102
481h = sub c 87
482end
483if eq h 99
484bad = true
485end
486v = or shl v 4 and h 15
487end
488if bad
489js_eerr 10
490ret false
491end
492put jqh 0 ulong v
493ret true
494end
495fn js_uesc to bool
496if not js_hex4
497ret false
498end
499n = uint get jqh 0
500if and ge n 56320 le n 57343
501js_eerr 16
502ret false
503end
504if or lt n 55296 gt n 56319
505js_scp n
506ret true
507end
508c = js_peek
509if eq c 256
510js_eerr 3
511ret false
512end
513put jpi 0 add get jpi 0 1
514if ne c 92
515js_eerr 19
516ret false
517end
518c = js_peek
519if eq c 256
520js_eerr 3
521ret false
522end
523put jpi 0 add get jpi 0 1
524if ne c 117
525js_eerr 19
526ret false
527end
528if not js_hex4
529ret false
530end
531n2 = uint get jqh 0
532if or lt n2 56320 gt n2 57343
533js_eerr 16
534ret false
535end
536js_scp add or shl sub n 55296 10 sub n2 56320 65536
537ret true
538end
539fn js_esc to bool
540i = get jpi 0
541if ge i get jpe 0
542js_eerr 3
543ret false
544end
545c = get jin i
546put jpi 0 add i 1
547if or eq c 34 or eq c 92 eq c 47
548js_spush c
549ret true
550end
551if eq c 98
552js_spush 8
553ret true
554end
555if eq c 102
556js_spush 12
557ret true
558end
559if eq c 110
560js_spush 10
561ret true
562end
563if eq c 114
564js_spush 13
565ret true
566end
567if eq c 116
568js_spush 9
569ret true
570end
571if eq c 117
572ret js_uesc
573end
574js_eerr 10
575ret false
576end
577note continuation byte check for js_utf8
578note core::str::from_utf8 acceptance of jsp[s .. e)
579fn js_utf8 s ulong e ulong to bool
580i = s
581for b ulong 4000
582for t ulong 4000
583if ge i e
584ret true
585end
586c = get jsp i
587if lt c 128
588i = add i 1
589else
590k = ulong 0
591lo = uchar 128
592hi = uchar 191
593if and ge c 194 le c 223
594k = 1
595end
596if and ge c 224 le c 239
597k = 2
598if eq c 224
599lo = 160
600end
601if eq c 237
602hi = 159
603end
604end
605if and ge c 240 le c 244
606k = 3
607if eq c 240
608lo = 144
609end
610if eq c 244
611hi = 143
612end
613end
614if eq k 0
615ret false
616end
617if gt add i k sub e 1
618ret false
619end
620d = get jsp add i 1
621if or lt d lo gt d hi
622ret false
623end
624if ge k 2
625if ne and get jsp add i 2 192 128
626ret false
627end
628end
629if eq k 3
630if ne and get jsp add i 3 192 128
631ret false
632end
633end
634i = add add i k 1
635end
636end
637end
638ret true
639end
640fn js_pstr to bool
641i = get jpi 0
642e = get jpe 0
643s0 = get jspn 0
644if gt sub e i sub jspcap s0
645js_ecap
646ret false
647end
648o = s0
649for b ulong 4000
650for t ulong 4000
651if ge i e
652put jpi 0 e
653put jspn 0 o
654js_eerr 3
655ret false
656end
657c = get jin i
658if eq c 34
659i = add i 1
660put jpi 0 i
661put jspn 0 o
662if not js_utf8 s0 o
663js_eerr 13
664ret false
665end
666put jqo 0 s0
667put jql 0 sub o s0
668ret true
669end
670if eq c 92
671put jpi 0 add i 1
672put jspn 0 o
673if not js_esc
674ret false
675end
676i = get jpi 0
677o = get jspn 0
678else
679if lt c 32
680put jpi 0 add i 1
681js_eerr 14
682ret false
683end
684put jsp o c
685o = add o 1
686i = add i 1
687end
688end
689end
690js_ecap
691ret false
692end
693note ---- nodes ----
694fn js_new k uchar st ulong to ulong
695n = get jnn 0
696if ge n jncap
697ret jnone
698end
699put jnk n k
700put jns n uint st
701put jne n uint st
702put jnv n 0
703put jnl n 0
704put jnko n 0
705put jnkl n 0
706put jnkq n 0
707put jnn 0 add n 1
708ret n
709end
710fn js_scal st ulong to ulong
711n = js_new get jqk 0 st
712if eq n jnone
713ret n
714end
715put jnv n get jqv 0
716put jne n uint get jpi 0
717ret n
718end
719fn js_push v ulong to bool
720n = get jstn 0
721if ge n jstcap
722js_ecap
723ret false
724end
725put jst n uint v
726put jstn 0 add n 1
727ret true
728end
729note key order (Rust String Ord: bytes, then length) of member nodes a, b: -1, 0, 1
730fn js_kcmp a ulong b ulong to int
731ao = ulong get jnko a
732al = ulong get jnkl a
733bo = ulong get jnko b
734bl = ulong get jnkl b
735m = al
736if lt bl m
737m = bl
738end
739k = ulong 0
740for c ulong 4000
741for t ulong 4000
742if ge k m
743if lt al bl
744ret -1
745end
746if gt al bl
747ret 1
748end
749ret 0
750end
751x = get jsp add ao k
752y = get jsp add bo k
753if lt x y
754ret -1
755end
756if gt x y
757ret 1
758end
759k = add k 1
760end
761end
762ret 0
763end
764note merge jcl[a .. m) and jcl[m .. z) into jst[o ..]
765fn js_merge a ulong m ulong z ulong o ulong to void
766j = m
767for c ulong 4000
768for t ulong 4000
769if and ge a m ge j z
770ret
771end
772x = jnone
773if lt a m
774x = ulong get jcl a
775end
776if lt j z
777y = ulong get jcl j
778tk = true
779if ne x jnone
780tk = gt js_kcmp x y 0
781end
782if tk
783x = y
784j = add j 1
785else
786a = add a 1
787end
788else
789a = add a 1
790end
791put jst o uint x
792o = add o 1
793end
794end
795end
796note bounds of the run pair starting at a (width w, end e) then merge
797fn js_mrg2 a ulong w ulong e ulong o ulong to void
798m = add a w
799if gt m e
800m = e
801end
802z = add m w
803if gt z e
804z = e
805end
806js_merge a m z o
807end
808note stable sort of jcl[s .. s+n) by key, temp jst[t .. t+n)
809fn js_ksort s ulong n ulong t ulong to void
810w = ulong 1
811e = add s n
812for p ulong 64
813if ge w n
814ret
815end
816a = s
817for q ulong 4194304
818if ge a e
819break
820end
821js_mrg2 a w e add t sub a s
822a = add a mul w 2
823end
824js_cpch s t n
825w = mul w 2
826end
827end
828note copy jst[base .. base+n) to jcl[off ..] (and to jcl[off+n+1 ..] when obj)
829fn js_cpch off ulong base ulong n ulong to void
830for b ulong 4000
831for c ulong 4000
832if eq n 0
833ret
834end
835x = get jst base
836put jcl off x
837off = add off 1
838base = add base 1
839n = sub n 1
840end
841end
842end
843note container end: children jst[base .. top) -> jcl (raw); objects also get [m, sorted unique keys]
844fn js_fin nd ulong base ulong obj bool to bool
845top = get jstn 0
846n = sub top base
847off = get jcln 0
848need = n
849if obj
850need = add mul n 2 1
851end
852if gt need sub jclcap off
853js_ecap
854ret false
855end
856js_cpch off base n
857if obj
858js_cpch add add off n 1 base n
859end
860put jnv nd off
861put jnl nd uint n
862put jne nd uint get jpi 0
863put jstn 0 base
864if not obj
865put jcln 0 add off n
866ret true
867end
868s = add add off n 1
869if gt n sub jstcap top
870js_ecap
871ret false
872end
873js_ksort s n top
874m = js_uniq s n
875put jcl add off n uint m
876put jcln 0 add s m
877ret true
878end
879note keep the last member of each run of equal keys (BTreeMap insert = last wins); returns count
880fn js_uniq s ulong n ulong to ulong
881m = ulong 0
882k = ulong 0
883for b ulong 4000
884for c ulong 4000
885if ge k n
886ret m
887end
888x = get jcl add s k
889keep = true
890if lt add k 1 n
891if eq js_kcmp ulong x ulong get jcl add add s k 1 0
892keep = false
893end
894end
895if keep
896put jcl add s m x
897m = add m 1
898end
899k = add k 1
900end
901end
902ret m
903end
904note ---- values (Deserializer::deserialize_any for serde_json::Value) ----
905note On failure jfail = 1. A container that was open keeps its completed members and is marked
906note incomplete (kind bit 16); its pending member (the one being read when the error hit) is stored
907note after the member list: an incomplete container, a placeholder kind 10 (value started and failed),
908note a placeholder kind 9 (object: key read, failed before the value started), or none.
909fn js_val to ulong
910c = js_ws
911st = get jpi 0
912if eq c 256
913js_perr 4
914ret jnone
915end
916if eq c 110
917put jpi 0 add get jpi 0 1
918if not js_ident jtull
919ret jnone
920end
921put jqk 0 0
922ret js_scal st
923end
924if eq c 116
925put jpi 0 add get jpi 0 1
926if not js_ident jtrue
927ret jnone
928end
929put jqk 0 2
930ret js_scal st
931end
932if eq c 102
933put jpi 0 add get jpi 0 1
934if not js_ident jtalse
935ret jnone
936end
937put jqk 0 1
938ret js_scal st
939end
940if eq c 45
941put jpi 0 add get jpi 0 1
942if not js_nint false
943ret jnone
944end
945ret js_scal st
946end
947if and ge c 48 le c 57
948if not js_nint true
949ret jnone
950end
951ret js_scal st
952end
953if eq c 34
954put jpi 0 add get jpi 0 1
955if not js_pstr
956ret jnone
957end
958put jqk 0 6
959put jqv 0 get jqo 0
960n = js_scal st
961if ne n jnone
962put jnl n uint get jql 0
963end
964ret n
965end
966if eq c 91
967ret js_arr st
968end
969if eq c 123
970ret js_obj st
971end
972js_perr 9
973ret jnone
974end
975fn js_deep to bool
976d = get jpd 0
977d = sub d 1
978put jpd 0 d
979if eq d 0
980js_perr 20
981ret false
982end
983ret true
984end
985note placeholder member for a failed value (k 10) or a key without value (k 9)
986fn js_ph k uchar to ulong
987n = js_new k get jpi 0
988if ne n jnone
989put jnk n or k 16
990end
991ret n
992end
993note incomplete container: completed members jst[base .. top) then the pending member
994fn js_finp nd ulong base ulong pend ulong to ulong
995top = get jstn 0
996n = sub top base
997off = get jcln 0
998if gt add n 1 sub jclcap off
999put jstn 0 base
1000put jnk nd or get jnk nd 16
1001put jnv nd off
1002put jnl nd 0
1003ret nd
1004end
1005js_cpch off base n
1006p = uint 4294967295
1007if ne pend jnone
1008p = uint pend
1009end
1010put jcl add off n p
1011put jcln 0 add add off n 1
1012put jnv nd off
1013put jnl nd uint n
1014put jne nd uint get jpi 0
1015put jnk nd or get jnk nd 16
1016put jstn 0 base
1017ret nd
1018end
1019fn js_arr st ulong to ulong
1020if not js_deep
1021ret jnone
1022end
1023put jpi 0 add get jpi 0 1
1024nd = js_new 7 st
1025if eq nd jnone
1026js_ecap
1027ret jnone
1028end
1029base = get jstn 0
1030first = true
1031for b ulong 4000
1032for t ulong 4000
1033c = js_ws
1034if eq c 256
1035js_perr 1
1036ret js_finp nd base jnone
1037end
1038if eq c 93
1039put jpi 0 add get jpi 0 1
1040put jpd 0 add get jpd 0 1
1041if not js_fin nd base false
1042ret js_finp nd base jnone
1043end
1044ret nd
1045end
1046if first
1047first = false
1048else
1049if ne c 44
1050js_perr 6
1051ret js_finp nd base jnone
1052end
1053put jpi 0 add get jpi 0 1
1054c = js_ws
1055if eq c 93
1056js_perr 17
1057ret js_finp nd base jnone
1058end
1059if eq c 256
1060js_perr 4
1061ret js_finp nd base jnone
1062end
1063end
1064v = js_val
1065if eq get jfail 0 1
1066if eq v jnone
1067v = js_ph 10
1068end
1069ret js_finp nd base v
1070end
1071if not js_push v
1072ret js_finp nd base jnone
1073end
1074end
1075end
1076js_ecap
1077ret js_finp nd base jnone
1078end
1079note has_next_key: returns 1 = key follows (index at '"'), 0 = '}' , 2 = error
1080fn js_hnk first bool to uchar
1081c = js_ws
1082if eq c 256
1083js_perr 2
1084ret 2
1085end
1086if eq c 125
1087ret 0
1088end
1089if first
1090if ne c 34
1091js_perr 15
1092ret 2
1093end
1094ret 1
1095end
1096if ne c 44
1097js_perr 7
1098ret 2
1099end
1100put jpi 0 add get jpi 0 1
1101c = js_ws
1102if eq c 34
1103ret 1
1104end
1105if eq c 125
1106js_perr 17
1107ret 2
1108end
1109if eq c 256
1110js_perr 4
1111ret 2
1112end
1113js_perr 15
1114ret 2
1115end
1116fn js_colon to bool
1117c = js_ws
1118if eq c 58
1119put jpi 0 add get jpi 0 1
1120ret true
1121end
1122if eq c 256
1123js_perr 2
1124ret false
1125end
1126js_perr 5
1127ret false
1128end
1129note key just parsed (jqo/jql) equals serde_json's RawValue token
1130fn js_israw to bool
1131if ne get jql 0 len jtrawk
1132ret false
1133end
1134o = get jqo 0
1135for k ulong len jtrawk
1136if ne get jsp add o k get jtrawk k
1137ret false
1138end
1139end
1140ret true
1141end
1142fn js_setk v ulong ko ulong kl ulong ke ulong to void
1143if ne v jnone
1144put jnko v uint ko
1145put jnkl v uint kl
1146put jnkq v uint ke
1147end
1148end
1149fn js_obj st ulong to ulong
1150if not js_deep
1151ret jnone
1152end
1153put jpi 0 add get jpi 0 1
1154nd = js_new 8 st
1155if eq nd jnone
1156js_ecap
1157ret jnone
1158end
1159base = get jstn 0
1160first = true
1161for b ulong 4000
1162for t ulong 4000
1163h = js_hnk first
1164if eq h 2
1165ret js_finp nd base js_ph 11
1166end
1167if eq h 0
1168put jpi 0 add get jpi 0 1
1169put jpd 0 add get jpd 0 1
1170if not js_fin nd base true
1171ret js_finp nd base jnone
1172end
1173ret nd
1174end
1175put jpi 0 add get jpi 0 1
1176if not js_pstr
1177ret js_finp nd base js_ph 11
1178end
1179ko = get jqo 0
1180kl = get jql 0
1181ke = get jpi 0
1182if first
1183if eq get jrvm 0 0
1184if js_israw
1185r = js_rawv
1186if eq get jfail 0 1
1187ret js_rawf nd base ko kl ke
1188end
1189ret r
1190end
1191end
1192end
1193first = false
1194if not js_colon
1195v = js_ph 9
1196js_setk v ko kl ke
1197ret js_finp nd base v
1198end
1199v = js_val
1200if eq get jfail 0 1
1201if eq v jnone
1202v = js_ph 10
1203end
1204js_setk v ko kl ke
1205ret js_finp nd base v
1206end
1207js_setk v ko kl ke
1208if not js_push v
1209ret js_finp nd base jnone
1210end
1211end
1212end
1213js_ecap
1214ret js_finp nd base jnone
1215end
1216note ---- serde_json raw_value feature: Value's visit_map with first key "$serde_json::private::RawValue" ----
1217note value must be a string; its contents are parsed again by serde_json::from_str (fresh depth); errors
1218note there become de::Error::custom (category Data). The rest of the map must then be '}'.
1219fn js_rawv to ulong
1220put jrvs 0 1
1221if not js_colon
1222ret jnone
1223end
1224put jrvs 0 2
1225c = js_ws
1226if eq c 256
1227js_perr 4
1228ret jnone
1229end
1230if ne c 34
1231js_rinv c
1232ret jnone
1233end
1234put jpi 0 add get jpi 0 1
1235if not js_pstr
1236ret jnone
1237end
1238put jrvs 0 3
1239r = js_sub get jqo 0 get jql 0 false
1240put jrvs 0 3
1241if eq get jfail 0 1
1242if ne get jecat 0 9
1243put jecat 0 3
1244end
1245ret jnone
1246end
1247c = js_ws
1248if eq c 125
1249put jpi 0 add get jpi 0 1
1250put jpd 0 add get jpd 0 1
1251ret r
1252end
1253if eq c 44
1254js_perr 17
1255ret jnone
1256end
1257if eq c 256
1258js_perr 2
1259ret jnone
1260end
1261js_perr 18
1262ret jnone
1263end
1264note partial tree for a failed RawValue member: stage 1 (colon) -> placeholder 9, stage 2 (value) ->
1265note placeholder 10, both keyed by the token (serde_path_to_error shows the key only for stage 2);
1266note stage 3 (the inner from_str or the closing '}') -> no pending member
1267fn js_rawf nd ulong base ulong ko ulong kl ulong ke ulong to ulong
1268v = jnone
1269if eq get jrvs 0 1
1270v = js_ph 9
1271end
1272if eq get jrvs 0 2
1273v = js_ph 10
1274end
1275js_setk v ko kl ke
1276ret js_finp nd base v
1277end
1278note peek_invalid_type for BoxedFromString ("expected raw value"); always returns false
1279fn js_rinv c uint to void
1280if or eq c 110 or eq c 116 eq c 102
1281put jpi 0 add get jpi 0 1
1282if eq c 110
1283if not js_ident jtull
1284ret
1285end
1286end
1287if eq c 116
1288if not js_ident jtrue
1289ret
1290end
1291end
1292if eq c 102
1293if not js_ident jtalse
1294ret
1295end
1296end
1297else
1298if eq c 45
1299put jpi 0 add get jpi 0 1
1300if not js_nint false
1301ret
1302end
1303else
1304if and ge c 48 le c 57
1305if not js_nint true
1306ret
1307end
1308else
1309if and ne c 91 ne c 123
1310js_perr 9
1311ret
1312end
1313end
1314end
1315end
1316put jeml 0 0
1317js_ejt jtinv
1318js_unexp c
1319js_ejt jtexp
1320js_epos_txt get jpi 0
1321put jecat 0 3
1322put jfail 0 1
1323ret
1324end
1325note serde Unexpected text for the value just read (first byte c); numbers from jqk/jqv
1326fn js_unexp c uint to void
1327if eq c 110
1328js_ejt jtnull
1329ret
1330end
1331if eq c 91
1332js_ejt jtseq
1333ret
1334end
1335if eq c 123
1336js_ejt jtmap
1337ret
1338end
1339if or eq c 116 eq c 102
1340js_ejt jtbool
1341if eq c 116
1342js_ejt jttrue
1343else
1344js_ejt jtfalse
1345end
1346js_ejm 96
1347ret
1348end
1349k = get jqk 0
1350if eq k 5
1351js_ejt jtflt
1352num_ryu get jqv 0 true
1353else
1354js_ejt jtint
1355if eq k 3
1356num_u64 get jqv 0
1357else
1358num_i64 bitcast long get jqv 0
1359end
1360end
1361for i ulong get jfbl 0
1362js_ejm get jfb i
1363end
1364js_ejm 96
1365end
1366note parse jsp[o .. o+n) as a separate document (from_str: own region, depth 128, then end())
1367fn js_sub o ulong n ulong pfx bool to ulong
1368u = get jinu 0
1369if gt n sub jincap u
1370js_ecap
1371ret jnone
1372end
1373js_cpb 0 u o n
1374si = get jpi 0
1375se = get jpe 0
1376sb = get jpb 0
1377sd = get jpd 0
1378put jinu 0 add u n
1379r = js_doc u add u n pfx
1380put jinu 0 u
1381put jpi 0 si
1382put jpe 0 se
1383put jpb 0 sb
1384put jpd 0 sd
1385ret r
1386end
1387note from_slice/from_str over jin[b .. e): value, then end() unless pfx (axum Json: no end());
1388note returns the root (possibly an incomplete container) or jnone; success iff jfail = 0
1389fn js_doc b ulong e ulong pfx bool to ulong
1390put jpi 0 b
1391put jpe 0 e
1392put jpb 0 b
1393put jpd 0 128
1394r = js_val
1395if eq get jfail 0 1
1396ret r
1397end
1398if not pfx
1399if ne js_ws 256
1400js_perr 18
1401end
1402end
1403ret r
1404end
1405note ---- public parse API ----
1406fn js_parse0 pfx bool to bool
1407num_init
1408put jnn 0 0
1409put jcln 0 0
1410put jstn 0 0
1411put jspn 0 0
1412put jeml 0 0
1413put jecat 0 0
1414put jfail 0 0
1415n = get jinl 0
1416put jinu 0 n
1417r = js_doc 0 n pfx
1418put jpb 0 0
1419put jroot 0 r
1420ret eq get jfail 0 0
1421end
1422note serde_json::from_slice::<Value>(jin[0 .. jinl)) -> jroot; false: message jem/jeml, category jecat,
1423note partial tree reachable from jroot (jnone when the failing value was a scalar at the root)
1424fn js_parse to bool
1425ret js_parse0 false
1426end
1427note as js_parse, but only the first value is read; trailing bytes are ignored (axum Json extractor)
1428fn js_parsep to bool
1429ret js_parse0 true
1430end
1431note kind: 0 null 1 false 2 true 3 u64 4 i64 5 f64 6 string 7 array 8 object; partial trees also
1432note have placeholders 9 (key read, no value), 10 (value started, failed), 11 (next key failed)
1433fn js_kind n ulong to uchar
1434ret and get jnk n 15
1435end
1436note false for an incomplete container or a placeholder (parse failed inside it)
1437fn js_done n ulong to bool
1438ret eq and get jnk n 16 0
1439end
1440note completed members of an array / object (raw document order, duplicate keys included)
1441fn js_len n ulong to ulong
1442k = and get jnk n 15
1443if or eq k 7 eq k 8
1444ret ulong get jnl n
1445end
1446ret 0
1447end
1448note pending member of an incomplete container, else jnone
1449fn js_pend n ulong to ulong
1450if js_done n
1451ret jnone
1452end
1453k = and get jnk n 15
1454if and ne k 7 ne k 8
1455ret jnone
1456end
1457p = get jcl add get jnv n ulong get jnl n
1458if eq p 4294967295
1459ret jnone
1460end
1461ret ulong p
1462end
1463note serde_path_to_error path (Value target) of the failure, appended to job: keys "a.b", indices "[i]",
1464note "?" where serde could not capture a key (error inside next_key). Returns false and appends nothing
1465note when the path is empty or only "?" segments (serde_path_to_error then prints no "path: " prefix).
1466fn js_path to bool
1467n = get jroot 0
1468s0 = get jobl 0
1469w = false
1470real = false
1471for it ulong 1000000
1472if eq n jnone
1473break
1474end
1475p = js_pend n
1476if eq p jnone
1477break
1478end
1479pk = and get jnk p 15
1480if eq and get jnk n 15 7
1481js_byte 91
1482js_u64 js_len n
1483js_byte 93
1484real = true
1485else
1486if eq pk 9
1487break
1488end
1489if w
1490js_byte 46
1491end
1492if eq pk 11
1493js_byte 63
1494else
1495js_esc_raw ulong get jnko p ulong get jnkl p
1496real = true
1497end
1498end
1499w = true
1500n = p
1501end
1502if not real
1503put jobl 0 s0
1504end
1505ret real
1506end
1507note copy pool bytes jsp[o .. o+n) to job unescaped
1508fn js_esc_raw o ulong n ulong to void
1509for b ulong 4000
1510for c ulong 4000
1511if eq n 0
1512ret
1513end
1514js_byte get jsp o
1515o = add o 1
1516n = sub n 1
1517end
1518end
1519end
1520note Rust <str as Debug> of the string node n ("..." with \0 \t \r \n \\ \" and \u{hex}), appended to job
1521fn js_dbg_str n ulong to void
1522o = get jnv n
1523e = add o ulong get jnl n
1524js_byte 34
1525i = o
1526for b ulong 4000
1527for t ulong 4000
1528if ge i e
1529js_byte 34
1530ret
1531end
1532c = get jsp i
1533if lt c 128
1534js_dbg1 c
1535i = add i 1
1536else
1537i = js_dbgm i e
1538end
1539end
1540end
1541js_byte 34
1542end
1543fn js_dbg1 c uchar to void
1544if eq c 0
1545js_byte 92
1546js_byte 48
1547ret
1548end
1549if eq c 9
1550js_byte 92
1551js_byte 116
1552ret
1553end
1554if eq c 13
1555js_byte 92
1556js_byte 114
1557ret
1558end
1559if eq c 10
1560js_byte 92
1561js_byte 110
1562ret
1563end
1564if or eq c 92 eq c 34
1565js_byte 92
1566js_byte c
1567ret
1568end
1569if or lt c 32 eq c 127
1570js_dbgu uint c
1571ret
1572end
1573js_byte c
1574end
1575fn js_dbgu v uint to void
1576js_byte 92
1577js_byte 117
1578js_byte 123
1579s = uint 28
1580st = false
1581for k ulong 8
1582d = and shr v s 15
1583if or st or ne d 0 eq s 0
1584st = true
1585js_byte get jthex d
1586end
1587if ne s 0
1588s = sub s 4
1589end
1590end
1591js_byte 125
1592end
1593note one multi-byte char of jsp at i (valid UTF-8); returns next index
1594fn js_dbgm i ulong e ulong to ulong
1595c = uint get jsp i
1596k = ulong 1
1597v = and c 31
1598if ge c 224
1599k = 2
1600v = and c 15
1601end
1602if ge c 240
1603k = 3
1604v = and c 7
1605end
1606for q ulong k
1607v = or shl v 6 and uint get jsp add add i q 1 63
1608end
1609if ru_inr v 2
1610js_dbgu v
1611else
1612for q ulong add k 1
1613js_byte get jsp add i q
1614end
1615end
1616ret add add i k 1
1617end
1618fn js_child n ulong i ulong to ulong
1619ret ulong get jcl add get jnv n i
1620end
1621fn js_num n ulong to ulong
1622ret get jnv n
1623end
1624fn js_spos n ulong to ulong
1625ret ulong get jns n
1626end
1627fn js_epos n ulong to ulong
1628ret ulong get jne n
1629end
1630fn js_kend n ulong to ulong
1631ret ulong get jnkq n
1632end
1633note position serde reports for a data error raised by a struct/map visitor itself (duplicate field after
1634note its key, missing field before the closing brace): skip JSON whitespace from idx, then step over a
1635note '}' (serde's end_map runs before fix_position). Duplicate field: js_vpos (js_kend m).
1636fn js_vpos idx ulong to ulong
1637e = get jinl 0
1638for it ulong 100000000
1639if ge idx e
1640ret idx
1641end
1642c = get jin idx
1643if eq c 125
1644ret add idx 1
1645end
1646if and ne c 32 and ne c 10 and ne c 9 ne c 13
1647ret idx
1648end
1649idx = add idx 1
1650end
1651ret idx
1652end
1653fn js_lnb b ulong idx ulong to ulong
1654ln = ulong 1
1655k = b
1656for c ulong 4000
1657for t ulong 4000
1658if ge k idx
1659ret ln
1660end
1661if eq get jin k 10
1662ln = add ln 1
1663end
1664k = add k 1
1665end
1666end
1667ret ln
1668end
1669fn js_solb b ulong idx ulong to ulong
1670k = idx
1671for c ulong 4000
1672for t ulong 4000
1673if le k b
1674ret b
1675end
1676if eq get jin sub k 1 10
1677ret k
1678end
1679k = sub k 1
1680end
1681end
1682ret b
1683end
1684note serde line / column of absolute index idx in the main document
1685fn js_line idx ulong to ulong
1686ret js_lnb 0 idx
1687end
1688fn js_col idx ulong to ulong
1689ret sub idx js_solb 0 idx
1690end
1691note byte copies into jin or jsv: sel 0 jsp -> jin, 1 jes -> jin, 2 jsp -> jsv
1692note (js_tosv: pool bytes jsp[o .. o+n) to jsv/jsvl)
1693fn js_cpb sel uchar d ulong o ulong n ulong to void
1694for b ulong 4000
1695for c ulong 4000
1696if eq n 0
1697ret
1698end
1699if eq sel 0
1700x = get jsp o
1701put jin d x
1702else
1703if eq sel 1
1704x = get jes o
1705put jin d x
1706else
1707x = get jsp o
1708put jsv d x
1709end
1710end
1711d = add d 1
1712o = add o 1
1713n = sub n 1
1714end
1715end
1716end
1717fn js_tosv o ulong n ulong to void
1718put jsvl 0 n
1719js_cpb 2 0 o n
1720end
1721fn js_str n ulong to void
1722js_tosv get jnv n ulong get jnl n
1723end
1724fn js_key n ulong to void
1725js_tosv ulong get jnko n ulong get jnkl n
1726end
1727note Value::get(key) on an object: the member kept by BTreeMap (last duplicate); jnone if absent
1728fn js_find n ulong key view uchar * to ulong
1729if ne and get jnk n 15 8
1730ret jnone
1731end
1732off = get jnv n
1733c = ulong get jnl n
1734r = jnone
1735i = ulong 0
1736for b ulong 4000
1737for t ulong 4000
1738if ge i c
1739ret r
1740end
1741m = ulong get jcl add off i
1742if eq ulong get jnkl m len key
1743if js_keq m key
1744r = m
1745end
1746end
1747i = add i 1
1748end
1749end
1750ret r
1751end
1752fn js_keq m ulong key view uchar * to bool
1753o = ulong get jnko m
1754k = ulong 0
1755for b ulong 4000
1756for t ulong 4000
1757if ge k len key
1758ret true
1759end
1760if ne get jsp add o k get key k
1761ret false
1762end
1763k = add k 1
1764end
1765end
1766ret true
1767end
1768note ---- serializer (serde_json compact) ----
1769fn js_esc1 c uchar to void
1770js_byte 92
1771if eq c 34
1772js_byte 34
1773ret
1774end
1775if eq c 92
1776js_byte 92
1777ret
1778end
1779if eq c 8
1780js_byte 98
1781ret
1782end
1783if eq c 12
1784js_byte 102
1785ret
1786end
1787if eq c 10
1788js_byte 110
1789ret
1790end
1791if eq c 13
1792js_byte 114
1793ret
1794end
1795if eq c 9
1796js_byte 116
1797ret
1798end
1799js_byte 117
1800js_byte 48
1801js_byte 48
1802js_byte get jthex shr c 4
1803js_byte get jthex and c 15
1804end
1805note escaped JSON string (with quotes) of pool bytes jsp[o .. o+n)
1806fn js_esc_sp o ulong n ulong to void
1807js_byte 34
1808p = get jobl 0
1809fast = le n div sub 16777216 p 6
1810for b ulong 4000
1811for t ulong 4000
1812if eq n 0
1813put jobl 0 p
1814js_byte 34
1815ret
1816end
1817c = get jsp o
1818o = add o 1
1819n = sub n 1
1820if or lt c 32 or eq c 34 eq c 92
1821put jobl 0 p
1822js_esc1 c
1823p = get jobl 0
1824else
1825if fast
1826put job p c
1827p = add p 1
1828else
1829put jobl 0 p
1830js_byte c
1831p = get jobl 0
1832end
1833end
1834end
1835end
1836end
1837note escaped JSON string of jes[off .. off+n)
1838fn js_esc_buf off ulong n ulong to void
1839js_byte 34
1840p = get jobl 0
1841fast = le n div sub 16777216 p 6
1842for b ulong 4000
1843for t ulong 4000
1844if eq n 0
1845put jobl 0 p
1846js_byte 34
1847ret
1848end
1849c = get jes off
1850off = add off 1
1851n = sub n 1
1852if or lt c 32 or eq c 34 eq c 92
1853put jobl 0 p
1854js_esc1 c
1855p = get jobl 0
1856else
1857if fast
1858put job p c
1859p = add p 1
1860else
1861put jobl 0 p
1862js_byte c
1863p = get jobl 0
1864end
1865end
1866end
1867end
1868end
1869fn js_esc_txt s view uchar * to void
1870js_byte 34
1871k = ulong 0
1872for b ulong 4000
1873for t ulong 4000
1874if ge k len s
1875js_byte 34
1876ret
1877end
1878c = get s k
1879k = add k 1
1880if or lt c 32 or eq c 34 eq c 92
1881js_esc1 c
1882else
1883js_byte c
1884end
1885end
1886end
1887end
1888note serde_json::to_string of the subtree n (objects in sorted-key BTreeMap order)
1889fn js_canon n ulong to void
1890k = get jnk n
1891if eq k 0
1892js_raw jtnull
1893ret
1894end
1895if eq k 1
1896js_raw jtfalse
1897ret
1898end
1899if eq k 2
1900js_raw jttrue
1901ret
1902end
1903if eq k 3
1904js_u64 get jnv n
1905ret
1906end
1907if eq k 4
1908js_i64 bitcast long get jnv n
1909ret
1910end
1911if eq k 5
1912js_f64 get jnv n
1913ret
1914end
1915if eq k 6
1916js_esc_sp get jnv n ulong get jnl n
1917ret
1918end
1919off = get jnv n
1920c = ulong get jnl n
1921if eq k 7
1922js_byte 91
1923js_canl off c false
1924js_byte 93
1925ret
1926end
1927js_byte 123
1928js_canl add add off c 1 ulong get jcl add off c true
1929js_byte 125
1930end
1931note members jcl[off .. off+c) comma separated; obj: "key":value
1932fn js_canl off ulong c ulong obj bool to void
1933i = ulong 0
1934for b ulong 4000
1935for t ulong 4000
1936if ge i c
1937ret
1938end
1939if ne i 0
1940js_byte 44
1941end
1942x = ulong get jcl add off i
1943if obj
1944js_esc_sp ulong get jnko x ulong get jnkl x
1945js_byte 58
1946end
1947js_canon x
1948i = add i 1
1949end
1950end
1951end
1952note serde_json::to_string(&from_str::<Value>(jes[off .. off+n))) appended to job; false (nothing
1953note appended) when the text is not accepted. The current tree (jroot and its nodes) is preserved.
1954fn js_canon_buf off ulong n ulong to bool
1955num_init
1956put jsav 8 get jnn 0
1957put jsav 9 get jcln 0
1958put jsav 10 get jstn 0
1959put jsav 11 get jspn 0
1960put jsav 12 get jinu 0
1961u = get jinu 0
1962if gt n sub jincap u
1963js_ecap
1964ret false
1965end
1966js_cpb 1 u off n
1967put jinu 0 add u n
1968put jsav 13 ulong get jfail 0
1969put jfail 0 0
1970r = js_doc u add u n false
1971ok = eq get jfail 0 0
1972if ok
1973js_canon r
1974end
1975put jfail 0 uchar get jsav 13
1976put jnn 0 get jsav 8
1977put jcln 0 get jsav 9
1978put jstn 0 get jsav 10
1979put jspn 0 get jsav 11
1980put jinu 0 get jsav 12
1981put jpb 0 0
1982ret ok
1983end