interplane.Get Omega
Read in your language

aienux

Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.

Brought by drakestapleton

branch main Branches Tags History

aienux / native / omega / allen / github.om

1250 lines · 18439 bytes Raw Blame History
1note SPDX-License-Identifier: AGPL-3.0-only
2note Strict JSON copied unchanged from omega-mv native/hermes/src/json.om.
3note Source revision b8e57bc6be5e40efc1d0d1ce01afdc58e814b449; single pinned parser.
4note SPDX-License-Identifier: AGPL-3.0-only
5note Bounded strict JSON. Tokens are valid only when jparse returns zero.
6note Types object1 array2 string3 number4 true5 false6 null7.
7note Raw token spans include string quotes; parent4096 denotes root.
8global jin uchar 65536
9global jerr ulong 1
10global jcnt ulong 1
11global jbeg ulong 4096
12global jend ulong 4096
13global jtyp ulong 4096
14global jpar ulong 4096
15global jpos ulong 1
16global jlen ulong 1
17fn jfail to void
18put jerr 0 1
19end
20fn jpeek to ulong
21p = get jpos 0
22if ge p get jlen 0
23ret 256
24end
25ret ulong get jin p
26end
27fn jtake to ulong
28c = jpeek
29if eq c 256
30jfail
31else
32put jpos 0 add get jpos 0 1
33end
34ret c
35end
36fn jspace to void
37c = jpeek
38while or or eq c 32 eq c 9 or eq c 10 eq c 13
39c = jtake
40c = jpeek
41end
42end
43fn jexpect want ulong to void
44if ne jtake want
45jfail
46end
47end
48fn jhex to ulong
49v = ulong 0
50for i ulong 4
51c = jtake
52d = ulong 16
53if and ge c 48 le c 57
54d = sub c 48
55end
56if and ge c 65 le c 70
57d = sub c 55
58end
59if and ge c 97 le c 102
60d = sub c 87
61end
62if eq d 16
63jfail
64ret 0
65end
66v = add mul v 16 d
67end
68ret v
69end
70fn jutf c ulong to void
71n = ulong 0
72lo = ulong 128
73hi = ulong 191
74if and ge c 194 le c 223
75n = 1
76end
77if and ge c 224 le c 239
78n = 2
79if eq c 224
80lo = 160
81end
82if eq c 237
83hi = 159
84end
85end
86if and ge c 240 le c 244
87n = 3
88if eq c 240
89lo = 144
90end
91if eq c 244
92hi = 143
93end
94end
95if eq n 0
96jfail
97ret
98end
99for i ulong n
100d = jtake
101if or lt d lo gt d hi
102jfail
103ret
104end
105lo = 128
106hi = 191
107end
108end
109fn jstring to void
110jexpect 34
111while eq get jerr 0 0
112c = jtake
113if eq c 34
114ret
115end
116if or lt c 32 eq c 256
117jfail
118ret
119end
120if eq c 92
121c = jtake
122if eq c 117
123u = jhex
124if and ge u 55296 le u 56319
125jexpect 92
126jexpect 117
127v = jhex
128if or lt v 56320 gt v 57343
129jfail
130end
131else
132if and ge u 56320 le u 57343
133jfail
134end
135end
136else
137ok = or or eq c 34 eq c 92 eq c 47
138ok = or ok or eq c 98 eq c 102
139ok = or ok or eq c 110 eq c 114
140ok = or ok eq c 116
141if not ok
142jfail
143end
144end
145else
146if ge c 128
147jutf c
148end
149end
150end
151end
152fn jdigit c ulong to bool
153ret and ge c 48 le c 57
154end
155fn jdigits to void
156if not jdigit jpeek
157jfail
158ret
159end
160while jdigit jpeek
161c = jtake
162end
163end
164fn jnumber to void
165if eq jpeek 45
166c = jtake
167end
168if eq jpeek 48
169c = jtake
170else
171jdigits
172end
173if eq jpeek 46
174c = jtake
175jdigits
176end
177if or eq jpeek 101 eq jpeek 69
178c = jtake
179if or eq jpeek 43 eq jpeek 45
180c = jtake
181end
182jdigits
183end
184end
185fn jtoken typ ulong par ulong to ulong
186n = get jcnt 0
187if ge n 4096
188jfail
189ret 4096
190end
191put jcnt 0 add n 1
192put jbeg n get jpos 0
193put jtyp n typ
194put jpar n par
195ret n
196end
197fn jvalue par ulong depth ulong to void
198jspace
199c = jpeek
200t = ulong 0
201if eq c 123
202t = 1
203end
204if eq c 91
205t = 2
206end
207if eq c 34
208t = 3
209end
210if or eq c 45 jdigit c
211t = 4
212end
213if eq c 116
214t = 5
215end
216if eq c 102
217t = 6
218end
219if eq c 110
220t = 7
221end
222if eq t 0
223jfail
224ret
225end
226id = jtoken t par
227if ne get jerr 0 0
228ret
229end
230if le t 2
231if ge depth 32
232jfail
233ret
234end
235c = jtake
236closing = ulong 93
237if eq t 1
238closing = 125
239end
240jspace
241if ne jpeek closing
242more = true
243while and more eq get jerr 0 0
244if eq t 1
245if ne jpeek 34
246jfail
247ret
248end
249key = jtoken 3 id
250if ne get jerr 0 0
251ret
252end
253jstring
254put jend key get jpos 0
255jspace
256jexpect 58
257end
258if eq get jerr 0 0
259jvalue id add depth 1
260end
261jspace
262if eq jpeek 44
263c = jtake
264jspace
265else
266more = false
267end
268end
269end
270jexpect closing
271else
272if eq t 3
273jstring
274end
275if eq t 4
276jnumber
277end
278if eq t 5
279jexpect 116
280jexpect 114
281jexpect 117
282jexpect 101
283end
284if eq t 6
285jexpect 102
286jexpect 97
287jexpect 108
288jexpect 115
289jexpect 101
290end
291if eq t 7
292jexpect 110
293jexpect 117
294jexpect 108
295jexpect 108
296end
297end
298put jend id get jpos 0
299end
300fn jparse n ulong to ulong
301put jerr 0 0
302put jcnt 0 0
303put jpos 0 0
304put jlen 0 n
305if or eq n 0 gt n len jin
306jfail
307ret 1
308end
309jvalue 4096 0
310jspace
311if ne get jpos 0 n
312jfail
313end
314if ne get jerr 0 0
315put jcnt 0 0
316end
317ret get jerr 0
318end
319
320note Network provider owns transport and writes only complete authenticated HTTPS bodies.
321note Host api.github.com; no redirects or credentials. Ghreq path is not a URL.
322note Ghreq kind,pathlen,unique generation,accept raw1/json0,maxbody,reserved3.
323note ghreply must echo kind AND generation. Timeout/network failure uses status0.
324global Ghbody uchar 262144
325global Ghpath uchar 1024
326global Ghreq ulong 8
327note Gh state0 idle1 loading2 ready3 error4 unsupported; generation; error; HTTP;
328note view0 README1 files2 details; scroll; selected; read bytes; file count;
329note pool bytes; directory bytes; clock; last accepted generation; readme absent.
330global Gh ulong 16
331global Ghat ulong 4
332global Ghmeta uchar 1024
333note Metadata offsets name0/64, branch64/256, description320/512, sha832/64,date896/64.
334global Ghlen ulong 8
335global Ghread uchar 262144
336global Ghdir uchar 512
337global Ghpool uchar 65536
338note Five words per directory entry: path offset,length,type(file1 dir2 other3),bytes,sha offset.
339global Ghfiles ulong 1280
340global Ghdec uchar 4096
341global Ghdn ulong 1
342global Ghbad ulong 1
343global Ghword uchar 160
344note Repository identity is DISCOVERED from a live listing and validated, never fixed.
345note Ghmeta 720/64 holds the selected full_name; 784/48 holds its created_at.
346global Ghbase uchar 128
347global Ghslen ulong 1
348text Ghext "/repos/"
349text Ghghu "https://github.com/"
350text Ghown "aien-dev/"
351text Ghlst "/orgs/aien-dev/repos?sort=created&direction=desc&per_page=1"
352text Ghkeys "full_name\ndefault_branch\ndescription\nprivate\nhtml_url\nsha\ncommit\ncommitter\ndate\npath\ntype\nsize\ncreated_at\n"
353text Ghsuf "/commits//readme?ref=/contents"
354text Ghhex "0123456789ABCDEF"
355text Ghvoc "repo\nrepository\nrepositories\ngit\ngithub\nfind\nshow\nopen\nbrowse\nwhere\nwhat\ncurrent\nyour\nallen\nsource\ncode\ncreate\ndelete\npush\nother\n"
356note Select the first repository in the live listing, then prove its identity before use.
357note Ordering is the server's (sort=created, direction=desc); we do not re-sort, we verify.
358note The listing is a JSON array; token 0 is the array and token 1 its first object.
359fn ghdiscover to bool
360if or lt get jcnt 0 2 ne get jtyp 0 2
361ret false
362end
363if or ne get jtyp 1 1 ne get jpar 1 0
364ret false
365end
366if not ghcopy ghfield 1 1 720 64 5
367ret false
368end
369n = get Ghlen 5
370if le n len Ghown
371ret false
372end
373for i ulong len Ghown
374if ne get Ghmeta add 720 i get Ghown i
375ret false
376end
377end
378first = add 720 len Ghown
379last = add 719 n
380if or eq get Ghmeta first 46 eq get Ghmeta first 45
381ret false
382end
383if or eq get Ghmeta last 46 eq get Ghmeta last 45
384ret false
385end
386for i ulong sub n len Ghown
387c = get Ghmeta add first i
388ok = and ge c 48 le c 57
389ok = or ok and ge c 65 le c 90
390ok = or ok and ge c 97 le c 122
391ok = or ok or eq c 46 eq c 95
392ok = or ok eq c 45
393if not ok
394ret false
395end
396end
397if not ghcopy ghfield 1 13 784 48 6
398ret false
399end
400if ne get Ghlen 6 20
401ret false
402end
403for i ulong 20
404c = get Ghmeta add 784 i
405want = uchar 0
406if or eq i 4 eq i 7
407want = 45
408end
409if eq i 10
410want = 84
411end
412if or eq i 13 eq i 16
413want = 58
414end
415if eq i 19
416want = 90
417end
418if ne want 0
419if ne c want
420ret false
421end
422else
423if or lt c 48 gt c 57
424ret false
425end
426end
427end
428ret eq get Ghbad 0 0
429end
430fn gherror code ulong to void
431put Gh 0 3
432put Gh 2 code
433put Ghreq 0 0
434note Existing bytes are never drawn as current after an error.
435end
436fn ghtime epoch ulong to void
437put Gh 11 epoch
438end
439fn ghinit to void
440for i ulong 16
441put Gh i 0
442end
443for i ulong 8
444put Ghreq i 0
445put Ghlen i 0
446end
447for i ulong 4
448put Ghat i 0
449end
450end
451fn ghreset to void
452for i ulong 8
453put Ghlen i 0
454end
455for i ulong 4
456put Ghat i 0
457end
458put Gh 2 0
459put Gh 3 0
460put Gh 4 0
461put Gh 5 0
462put Gh 6 0
463put Gh 7 0
464put Gh 8 0
465put Gh 9 0
466put Gh 10 0
467put Gh 12 0
468put Gh 13 0
469end
470fn ghbyte c uchar to void
471n = get Ghreq 1
472if ge n len Ghpath
473put Ghbad 0 1
474ret
475end
476put Ghpath n c
477put Ghreq 1 add n 1
478end
479fn ghenc c uchar to void
480ok = or and ge c 65 le c 90 and ge c 97 le c 122
481ok = or ok and ge c 48 le c 57
482ok = or ok or eq c 45 eq c 95
483ok = or ok or eq c 46 eq c 126
484if ok
485ghbyte c
486else
487ghbyte 37
488ghbyte get Ghhex div ulong c 16
489ghbyte get Ghhex rem ulong c 16
490end
491end
492fn ghbasebuf to bool
493note Ghbase = "/repos/" + the validated full_name held at Ghmeta 720.
494n = get Ghlen 5
495if or eq n 0 gt n 64
496ret false
497end
498put Ghslen 0 0
499for i ulong len Ghext
500put Ghbase i get Ghext i
501put Ghslen 0 add i 1
502end
503for i ulong n
504put Ghbase add len Ghext i get Ghmeta add 720 i
505end
506put Ghslen 0 add len Ghext n
507ret true
508end
509fn ghissue kind ulong to void
510if eq get Gh 1 18446744073709551615
511gherror 8
512ret
513end
514put Gh 1 add get Gh 1 1
515put Ghreq 0 kind
516put Ghreq 1 0
517put Ghreq 2 get Gh 1
518put Ghreq 3 0
519put Ghreq 4 65536
520put Ghbad 0 0
521note Clock is per response, never inherited as a fresh retrieval timestamp.
522put Gh 11 0
523if eq kind 5
524for i ulong len Ghlst
525ghbyte get Ghlst i
526end
527else
528if not ghbasebuf
529gherror 3
530ret
531end
532for i ulong get Ghslen 0
533ghbyte get Ghbase i
534end
535end
536if eq kind 2
537for i ulong 9
538ghbyte get Ghsuf i
539end
540for i ulong get Ghlen 1
541ghenc get Ghmeta add 64 i
542end
543end
544if eq kind 3
545put Ghreq 3 1
546put Ghreq 4 len Ghbody
547for i ulong 12
548ghbyte get Ghsuf add 9 i
549end
550end
551if eq kind 4
552for i ulong 9
553ghbyte get Ghsuf add 21 i
554end
555if gt get Gh 10 0
556ghbyte 47
557for i ulong get Gh 10
558c = get Ghdir i
559if eq c 47
560ghbyte c
561else
562ghenc c
563end
564end
565end
566ghbyte 63
567ghbyte 114
568ghbyte 101
569ghbyte 102
570ghbyte 61
571end
572if or eq kind 3 eq kind 4
573for i ulong get Ghlen 3
574ghbyte get Ghmeta add 832 i
575end
576end
577if ne get Ghbad 0 0
578gherror 8
579ret
580end
581put Gh 0 1
582end
583fn ghrefresh to void
584ghreset
585ghissue 5
586end
587note Intent is bounded word classification, not a canned prompt equality.
588fn ghvocab n ulong to ulong
589word = ulong 1
590at = ulong 0
591same = true
592for i ulong len Ghvoc
593c = get Ghvoc i
594if eq c 10
595if and same eq at n
596ret word
597end
598word = add word 1
599at = 0
600same = true
601else
602if ge at n
603same = false
604else
605if ne c get Ghword at
606same = false
607end
608end
609at = add at 1
610end
611end
612ret 0
613end
614fn ghask to bool
615ghreset
616put Ghreq 0 0
617put Gh 0 4
618n = get Inlen 0
619if or eq n 0 gt n 159
620ret false
621end
622bits = ulong 0
623at = ulong 0
624for i ulong add n 1
625c = uchar 32
626if lt i n
627c = get In i
628end
629if and ge c 65 le c 90
630c = add sub c 65 97
631end
632if and ge c 97 le c 122
633put Ghword at c
634at = add at 1
635else
636if or eq c 47 eq c 58
637ret false
638end
639if gt at 0
640w = ghvocab at
641if and ge w 1 le w 5
642bits = or bits 1
643end
644if and ge w 6 le w 16
645bits = or bits 2
646end
647if ge w 17
648ret false
649end
650at = 0
651end
652end
653end
654if ne bits 3
655ret false
656end
657ghissue 5
658ret true
659end
660note Decode only validated JSON strings, preserving UTF8. No renderer executes text.
661fn ghdbyte c ulong to void
662n = get Ghdn 0
663if ge n len Ghdec
664put Ghbad 0 1
665ret
666end
667put Ghdec n uchar c
668put Ghdn 0 add n 1
669end
670fn ghutf cp ulong to void
671if lt cp 128
672ghdbyte cp
673else
674if lt cp 2048
675ghdbyte add 192 shr cp 6
676ghdbyte add 128 and cp 63
677else
678if lt cp 65536
679ghdbyte add 224 shr cp 12
680ghdbyte add 128 and shr cp 6 63
681ghdbyte add 128 and cp 63
682else
683ghdbyte add 240 shr cp 18
684ghdbyte add 128 and shr cp 12 63
685ghdbyte add 128 and shr cp 6 63
686ghdbyte add 128 and cp 63
687end
688end
689end
690end
691fn ghdecode id ulong to bool
692put Ghdn 0 0
693if ge id get jcnt 0
694ret false
695end
696if ne get jtyp id 3
697ret false
698end
699put jpos 0 add get jbeg id 1
700stop = sub get jend id 1
701while lt get jpos 0 stop
702c = jtake
703if eq c 92
704c = jtake
705if eq c 117
706c = jhex
707if and ge c 55296 le c 56319
708put jpos 0 add get jpos 0 2
709v = jhex
710c = add 65536 add mul sub c 55296 1024 sub v 56320
711end
712ghutf c
713else
714if eq c 98
715c = 8
716end
717if eq c 102
718c = 12
719end
720if eq c 110
721c = 10
722end
723if eq c 114
724c = 13
725end
726if eq c 116
727c = 9
728end
729ghdbyte c
730end
731else
732ghdbyte c
733end
734if ne get Ghbad 0 0
735ret false
736end
737end
738ret true
739end
740fn ghwhich id ulong to ulong
741if not ghdecode id
742ret 0
743end
744word = ulong 1
745at = ulong 0
746same = true
747for i ulong len Ghkeys
748c = get Ghkeys i
749if eq c 10
750if and same eq at get Ghdn 0
751ret word
752end
753word = add word 1
754at = 0
755same = true
756else
757if ge at get Ghdn 0
758same = false
759else
760if ne c get Ghdec at
761same = false
762end
763end
764at = add at 1
765end
766end
767ret 0
768end
769fn ghnext id ulong to ulong
770stop = get jend id
771i = add id 1
772while lt i get jcnt 0
773if ge get jbeg i stop
774ret i
775end
776i = add i 1
777end
778ret i
779end
780note Lookup validates object and rejects duplicate decoded keys for each consumed field.
781fn ghfield obj ulong key ulong to ulong
782if ge obj get jcnt 0
783put Ghbad 0 1
784ret 4096
785end
786if ne get jtyp obj 1
787put Ghbad 0 1
788ret 4096
789end
790found = ulong 4096
791i = add obj 1
792while lt i get jcnt 0
793if ge get jbeg i get jend obj
794ret found
795end
796if eq ghwhich i key
797if ne found 4096
798put Ghbad 0 1
799end
800found = add i 1
801end
802i = ghnext add i 1
803end
804ret found
805end
806fn ghcopy id ulong off ulong cap ulong slot ulong to bool
807if not ghdecode id
808ret false
809end
810n = get Ghdn 0
811if gt n cap
812ret false
813end
814for i ulong n
815c = get Ghdec i
816if lt c 32
817ret false
818end
819put Ghmeta add off i c
820end
821put Ghlen slot n
822ret true
823end
824fn ghbranch to bool
825n = get Ghlen 1
826if eq n 0
827ret false
828end
829for i ulong n
830c = get Ghmeta add 64 i
831if or lt c 33 eq c 127
832ret false
833end
834end
835ret true
836end
837fn ghmetadata to bool
838if not ghcopy ghfield 0 1 0 64 0
839ret false
840end
841if eq get Ghlen 5 0
842ret false
843end
844if ne get Ghlen 0 get Ghlen 5
845ret false
846end
847for i ulong get Ghlen 5
848if ne get Ghmeta i get Ghmeta add 720 i
849ret false
850end
851end
852id = ghfield 0 4
853if eq id 4096
854ret false
855end
856if ne get jtyp id 6
857ret false
858end
859if not ghdecode ghfield 0 5
860ret false
861end
862if ne get Ghdn 0 add len Ghghu get Ghlen 5
863ret false
864end
865for i ulong len Ghghu
866if ne get Ghdec i get Ghghu i
867ret false
868end
869end
870for i ulong get Ghlen 5
871if ne get Ghdec add len Ghghu i get Ghmeta add 720 i
872ret false
873end
874end
875if not ghcopy ghfield 0 2 64 256 1
876ret false
877end
878if not ghbranch
879ret false
880end
881id = ghfield 0 3
882if eq id 4096
883ret false
884end
885if ne get jtyp id 7
886if not ghcopy id 320 512 2
887ret false
888end
889end
890ret eq get Ghbad 0 0
891end
892fn ghsha to bool
893if ne get Ghdn 0 40
894ret false
895end
896for i ulong 40
897c = get Ghdec i
898ok = or and ge c 48 le c 57 and ge c 97 le c 102
899if not ok
900ret false
901end
902end
903ret true
904end
905fn ghcommit to bool
906if not ghdecode ghfield 0 6
907ret false
908end
909if not ghsha
910ret false
911end
912for i ulong 40
913put Ghmeta add 832 i get Ghdec i
914end
915put Ghlen 3 40
916id = ghfield 0 7
917id = ghfield id 8
918id = ghfield id 9
919if not ghcopy id 896 64 4
920ret false
921end
922if ne get Ghlen 4 20
923ret false
924end
925for i ulong 20
926c = get Ghmeta add 896 i
927want = uchar 0
928if or eq i 4 eq i 7
929want = 45
930end
931if eq i 10
932want = 84
933end
934if or eq i 13 eq i 16
935want = 58
936end
937if eq i 19
938want = 90
939end
940if ne want 0
941if ne c want
942ret false
943end
944else
945if or lt c 48 gt c 57
946ret false
947end
948end
949end
950ret eq get Ghbad 0 0
951end
952note Paths must be relative immediate children of the requested directory.
953note No dot components, controls, backslash, URL metacharacters or percent escapes.
954fn ghpathok to bool
955n = get Ghdn 0
956base = get Gh 10
957if or eq n 0 gt n 511
958ret false
959end
960at = ulong 0
961if gt base 0
962if le n add base 1
963ret false
964end
965for i ulong base
966if ne get Ghdec i get Ghdir i
967ret false
968end
969end
970if ne get Ghdec base 47
971ret false
972end
973at = add base 1
974end
975size = sub n at
976if eq get Ghdec at 46
977if eq size 1
978ret false
979end
980if eq size 2
981if eq get Ghdec add at 1 46
982ret false
983end
984end
985end
986while lt at n
987c = get Ghdec at
988if or lt c 32 eq c 127
989ret false
990end
991if or or eq c 47 eq c 92 or eq c 58 eq c 37
992ret false
993end
994if or eq c 63 eq c 35
995ret false
996end
997at = add at 1
998end
999ret true
1000end
1001fn ghuint id ulong to ulong
1002if ge id get jcnt 0
1003put Ghbad 0 1
1004ret 0
1005end
1006if ne get jtyp id 4
1007put Ghbad 0 1
1008ret 0
1009end
1010v = ulong 0
1011p = get jbeg id
1012while lt p get jend id
1013c = get jin p
1014if or lt c 48 gt c 57
1015put Ghbad 0 1
1016ret 0
1017end
1018if gt v 1844674407370955161
1019put Ghbad 0 1
1020ret 0
1021end
1022if eq v 1844674407370955161
1023if gt c 53
1024put Ghbad 0 1
1025ret 0
1026end
1027end
1028v = add mul v 10 sub ulong c 48
1029p = add p 1
1030end
1031ret v
1032end
1033fn ghentry obj ulong to bool
1034if ge get Gh 8 256
1035ret false
1036end
1037if not ghdecode ghfield obj 10
1038ret false
1039end
1040if not ghpathok
1041ret false
1042end
1043n = get Ghdn 0
1044p = get Gh 9
1045if gt add add p n 40 len Ghpool
1046ret false
1047end
1048slot = mul get Gh 8 5
1049put Ghfiles slot p
1050put Ghfiles add slot 1 n
1051for i ulong n
1052put Ghpool add p i get Ghdec i
1053end
1054p = add p n
1055put Ghfiles add slot 4 p
1056if not ghdecode ghfield obj 6
1057ret false
1058end
1059if not ghsha
1060ret false
1061end
1062for i ulong 40
1063put Ghpool add p i get Ghdec i
1064end
1065put Gh 9 add p 40
1066put Ghfiles add slot 3 ghuint ghfield obj 12
1067if not ghdecode ghfield obj 11
1068ret false
1069end
1070typ = ulong 3
1071if eq get Ghdn 0 4
1072if and eq get Ghdec 0 102 eq get Ghdec 1 105
1073if and eq get Ghdec 2 108 eq get Ghdec 3 101
1074typ = 1
1075end
1076end
1077end
1078if eq get Ghdn 0 3
1079if and eq get Ghdec 0 100 eq get Ghdec 1 105
1080if eq get Ghdec 2 114
1081typ = 2
1082end
1083end
1084end
1085put Ghfiles add slot 2 typ
1086put Gh 8 add get Gh 8 1
1087ret eq get Ghbad 0 0
1088end
1089fn ghlisting to bool
1090if ne get jtyp 0 2
1091ret false
1092end
1093put Gh 8 0
1094put Gh 9 0
1095i = ulong 1
1096while lt i get jcnt 0
1097if not ghentry i
1098ret false
1099end
1100i = ghnext i
1101end
1102ret eq get Ghbad 0 0
1103end
1104fn ghrawutf p ulong n ulong to ulong
1105c = ulong get Ghbody p
1106p = add p 1
1107if lt c 128
1108if lt c 32
1109if not or or eq c 9 eq c 10 eq c 13
1110ret 262145
1111end
1112end
1113if eq c 127
1114ret 262145
1115end
1116ret p
1117end
1118k = ulong 0
1119lo = ulong 128
1120hi = ulong 191
1121if and ge c 194 le c 223
1122k = 1
1123end
1124if and ge c 224 le c 239
1125k = 2
1126if eq c 224
1127lo = 160
1128end
1129if eq c 237
1130hi = 159
1131end
1132end
1133if and ge c 240 le c 244
1134k = 3
1135if eq c 240
1136lo = 144
1137end
1138if eq c 244
1139hi = 143
1140end
1141end
1142if eq k 0
1143ret 262145
1144end
1145if gt add p k n
1146ret 262145
1147end
1148for i ulong k
1149c = ulong get Ghbody p
1150if or lt c lo gt c hi
1151ret 262145
1152end
1153p = add p 1
1154lo = 128
1155hi = 191
1156end
1157ret p
1158end
1159fn ghreadme n ulong to bool
1160note Validate plain UTF8 and reject binary controls; tabs/newlines are text.
1161p = ulong 0
1162while lt p n
1163p = ghrawutf p n
1164if gt p n
1165ret false
1166end
1167end
1168for i ulong n
1169put Ghread i get Ghbody i
1170end
1171put Gh 7 n
1172ret true
1173end
1174fn ghreply kind ulong status ulong size ulong gen ulong to bool
1175if or eq kind 0 ne kind get Ghreq 0
1176ret false
1177end
1178if ne gen get Ghreq 2
1179ret false
1180end
1181put Gh 3 status
1182if gt size get Ghreq 4
1183gherror 2
1184ret true
1185end
1186if and eq kind 3 eq status 404
1187put Gh 13 1
1188put Gh 7 0
1189put Ghat 2 get Gh 11
1190ghissue 4
1191ret true
1192end
1193if ne status 200
1194if or eq status 403 eq status 429
1195gherror 4
1196else
1197gherror 1
1198end
1199ret true
1200end
1201put Ghbad 0 0
1202ok = false
1203if eq kind 3
1204ok = ghreadme size
1205else
1206for i ulong size
1207put jin i get Ghbody i
1208end
1209if ne jparse size 0
1210gherror 3
1211ret true
1212end
1213if eq kind 1
1214ok = ghmetadata
1215end
1216if eq kind 2
1217ok = ghcommit
1218end
1219if eq kind 4
1220ok = ghlisting
1221end
1222if eq kind 5
1223ok = ghdiscover
1224end
1225end
1226if not ok
1227if eq kind 5
1228note A rejected listing leaves no repository name behind for the header to draw.
1229put Ghlen 5 0
1230put Ghlen 6 0
1231end
1232gherror 3
1233ret true
1234end
1235put Gh 12 gen
1236if eq kind 5
1237ghissue 1
1238ret true
1239end
1240put Ghat sub kind 1 get Gh 11
1241if lt kind 4
1242ghissue add kind 1
1243else
1244put Ghreq 0 0
1245put Gh 0 2
1246put Gh 5 0
1247put Gh 6 0
1248end
1249ret true
1250end