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 / runtime.om

510 lines · 9938 bytes Raw Blame History
1note Shared native site runtime; concatenate after the unit's leading om2.
2note API sr_raw/sr_bytes write exact bytes; sr_esc escapes HTML text and quoted attributes.
3note sr_open creates checked parents and truncates a file; sr_close flushes and restores stdout.
4note sofd is the current output descriptor after sr_init or sr_open. Never mutate it without sr_flush.
5note sr_copy preserves bytes, not mode; refuses same inode before truncation. All I/O errors exit 70.
6note Paths use the host's 4095-byte limit; zero bytes and empty paths are refused by name.
7note Streaming operations allow 999998 read attempts, then refuse IO_LIMIT rather than trap/truncate.
8note Integration cases (NOT_RUN): nested parents; existing regular-file parent refusal; missing source;
9note same-inode copy refusal including hardlink; empty and multi-block copy; /dev/full write refusal;
10note partial pipe reads/writes; empty strings; equality length mismatch; escaping ampersand/angles/quotes.
11text srepre "site runtime: "
12text srenl "\n"
13text srewr "WRITE"
14text srerd "READ"
15text srecl "CLOSE"
16text sreop "OPEN"
17text sremk "MKDIR"
18text srepa "PATH"
19text srebo "BOUNDS"
20text ghforge "https://interplane.io/drakestapleton/"
21text sreli "IO_LIMIT"
22text sresa "COPY_SAME_FILE"
23text srest "STAT"
24text sretr "TRUNCATE"
25text sreamp "&"
26text srelt "<"
27text sregt ">"
28text srequ """
29text sreapo "'"
30text srehash "#"
31global sofd int 1
32global srb uchar 16384
33global srn ulong 1
34global sri uchar 1
35note srnoh[0] = 1 while a Markdown link URL is written: its # stays a byte, as in r4.
36global srnoh uchar 1
37fn sr_diag s view uchar * to void
38p = ulong 0
39while lt p len s bound 4096
40k = write 2 s p sub len s p
41if le k 0
42exit 70
43end
44p = add p ulong k
45end
46end
47fn sr_fail why view uchar * to void
48sr_diag srepre
49sr_diag why
50sr_diag srenl
51exit 70
52end
53fn sr_init to void
54if eq get sri 0 0
55put sofd 0 1
56put sri 0 1
57end
58end
59fn sr_flush to void
60sr_init
61p = ulong 0
62while lt p get srn 0 bound 16384
63k = write get sofd 0 srb p sub get srn 0 p
64if le k 0
65sr_fail srewr
66end
67p = add p ulong k
68end
69put srn 0 0
70end
71fn sr_byte c uchar to void
72if eq get srn 0 len srb
73sr_flush
74end
75put srb get srn 0 c
76put srn 0 add get srn 0 1
77end
78fn sr_write fd int s view uchar * off ulong cnt ulong to void
79note A chunk is at most 65536 bytes, so even one-byte progress respects the loop bound.
80p = ulong 0
81while lt p cnt bound 65536
82k = write fd s add off p sub cnt p
83if le k 0
84sr_fail srewr
85end
86p = add p ulong k
87end
88end
89fn sr_bytes s view uchar * off ulong cnt ulong to void
90if gt off len s
91sr_fail srebo
92end
93if gt cnt sub len s off
94sr_fail srebo
95end
96note Compiler array limit is 16777216 bytes. Chunking avoids the million-iteration guard.
97if gt cnt 16777216
98sr_fail srebo
99end
100p = ulong 0
101while lt p cnt bound 16384
102n = sub cnt p
103if ge n len srb
104sr_flush
105if gt n 65536
106n = 65536
107end
108sr_write get sofd 0 s add off p n
109p = add p n
110else
111for j ulong n
112sr_byte get s add add off p j
113end
114p = add p n
115end
116end
117end
118fn sr_raw s view uchar * to void
119sr_bytes s 0 len s
120end
121fn sr_escape c uchar to void
122if eq c 38
123sr_raw sreamp
124ret
125end
126if eq c 60
127sr_raw srelt
128ret
129end
130if eq c 62
131sr_raw sregt
132ret
133end
134if eq c 34
135sr_raw srequ
136ret
137end
138if eq c 39
139sr_raw sreapo
140ret
141end
142sr_byte c
143end
144note sr_escref: c escaped as sr_escape does, except the # of a reference (# then the digit d,
145note as in #775) is #, so page text has no # followed by digits; it renders the same.
146fn sr_escref c uchar d uchar to void
147if eq c 35
148if and ge d 48 eq get srnoh 0 0
149if lt d 58
150sr_raw srehash
151ret
152end
153end
154end
155sr_escape c
156end
157fn sr_esc s view uchar * to void
158p = ulong 0
159while lt p len s bound 16384
160n = sub len s p
161if gt n 65536
162n = 65536
163end
164for j ulong n
165ec8 = get s add p j
166ed8 = ec8
167ek8 = add add p j 1
168if lt ek8 len s
169ed8 = get s ek8
170end
171sr_escref ec8 ed8
172end
173p = add p n
174end
175end
176fn sr_equal a view uchar * b view uchar * to bool
177if ne len a len b
178ret false
179end
180p = ulong 0
181while lt p len a bound 16384
182n = sub len a p
183if gt n 65536
184n = 65536
185end
186for j ulong n
187if ne get a add p j get b add p j
188ret false
189end
190end
191p = add p n
192end
193ret true
194end
195fn sr_num n ulong to void
196buf = new uchar 20 0
197p = ulong 20
198while true bound 20
199p = sub p 1
200put buf p uchar add rem n 10 48
201n = div n 10
202if eq n 0
203break
204end
205end
206sr_bytes buf p sub ulong 20 p
207end
208fn sr_path path view uchar * to void
209if or eq len path 0 gt len path 4095
210sr_fail srepa
211end
212for j ulong len path
213if eq get path j 0
214sr_fail srepa
215end
216end
217end
218fn sr_fclose fd int to void
219k = fclose fd
220if ne k 0
221sr_fail srecl
222end
223end
224fn sr_dir path view uchar * n ulong to void
225k = makedir path 0 n 493
226if and lt k 0 ne k -17
227sr_fail sremk
228end
229note EEXIST alone is not success: Linux AArch64 O_DIRECTORY (16384) proves a directory.
230k = fopen path 0 n 16384 0
231if lt k 0
232sr_fail sremk
233end
234sr_fclose int k
235end
236fn sr_parents path view uchar * to void
237sr_path path
238for j ulong len path
239if gt j 0
240if eq get path j 47
241sr_dir path j
242end
243end
244end
245end
246fn sr_open path view uchar * to void
247sr_close
248sr_parents path
249k = fopen path 0 len path 577 420
250if lt k 0
251sr_fail sreop
252end
253put sofd 0 int k
254put sri 0 2
255end
256fn sr_close to void
257sr_flush
258if eq get sri 0 2
259sr_fclose get sofd 0
260end
261put sofd 0 1
262put sri 0 1
263end
264fn sr_stream fd int dest int to void
265buf = new uchar 65536 0
266for tries ulong 999998
267k = read fd buf 0 len buf
268if lt k 0
269sr_fail srerd
270end
271if eq k 0
272ret
273end
274sr_write dest buf 0 ulong k
275end
276sr_fail sreli
277end
278fn sr_file path view uchar * to void
279sr_path path
280k = fopen path 0 len path 0 0
281if lt k 0
282sr_fail sreop
283end
284sr_flush
285sr_stream int k get sofd 0
286sr_fclose int k
287end
288fn sr_distinct src int dst int to void
289a = new uchar 128 0
290b = new uchar 128 0
291k = fstat src a 0 len a
292if ne k 0
293sr_fail srest
294end
295k = fstat dst b 0 len b
296if ne k 0
297sr_fail srest
298end
299note Linux AArch64 stat begins with st_dev and st_ino, each eight bytes.
300same = true
301for j ulong 16
302if ne get a j get b j
303same = false
304end
305end
306if same
307sr_fail sresa
308end
309end
310fn sr_copy src view uchar * dst view uchar * to void
311sr_path src
312sr_parents dst
313fd = fopen src 0 len src 0 0
314if lt fd 0
315sr_fail sreop
316end
317od = fopen dst 0 len dst 65 420
318if lt od 0
319sr_fail sreop
320end
321sr_distinct int fd int od
322k = ftrunc int od 0
323if ne k 0
324sr_fail sretr
325end
326sr_stream int fd int od
327sr_fclose int fd
328sr_fclose int od
329end
330
331note Public project navigation uses INTERPLANE; GitHub source provenance in code examples is retained as text.
332text ghhost "https://github.com/"
333text ghhttp "http://github.com/"
334text ghexpl "https://interplane.io/explore"
335text ghslash "/"
336text ghpull "/pull"
337text ghissue "/issues"
338text ghrel "/releases"
339text ghpatch "/patches"
340text ghblob "/blob/"
341text ghtree "/tree/"
342text ghcommit "/commit/"
343text ghcs "/commits/"
344text ghdev "aien-dev"
345text ghspark "aien-spark"
346text ghdrake "drakestapleton"
347text ghmap "omega|omega-mv\naien-architecture|aien-architecture-mv\naien-sovereign-core|aien-sovereign-core-mv\naien-protocols|aien-protocols-mv\nbenchmarks|benchmarks-mv\ninterplane|interplane-mv\nphysics|physics-mv\naegis-runtime|aegis-runtime-mv\nspark-rsi|spark-rsi-mv\n"
348fn gh_prefix value view uchar * to ulong
349if ge len value len ghhost
350if sr_equal part value 0 len ghhost ghhost
351ret len ghhost
352end
353end
354if ge len value len ghhttp
355if sr_equal part value 0 len ghhttp ghhttp
356ret len ghhttp
357end
358end
359ret 0
360end
361fn gh_repo value view uchar * to void
362p = ulong 0
363while lt p len ghmap bound 4096
364q = p
365while lt q len ghmap bound 4096
366if eq get ghmap q 124
367break
368end
369q = add q 1
370end
371z = add q 1
372while lt z len ghmap bound 4096
373if eq get ghmap z 10
374break
375end
376z = add z 1
377end
378if sr_equal value part ghmap p sub q p
379sr_esc part ghmap add q 1 sub z add q 1
380ret
381end
382p = add z 1
383end
384sr_esc value
385end
386fn gh_tail value view uchar * term view uchar * to bool
387if lt len value len term
388ret false
389end
390ret sr_equal part value 0 len term term
391end
392fn gxextern value view uchar * to bool
393p = gh_prefix value
394if eq p 0
395ret false
396end
397q = p
398while lt q len value bound 4096
399if eq get value q 47
400break
401end
402q = add q 1
403end
404ret not or sr_equal part value p sub q p ghdev or sr_equal part value p sub q p ghspark sr_equal part value p sub q p ghdrake
405end
406fn gh_numeric value view uchar * pos ulong to bool
407if ge pos len value
408ret false
409end
410seen = false
411p = pos
412while lt p len value bound 4096
413c = get value p
414if or eq c 35 eq c 63
415break
416end
417if or lt c 48 gt c 57
418ret false
419end
420seen = true
421p = add p 1
422end
423ret seen
424end
425text ghisnum "/issues/"
426text ghplnum "/pull/"
427fn gh_forge_url value view uchar * to void
428p = len ghforge
429while lt p len value bound 4096
430if eq get value p 47
431break
432end
433p = add p 1
434end
435if lt p len value
436if and gh_tail part value p sub len value p ghisnum gh_numeric value add p len ghisnum
437sr_esc part value 0 p
438sr_raw ghissue
439ret
440end
441if and gh_tail part value p sub len value p ghplnum gh_numeric value add p len ghplnum
442sr_esc part value 0 p
443sr_raw ghpatch
444ret
445end
446end
447sr_esc value
448end
449fn gh_url value view uchar * to void
450p = gh_prefix value
451if eq p 0
452if gh_tail value ghforge
453gh_forge_url value
454else
455sr_esc value
456end
457ret
458end
459q = p
460while lt q len value bound 4096
461if eq get value q 47
462break
463end
464q = add q 1
465end
466if eq q len value
467sr_raw ghexpl
468ret
469end
470if not or sr_equal part value p sub q p ghdev or sr_equal part value p sub q p ghspark sr_equal part value p sub q p ghdrake
471sr_esc value
472ret
473end
474p = add q 1
475q = p
476while lt q len value bound 4096
477if or eq get value q 47 or eq get value q 35 eq get value q 63
478break
479end
480q = add q 1
481end
482if eq p q
483sr_raw ghexpl
484ret
485end
486sr_raw ghforge
487gh_repo part value p sub q p
488if ge q len value
489ret
490end
491if or gh_tail part value q sub len value q ghblob gh_tail part value q sub len value q ghtree
492sr_esc part value q sub len value q
493ret
494end
495if or gh_tail part value q sub len value q ghcommit gh_tail part value q sub len value q ghcs
496sr_esc part value q sub len value q
497ret
498end
499if gh_tail part value q sub len value q ghpull
500sr_raw ghpatch
501ret
502end
503if gh_tail part value q sub len value q ghissue
504sr_raw ghissue
505ret
506end
507if gh_tail part value q sub len value q ghrel
508sr_raw ghrel
509end
510end