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 / gpu / nvidia / om / components / pathcopy.om

84 lines · 1391 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2om2
3note Bounded path copy. Never reads past len src. The first 0 ends the scan and is written.
4note src and dst bounds are independent. Empty source is a refusal. A nonempty NULL is refused by the binding.
5fn pathbyte value ulong to ulong
6if or and ge value 97 le value 122 and ge value 65 le value 90
7ret value
8end
9if and ge value 48 le value 57
10ret value
11end
12if or or or eq value 46 eq value 95 eq value 45 eq value 47
13ret value
14end
15if or or or eq value 43 eq value 44 eq value 61 eq value 64
16ret value
17end
18if or eq value 58 eq value 126
19ret value
20end
21ret 256
22end
23fn pathstep state ulong value ulong count ulong cap ulong to ulong
24if eq value 0
25if or eq count 0 eq state 2
26ret 4
27end
28ret 5
29end
30if ge count cap
31ret 4
32end
33if ge count sub cap 1
34ret 4
35end
36if eq pathbyte value 256
37ret 4
38end
39if eq value 47
40if eq state 2
41ret 4
42end
43ret 0
44end
45if eq value 46
46if lt state 2
47ret add state 1
48end
49end
50ret 3
51end
52export fn pathlen a view uchar * to ulong
53ensures le result len a
54n = len a
55for i ulong n
56b = get a i
57if eq b 0
58ret i
59end
60end
61ret n
62end
63export fn pathcopy src view uchar * dst edit uchar * to ulong
64ensures le result 1
65n = len src
66cap = len dst
67if eq n 0
68ret 0
69end
70state = ulong 0
71for i ulong n
72b = get src i
73next = pathstep state ulong b i cap
74if eq next 4
75ret 0
76end
77put dst i b
78if eq next 5
79ret 1
80end
81state = next
82end
83ret 0
84end