interplane.Get Omega
Read in your language

interplane-forge

INTERPLANE Forge

Brought by drakestapleton

branch main Branches Tags History

interplane-forge / collab / co1json.om

350 lines · 6770 bytes Raw Blame History
1note collab/co1json.om (ForgePatches): read the flat JSON of one Radicle COB action blob held in fxo[a,e).
2note Radicle writes each action as compact JSON on one line, so a scanner over fxo is enough:
3note cokey finds a key of an object, coseq compares a string value, cospool decodes a string into gcpool.
4note Every function stops at e, so a malformed blob only ends the scan; it never reads past the line.
5text tccomma ", "
6global gcpool uchar 4194304
7global gcpl ulong 1
8note gcov: 1 when the object loaded by coload (collab/co2cob.om) is not whole in memory: a change past
9note the 512th, a revision past the 64th, a comment past the 512th, a review past the 64th, a merge past
10note the 16th, an index entry past the 4096th, a string that did not fit gcpool, or a git output that did
11note not fit fxo. coreset clears it. The page of one object answers the whole 500 of fincut then; a
12note list row built from such an object is still built from the part that was read.
13global gcov ulong 1
14note cows: index of the first byte at or after p that is not white space (or e)
15fn cows p ulong e ulong to ulong
16q = p
17while lt q e bound 16777216
18if gt get fxo q 32
19ret q
20end
21q = add q 1
22end
23ret e
24end
25note costre: p is at an opening quote; the index just after the closing quote (or e)
26fn costre p ulong e ulong to ulong
27q = add p 1
28while lt q e bound 16777216
29c = get fxo q
30if eq c 92
31q = add q 2
32continue
33end
34if eq c 34
35ret add q 1
36end
37q = add q 1
38end
39ret e
40end
41note coval: skip one JSON value starting at p; the index just after it (or e)
42fn coval p ulong e ulong to ulong
43if ge p e
44ret e
45end
46if eq get fxo p 34
47ret costre p e
48end
49d = ulong 0
50q = p
51while lt q e bound 16777216
52c = get fxo q
53if eq c 34
54q = costre q e
55continue
56end
57if or eq c 123 eq c 91
58d = add d 1
59end
60if or eq c 125 eq c 93
61if eq d 0
62ret q
63end
64d = sub d 1
65if eq d 0
66ret add q 1
67end
68end
69if eq d 0
70if eq c 44
71ret q
72end
73end
74q = add q 1
75end
76ret e
77end
78note coraweq: fxo[a,b) equals k byte for byte
79fn coraweq a ulong b ulong k view uchar * to bool
80if lt b a
81ret false
82end
83if ne sub b a len k
84ret false
85end
86for i ulong len k
87if ne get fxo add a i get k i
88ret false
89end
90end
91ret true
92end
93note cokey: the object starting at a (white space allowed); the index of the value of key k, or e
94fn cokey a ulong e ulong k view uchar * to ulong
95p = cows a e
96if ge p e
97ret e
98end
99if ne get fxo p 123
100ret e
101end
102note one pass per key, and a key with its value takes 5 bytes or more ("":0,), so the passes are
103note at most (e - a) / 5 with e - a at most len fxo = 16777216. The bound was 1048576: an object of
104note 5 MB with 1,048,577 keys was trap 4 (exit 104).
105p = cows add p 1 e
106while lt p e bound 16777216
107if ne get fxo p 34
108ret e
109end
110q = costre p e
111m = coraweq add p 1 sub q 1 k
112p = cows q e
113if ge p e
114ret e
115end
116if ne get fxo p 58
117ret e
118end
119p = cows add p 1 e
120if m
121ret p
122end
123p = cows coval p e e
124if ge p e
125ret e
126end
127if ne get fxo p 44
128ret e
129end
130p = cows add p 1 e
131end
132ret e
133end
134note coseq: the value at p is a string whose raw bytes equal t
135fn coseq p ulong e ulong t view uchar * to bool
136if ge p e
137ret false
138end
139if ne get fxo p 34
140ret false
141end
142q = costre p e
143ret coraweq add p 1 sub q 1 t
144end
145note cohexat: the value at p is a string of exactly 40 lowercase hex digits (a git object id)
146fn cohexat p ulong e ulong to bool
147if gt add p 42 e
148ret false
149end
150if ne get fxo p 34
151ret false
152end
153if ne get fxo add p 41 34
154ret false
155end
156for i ulong 40
157c = get fxo add p add i 1
158if cohexc c
159continue
160end
161ret false
162end
163ret true
164end
165note cohexc: a lowercase hex digit
166fn cohexc c uchar to bool
167if and ge c 48 le c 57
168ret true
169end
170ret and ge c 97 le c 102
171end
172note cohexv: value of a hex digit (either case), 16 when it is not one
173fn cohexv c uchar to ulong
174if and ge c 48 le c 57
175ret sub ulong c 48
176end
177if and ge c 97 le c 102
178ret sub ulong c 87
179end
180if and ge c 65 le c 70
181ret sub ulong c 55
182end
183ret ulong 16
184end
185note ---- string decoding into gcpool (cleared per COB load by coreset)
186fn copoolc c uchar to void
187n = get gcpl 0
188if lt n len gcpool
189put gcpool n c
190put gcpl 0 add n 1
191else
192put gcov 0 1
193end
194end
195fn copoolt t view uchar * to void
196for i ulong len t
197copoolc get t i
198end
199end
200note coutf8: append code point u as UTF-8 (a lone surrogate becomes U+FFFD)
201fn coutf8 u ulong to void
202v = u
203if and ge v 55296 le v 57343
204v = ulong 65533
205end
206if lt v 128
207copoolc uchar v
208ret
209end
210if lt v 2048
211copoolc uchar or 192 shr v 6
212copoolc uchar or 128 and v 63
213ret
214end
215if lt v 65536
216copoolc uchar or 224 shr v 12
217copoolc uchar or 128 and shr v 6 63
218copoolc uchar or 128 and v 63
219ret
220end
221copoolc uchar or 240 and shr v 18 7
222copoolc uchar or 128 and shr v 12 63
223copoolc uchar or 128 and shr v 6 63
224copoolc uchar or 128 and v 63
225end
226note cohex4: the value of 4 hex digits at p, or 1048576 when they are not hex
227fn cohex4 p ulong e ulong to ulong
228if gt add p 4 e
229ret ulong 1048576
230end
231v = ulong 0
232for i ulong 4
233d = cohexv get fxo add p i
234if gt d 15
235ret ulong 1048576
236end
237v = or shl v 4 d
238end
239ret v
240end
241note couesc: q is at the backslash of a \u escape; append it (joining a surrogate pair); next index
242fn couesc q ulong e ulong to ulong
243u = cohex4 add q 2 e
244if gt u 65535
245ret e
246end
247r = add q 6
248if and ge u 55296 le u 56319
249if le add r 6 e
250if and eq get fxo r 92 eq get fxo add r 1 117
251w = cohex4 add r 2 e
252if and ge w 56320 le w 57343
253u = add 65536 add shl sub u 55296 10 sub w 56320
254r = add r 6
255end
256end
257end
258end
259coutf8 u
260ret r
261end
262note coesc: q is at a backslash; append the escaped byte(s); the next index
263fn coesc q ulong e ulong to ulong
264if ge add q 1 e
265ret e
266end
267c = get fxo add q 1
268if eq c 110
269copoolc uchar 10
270ret add q 2
271end
272if eq c 116
273copoolc uchar 9
274ret add q 2
275end
276if eq c 114
277copoolc uchar 13
278ret add q 2
279end
280if eq c 98
281copoolc uchar 8
282ret add q 2
283end
284if eq c 102
285copoolc uchar 12
286ret add q 2
287end
288if eq c 117
289ret couesc q e
290end
291copoolc c
292ret add q 2
293end
294note cospool: decode the string at p into gcpool; the number of bytes appended (0 when not a string)
295fn cospool p ulong e ulong to ulong
296if ge p e
297ret 0
298end
299if ne get fxo p 34
300ret 0
301end
302s = get gcpl 0
303q = add p 1
304while lt q e bound 16777216
305c = get fxo q
306if eq c 34
307break
308end
309if eq c 92
310q = coesc q e
311continue
312end
313copoolc c
314q = add q 1
315end
316ret sub get gcpl 0 s
317end
318note coslist: p at an array of strings; append them to gcpool joined by ", "; the bytes appended
319fn coslist p ulong e ulong to ulong
320s = get gcpl 0
321if ge p e
322ret 0
323end
324if ne get fxo p 91
325ret 0
326end
327note one pass per string, 3 bytes or more each ("",), inside fxo (16777216 bytes). The bound was
328note 1048576: an array of 1,048,578 strings (3 MB) was trap 4.
329q = cows add p 1 e
330k = ulong 0
331while lt q e bound 16777216
332if ne get fxo q 34
333break
334end
335if gt k 0
336copoolt tccomma
337end
338x = cospool q e
339k = add k 1
340q = cows costre q e e
341if ge q e
342break
343end
344if ne get fxo q 44
345break
346end
347q = cows add q 1 e
348end
349ret sub get gcpl 0 s
350end