interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / apps / interplane-forge / collab / co0form.om

205 lines · 3372 bytes Raw Blame History
1global gcfv uchar 65536
2global gcfvl ulong 1
3note Shared issue and preview form decoding and text validation.
4note cobfld t: decode field t into gcfv; its length, -1 when absent, -2 when over 65536 bytes
5fn cobfld t view uchar * to long
6n = get fbodyl 0
7i = ulong 0
8while lt i n bound 70000
9if cobfmat t i n
10ret cobfdec add add i len t 1 n
11end
12i = cobfnxt i n
13end
14ret -1
15end
16fn cobfmat t view uchar * i ulong n ulong to bool
17if gt add add i len t 1 n
18ret false
19end
20for k ulong len t bound 64
21if ne get fbody add i k get t k
22ret false
23end
24end
25ret eq get fbody add i len t 61
26end
27fn cobfnxt i ulong n ulong to ulong
28j = i
29while lt j n bound 70000
30if eq get fbody j 38
31ret add j 1
32end
33j = add j 1
34end
35ret n
36end
37fn cobfdec i ulong n ulong to long
38j = i
39o = ulong 0
40while lt j n bound 70000
41c = get fbody j
42if eq c 38
43break
44end
45if ge o 65536
46ret -2
47end
48j = add j 1
49if eq c 43
50c = uchar 32
51end
52if eq c 37
53c = cobpct j n
54if lt add j 1 n
55j = add j 2
56end
57end
58put gcfv o c
59o = add o 1
60end
61put gcfvl 0 o
62ret long o
63end
64fn cobpct j ulong n ulong to uchar
65if ge add j 1 n
66ret uchar 37
67end
68a = fhexv get fbody j
69b = fhexv get fbody add j 1
70if or lt a 0 lt b 0
71ret uchar 37
72end
73ret uchar add mul a 16 b
74end
75note ---- text checks on gcfv[0,n)
76note cotxtok n ml: CRLF and lone CR become LF; then the text must be UTF-8 without NUL or control
77note bytes (ml: tab and LF allowed; else none); trailing blanks and leading newlines are trimmed
78note (single line: leading blanks too). The cleaned length, or -1 when the text is refused.
79fn cotxtok n ulong ml bool to long
80m = cocrlf n
81if eq cowutf8 m ml false
82ret -1
83end
84e = m
85while gt e 0 bound 70000
86c = get gcfv sub e 1
87if and ne c 32 and ne c 9 ne c 10
88break
89end
90e = sub e 1
91end
92s = ulong 0
93while lt s e bound 70000
94c = get gcfv s
95if and ne c 10 or ml and ne c 32 ne c 9
96break
97end
98s = add s 1
99end
100if gt s 0
101for k ulong sub e s bound 70000
102put gcfv k get gcfv add s k
103end
104end
105ret long sub e s
106end
107fn cocrlf n ulong to ulong
108o = ulong 0
109for i ulong n bound 70000
110c = get gcfv i
111if eq c 13
112c = uchar 10
113if lt add i 1 n
114if eq get gcfv add i 1 10
115c = uchar 0
116end
117end
118end
119if ne c 0
120put gcfv o c
121o = add o 1
122else
123if ne get gcfv i 13
124put gcfv o c
125o = add o 1
126end
127end
128end
129ret o
130end
131note cowutf8 n ml: well-formed UTF-8 (no overlong forms, surrogates or code points over U+10FFFF), no
132note NUL, C0 control or DEL byte except tab and LF when ml
133fn cowutf8 n ulong ml bool to bool
134i = ulong 0
135while lt i n bound 70000
136c = get gcfv i
137if lt c 128
138if eq coctlok c ml false
139ret false
140end
141i = add i 1
142else
143k = coulen i n
144if eq k 0
145ret false
146end
147i = add i k
148end
149end
150ret true
151end
152fn coctlok c uchar ml bool to bool
153if eq c 127
154ret false
155end
156if ge c 32
157ret true
158end
159if and ml or eq c 9 eq c 10
160ret true
161end
162ret false
163end
164note coulen i n: byte length of the multi-byte sequence at gcfv[i], 0 when it is malformed
165fn coulen i ulong n ulong to ulong
166c = get gcfv i
167k = ulong 0
168lo = uchar 128
169hi = uchar 191
170if and ge c 194 le c 223
171k = ulong 2
172end
173if and ge c 224 le c 239
174k = ulong 3
175if eq c 224
176lo = uchar 160
177end
178if eq c 237
179hi = uchar 159
180end
181end
182if and ge c 240 le c 244
183k = ulong 4
184if eq c 240
185lo = uchar 144
186end
187if eq c 244
188hi = uchar 143
189end
190end
191if or eq k 0 gt add i k n
192ret ulong 0
193end
194d = get gcfv add i 1
195if or lt d lo gt d hi
196ret ulong 0
197end
198for j ulong sub k 2 bound 2
199d = get gcfv add add i 2 j
200if or lt d 128 gt d 191
201ret ulong 0
202end
203end
204ret k
205end