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 / seed / omc / tests / float / mutate.om

126 lines · 1979 bytes Raw Blame History
1note Qualification-only exact-once source substitutions; argv1: 0 FMSUB, 1 unfused,
2note 2 lost decimal remainder, 3 ties down. Refuse absent/duplicate sites. Never a production compiler.
3global src uchar 1048576
4global needle uchar 256
5global repl uchar 256
6global used ulong 1
7global rlen ulong 1
8global arg uchar 8
9text n0 "emit or b vd"
10text r0 "emit or xor b 32768 vd"
11text n1 "emit or b vd"
12text r1 "fp_binop 35 at va vb vd\nfp_binop 33 at vd vc vd"
13text n2 "put fg_stk 0 fbmul 0 1"
14text r2 "put fg_stk 0 0"
15text n3 "if or ne sticky 0 eq and q 1 1"
16text r3 "if ne sticky 0"
17fn matches i ulong to bool
18for j ulong get used 0
19if ne get src add i j get needle j
20ret false
21end
22end
23ret true
24end
25fn srcout p ulong n ulong to void
26while lt p n
27r = write 1 src p sub n p
28if le r 0
29exit 94
30end
31p = add p ulong r
32end
33end
34fn main to int
35if ne argcnt 2
36ret 90
37end
38r = argread 1 arg 0 len arg
39if ne r 1
40ret 90
41end
42m = get arg 0
43if or lt m 48 gt m 51
44ret 90
45end
46if eq m 48
47put used 0 len n0
48put rlen 0 len r0
49for i ulong len n0
50put needle i get n0 i
51end
52for i ulong len r0
53put repl i get r0 i
54end
55end
56if eq m 49
57put used 0 len n1
58put rlen 0 len r1
59for i ulong len n1
60put needle i get n1 i
61end
62for i ulong len r1
63put repl i get r1 i
64end
65end
66if eq m 50
67put used 0 len n2
68put rlen 0 len r2
69for i ulong len n2
70put needle i get n2 i
71end
72for i ulong len r2
73put repl i get r2 i
74end
75end
76if eq m 51
77put used 0 len n3
78put rlen 0 len r3
79for i ulong len n3
80put needle i get n3 i
81end
82for i ulong len r3
83put repl i get r3 i
84end
85end
86n = ulong 0
87go = true
88while go
89if eq n len src
90ret 91
91end
92r = read 0 src n sub len src n
93if lt r 0
94ret 92
95end
96if eq r 0
97go = false
98else
99n = add n ulong r
100end
101end
102found = ulong 0
103at = ulong 0
104for i ulong n
105if le get used 0 sub n i
106if matches i
107found = add found 1
108at = i
109end
110end
111end
112if ne found 1
113ret 93
114end
115srcout 0 at
116p = ulong 0
117while lt p get rlen 0
118r = write 1 repl p sub get rlen 0 p
119if le r 0
120ret 94
121end
122p = add p ulong r
123end
124srcout add at get used 0 n
125ret 0
126end