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 / train / omega-llm / tools / controller / normalize.om

166 lines · 3540 bytes Raw Blame History
1note normalize PROMPT [BODY]. Rewrite the signature or restore a generated body by identifier.
2global cpwordstart ulong 16
3global cpwordlen ulong 16
4global cpwords ulong 1
5global cpnames ulong 3
6text nx "x"
7text ny "y"
8text na "a"
9text nb "b"
10text ni "items"
11text nc "count"
12text nd "data"
13text nn "n"
14fn cpfile arg ulong buf edit uchar * to ulong
15wdpclr
16wdpa arg
17n = wdload
18if or lt n 1 ge ulong n len buf
19exit 72
20end
21for i ulong ulong n
22put buf i get wdsrc i
23end
24ret ulong n
25end
26fn cpid c uchar to bool
27ret or eq c 95 or and ge c 48 le c 57 or and ge c 65 le c 90 and ge c 97 le c 122
28end
29fn cpwordend buf view uchar * i ulong n ulong to ulong
30while lt i n bound 8192
31if not cpid get buf i
32break
33end
34i = add i 1
35end
36ret i
37end
38fn samebytes a view uchar * b view uchar * to bool
39if ne len a len b
40ret false
41end
42for i ulong len a
43if ne get a i get b i
44ret false
45end
46end
47ret true
48end
49global aliaslen ulong 2
50fn setalias aliases edit uchar * k ulong v view uchar * to void
51put aliaslen k len v
52for j ulong len v
53put aliases add mul k 32 j get v j
54end
55end
56fn parsesig cprompt view uchar * n ulong to void
57i = ulong 0
58while lt i n bound 4096
59if eq get cprompt i 10
60break
61end
62i = add i 1
63end
64i = add i 1
65k = ulong 0
66while lt i n bound 4096
67if cpid get cprompt i
68s = i
69i = cpwordend cprompt i n
70if ge k 16
71exit 72
72end
73put cpwordstart k s
74put cpwordlen k sub i s
75k = add k 1
76else
77i = add i 1
78end
79end
80if and ne k 8 ne k 10
81exit 72
82end
83put cpwords 0 k
84put cpnames 0 2
85put cpnames 1 sub k 4
86end
87fn choosealiases cprompt view uchar * aliases edit uchar * to void
88k = get cpwords 0
89second = false
90if eq k 10
91second = and samebytes part cprompt get cpwordstart get cpnames 0 get cpwordlen get cpnames 0 ni samebytes part cprompt get cpwordstart get cpnames 1 get cpwordlen get cpnames 1 nc
92else
93second = and samebytes part cprompt get cpwordstart get cpnames 0 get cpwordlen get cpnames 0 nx samebytes part cprompt get cpwordstart get cpnames 1 get cpwordlen get cpnames 1 ny
94end
95if eq k 10
96if second
97setalias aliases 0 nd
98setalias aliases 1 nn
99else
100setalias aliases 0 ni
101setalias aliases 1 nc
102end
103else
104if second
105setalias aliases 0 na
106setalias aliases 1 nb
107else
108setalias aliases 0 nx
109setalias aliases 1 ny
110end
111end
112end
113fn restoretoken cprompt view uchar 4096 aliases view uchar 64 v view uchar * to void
114if samebytes v part aliases mul ulong 32 0 get aliaslen 0
115wdot part cprompt get cpwordstart get cpnames 0 get cpwordlen get cpnames 0
116else
117if samebytes v part aliases mul ulong 32 1 get aliaslen 1
118wdot part cprompt get cpwordstart get cpnames 1 get cpwordlen get cpnames 1
119else
120if or samebytes v part cprompt get cpwordstart get cpnames 0 get cpwordlen get cpnames 0 samebytes v part cprompt get cpwordstart get cpnames 1 get cpwordlen get cpnames 1
121exit 75
122end
123wdot v
124end
125end
126end
127fn restorebody cprompt view uchar 4096 aliases view uchar 64 a view uchar * to void
128i = ulong 0
129while lt i len a bound 8192
130if cpid get a i
131s = i
132i = cpwordend a i len a
133restoretoken cprompt aliases part a s sub i s
134else
135wdoc ulong get a i
136i = add i 1
137end
138end
139end
140fn main to int
141if and ne argcnt 2 ne argcnt 3
142ret 2
143end
144cprompt = new uchar 4096 0
145aliases = new uchar 64 0
146a = new uchar 8192 0
147n = cpfile 1 cprompt
148parsesig cprompt n
149choosealiases cprompt aliases
150if eq argcnt 3
151an = cpfile 2 a
152restorebody cprompt aliases part a 0 an
153else
154s = ulong 0
155for j ulong 2
156k = get cpnames j
157off = get cpwordstart k
158wdot part cprompt s sub off s
159wdot part aliases mul ulong 32 j get aliaslen j
160s = add off get cpwordlen k
161end
162wdot part cprompt s sub n s
163end
164wdoflush 1
165ret 0
166end