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 / protocol / omnet / om / quantity / mutate.om

95 lines · 1699 bytes Raw Blame History
1note Test-only source transformer. stdin quantity.om, argument a or m; stdout one guard removed.
2note Requires exactly one exact guard occurrence, bounded input, complete writes. Never production code.
3global src uchar 16384
4text aguard "if gt get b val sub get a cap get a val\nret int 3\nend\n"
5text mguard "if ne get a val ulong 0\nif gt get b val div get a cap get a val\nret int 3\nend\nend\n"
6
7fn match at ulong kind uchar to bool
8if eq kind uchar 97
9for i ulong len aguard
10if ne get src add at i get aguard i
11ret bool 0
12end
13end
14else
15for i ulong len mguard
16if ne get src add at i get mguard i
17ret bool 0
18end
19end
20end
21ret bool 1
22end
23
24fn emit at ulong size ulong to bool
25pos = ulong 0
26while lt pos size bound 16384
27n = write int 1 src add at pos sub size pos
28if le n long 0
29ret bool 0
30end
31pos = add pos ulong n
32end
33ret bool 1
34end
35
36fn load to long
37size = ulong 0
38while lt size len src bound 16384
39n = read int 0 src size sub len src size
40if lt n long 0
41ret long -1
42end
43if eq n long 0
44ret long size
45end
46size = add size ulong n
47end
48ret long -1
49end
50
51fn main to int
52arg = new uchar 1 uchar 0
53if ne argcnt long 2
54ret int 2
55end
56n = argread ulong 1 arg ulong 0 ulong 1
57if ne n long 1
58ret int 2
59end
60kind = get arg 0
61if and ne kind uchar 97 ne kind uchar 109
62ret int 2
63end
64n = load
65if lt n long 0
66ret int 3
67end
68size = ulong n
69width = len aguard
70if eq kind uchar 109
71width = len mguard
72end
73if lt size width
74ret int 4
75end
76hits = ulong 0
77found = ulong 0
78for i ulong add sub size width ulong 1
79if match i kind
80hits = add hits ulong 1
81found = i
82end
83end
84if ne hits ulong 1
85ret int 4
86end
87if not emit ulong 0 found
88ret int 5
89end
90found = add found width
91if not emit found sub size found
92ret int 5
93end
94ret int 0
95end