interplane.Get Omega
Read in your language

aienos.com

Source of www.aienos.com, served from my own hardware

Brought by drakestapleton

branch main Branches Tags History

aienos.com / om / omega-reference / vendor / examples / functions.om

66 lines · 1350 bytes Raw Blame History
1note functions: at most 6 parameters; a call may name any function in the unit; recursion in program mode
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
42fn main to int
43putu fact 20
44putu gcd 1071 462
45putu ulong pick 1 2 3 4 5 6
46ret 0
47end
48fn fact n ulong to ulong
49if le n 1
50ret 1
51end
52ret mul n fact sub n 1
53end
54fn gcd a ulong b ulong to ulong
55x = a
56y = b
57while ne y 0 bound 200
58t = rem x y
59x = y
60y = t
61end
62ret x
63end
64fn pick a int b int c int d int e int f int to int
65ret add add a f mul b sub e d
66end