interplane.Get Omega
Read in your language

sovereign-intelligence

Front door to Drake Stapleton's sovereign stack.

Brought by drakestapleton

branch main Branches Tags History

sovereign-intelligence / harness / examples / loops.om

70 lines · 1401 bytes Raw Blame History
1note loops: while COND bound N (N 1..9223372036854775807), for i T K [bound N], break and continue
2note ---- output helpers: a function works on a global by naming it (a global is never an argument)
3global ob uchar 32
4note outb: write ob[off .. off+n) to stdout; a short write continues, 0 or an error exits 90
5note bound: every pass writes at least one byte and n <= 32, so at most 32 passes
6fn outb off ulong n ulong to void
7e = add off n
8p = off
9while lt p e bound 32
10k = write 1 ob p sub e p
11if le k 0
12exit 90
13end
14p = add p ulong k
15end
16end
17note putu: v in decimal, then a newline. A ulong has at most 20 digits, so 20 passes
18fn putu v ulong to void
19i = ulong 31
20put ob 31 10
21n = v
22while true bound 20
23i = sub i 1
24put ob i uchar add rem n 10 48
25n = div n 10
26if eq n 0
27break
28end
29end
30outb i sub 32 i
31end
32note putl: a signed value; -(v+1)+1 avoids negating the minimum, which would trap 1
33fn putl v long to void
34if lt v 0
35put ob 0 45
36outb 0 1
37putu add ulong neg add v 1 1
38ret
39end
40putu ulong v
41end
42note collatz: the step count to reach 1; the bound is a stated limit, not a proof, so exceeding it traps 4
43fn collatz n ulong to ulong
44x = n
45c = ulong 0
46while ne x 1 bound 1000
47c = add c 1
48if eq rem x 2 0
49x = div x 2
50continue
51end
52x = add mul x 3 1
53end
54ret c
55end
56fn main to int
57putu collatz 27
58s = ulong 0
59for i ulong 100
60if eq rem i 3 0
61continue
62end
63if gt i 50
64break
65end
66s = add s i
67end
68putu s
69ret 0
70end