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 / bubble-sort.wiki

91 lines · 1535 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 bsort a edit long 10 to void
45for p ulong 9
46swapped = false
47for i ulong 9
48if gt get a i get a add i 1
49t = get a i
50put a i get a add i 1
51put a add i 1 t
52swapped = true
53end
54end
55if not swapped
56break
57end
58end
59end
60fn show a view long 10 to void
61for i ulong 10
62if gt i 0
63emit sp
64end
65emiti get a i
66end
67emit nl
68end
69fn main to int
70a = new long 10 0
71put a 0 5
72put a 1 -3
73put a 2 9
74put a 3 0
75put a 4 12
76put a 5 -8
77put a 6 7
78put a 7 7
79put a 8 1
80put a 9 100
81show a
82bsort a
83show a
84ret 0
85end
86</syntaxhighlight>
87{{out}}
88<pre>
895 -3 9 0 12 -8 7 7 1 100
90-8 -3 0 1 5 7 7 9 12 100
91</pre>