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/tasks/bubble-sort/bubble-sort.om # 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 / tasks / bubble-sort / bubble-sort.om` 83 lines ยท 1385 bytes Raw Blame History 1 note Rosetta Code task "Sorting algorithms/Bubble sort": https://rosettacode.org/wiki/Sorting_algorithms/Bubble_sort 2 note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 3 om2 4 text nl "\n" 5 text sp " " 6 text minus "-" 7 note emit writes every byte of a to stdout; a short write is retried, an error exits 1 8 fn emit a view uchar * to void 9 o = ulong 0 10 while lt o len a bound 4096 11 k = write 1 a o sub len a o 12 if le k 0 13 exit 1 14 end 15 o = add o ulong k 16 end 17 end 18 note emitu writes n in decimal; 20 digits hold every ulong 19 fn emitu n ulong to void 20 d = new uchar 20 0 21 i = ulong 20 22 v = n 23 while true bound 20 24 i = sub i 1 25 put d i uchar add rem v 10 48 26 v = div v 10 27 if eq v 0 28 break 29 end 30 end 31 emit part d i sub 20 i 32 end 33 note emiti writes a signed n; the magnitude is taken as a ulong so the minimum long cannot overflow 34 fn emiti n long to void 35 if lt n 0 36 emit minus 37 emitu add bitcast ulong not n 1 38 else 39 emitu ulong n 40 end 41 end 42 fn bsort a edit long 10 to void 43 for p ulong 9 44 swapped = false 45 for i ulong 9 46 if gt get a i get a add i 1 47 t = get a i 48 put a i get a add i 1 49 put a add i 1 t 50 swapped = true 51 end 52 end 53 if not swapped 54 break 55 end 56 end 57 end 58 fn show a view long 10 to void 59 for i ulong 10 60 if gt i 0 61 emit sp 62 end 63 emiti get a i 64 end 65 emit nl 66 end 67 fn main to int 68 a = new long 10 0 69 put a 0 5 70 put a 1 -3 71 put a 2 9 72 put a 3 0 73 put a 4 12 74 put a 5 -8 75 put a 6 7 76 put a 7 7 77 put a 8 1 78 put a 9 100 79 show a 80 bsort a 81 show a 82 ret 0 83 end