Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them.
Page: /drakestapleton/omega-rosetta/blob/main/drafts/rosettacode/insertion-sort.wiki
# omega-rosetta
aien-dev/omega-rosetta
Brought by drakestapleton
Sign in to star 0 stars 0 watching
About Files History Releases Proposed changes Issues For developers
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}}
3 Omega has no imports, so the small output helpers (emit and friends) are part of the program.
4
5 om2
6 text nl "\n"
7 text sp " "
8 text minus "-"
9 note emit writes every byte of a to stdout; a short write is retried, an error exits 1
10 fn emit a view uchar * to void
11 o = ulong 0
12 while lt o len a bound 4096
13 k = write 1 a o sub len a o
14 if le k 0
15 exit 1
16 end
17 o = add o ulong k
18 end
19 end
20 note emitu writes n in decimal; 20 digits hold every ulong
21 fn emitu n ulong to void
22 d = new uchar 20 0
23 i = ulong 20
24 v = n
25 while true bound 20
26 i = sub i 1
27 put d i uchar add rem v 10 48
28 v = div v 10
29 if eq v 0
30 break
31 end
32 end
33 emit part d i sub 20 i
34 end
35 note emiti writes a signed n; the magnitude is taken as a ulong so the minimum long cannot overflow
36 fn emiti n long to void
37 if lt n 0
38 emit minus
39 emitu add bitcast ulong not n 1
40 else
41 emitu ulong n
42 end
43 end
44 fn isort a edit long 10 to void
45 for i ulong 9
46 k = get a add i 1
47 j = add i 1
48 note and evaluates both sides, so the bound test and the load are separate lines
49 while gt j 0 bound 10
50 if le get a sub j 1 k
51 break
52 end
53 put a j get a sub j 1
54 j = sub j 1
55 end
56 put a j k
57 end
58 end
59 fn show a view long 10 to void
60 for i ulong 10
61 if gt i 0
62 emit sp
63 end
64 emiti get a i
65 end
66 emit nl
67 end
68 fn main to int
69 a = new long 10 0
70 put a 0 31
71 put a 1 41
72 put a 2 59
73 put a 3 26
74 put a 4 -41
75 put a 5 58
76 put a 6 0
77 put a 7 -`9223372036854775808`
78 put a 8 `9223372036854775807`
79 put a 9 26
80 show a
81 isort a
82 show a
83 ret 0
84 end
85
86 {{out}}
87
88 31 41 59 26 -41 58 0 -`9223372036854775808` `9223372036854775807` 26
89 -`9223372036854775808` -41 0 26 26 31 41 58 59 `9223372036854775807`
90