interplane.Get Omega
Read in your language

omega-rosetta

aien-dev/omega-rosetta

Brought by drakestapleton

branch main Branches Tags History

omega-rosetta / drafts / rosettacode / insertion-sort.wiki

90 lines · 1712 bytes Raw Blame History
1=={{header|Omegese}}==
2{{works with|omc|sha256 2c824805, aien-dev/omega-mv e5b32567, Linux AArch64}}
3Omega has no imports, so the small output helpers (<code>emit</code> and friends) are part of the program.
4<syntaxhighlight lang="text">
5om2
6text nl "\n"
7text sp " "
8text minus "-"
9note emit writes every byte of a to stdout; a short write is retried, an error exits 1
10fn emit a view uchar * to void
11o = ulong 0
12while lt o len a bound 4096
13k = write 1 a o sub len a o
14if le k 0
15exit 1
16end
17o = add o ulong k
18end
19end
20note emitu writes n in decimal; 20 digits hold every ulong
21fn emitu n ulong to void
22d = new uchar 20 0
23i = ulong 20
24v = n
25while true bound 20
26i = sub i 1
27put d i uchar add rem v 10 48
28v = div v 10
29if eq v 0
30break
31end
32end
33emit part d i sub 20 i
34end
35note emiti writes a signed n; the magnitude is taken as a ulong so the minimum long cannot overflow
36fn emiti n long to void
37if lt n 0
38emit minus
39emitu add bitcast ulong not n 1
40else
41emitu ulong n
42end
43end
44fn isort a edit long 10 to void
45for i ulong 9
46k = get a add i 1
47j = add i 1
48note and evaluates both sides, so the bound test and the load are separate lines
49while gt j 0 bound 10
50if le get a sub j 1 k
51break
52end
53put a j get a sub j 1
54j = sub j 1
55end
56put a j k
57end
58end
59fn show a view long 10 to void
60for i ulong 10
61if gt i 0
62emit sp
63end
64emiti get a i
65end
66emit nl
67end
68fn main to int
69a = new long 10 0
70put a 0 31
71put a 1 41
72put a 2 59
73put a 3 26
74put a 4 -41
75put a 5 58
76put a 6 0
77put a 7 -9223372036854775808
78put a 8 9223372036854775807
79put a 9 26
80show a
81isort a
82show a
83ret 0
84end
85</syntaxhighlight>
86{{out}}
87<pre>
8831 41 59 26 -41 58 0 -9223372036854775808 9223372036854775807 26
89-9223372036854775808 -41 0 26 26 31 41 58 59 9223372036854775807
90</pre>