omega-rosetta
aien-dev/omega-rosetta
Brought by drakestapleton
omega-rosetta / drafts / rosettacode / character-codes.wiki
| 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 (<code>emit</code> and friends) are part of the program. |
| 4 | <syntaxhighlight lang="text"> |
| 5 | om2 |
| 6 | text nl "\n" |
| 7 | text sp " " |
| 8 | text ch "a" |
| 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 emitc writes one byte |
| 36 | fn emitc c uchar to void |
| 37 | b = new uchar 1 0 |
| 38 | put b 0 c |
| 39 | emit b |
| 40 | end |
| 41 | fn main to int |
| 42 | note a byte is a number: the code of a is get ch 0, and the number 97 printed as a byte is a |
| 43 | emit ch |
| 44 | emit sp |
| 45 | emitu ulong get ch 0 |
| 46 | emit nl |
| 47 | emitu 97 |
| 48 | emit sp |
| 49 | emitc 97 |
| 50 | emit nl |
| 51 | ret 0 |
| 52 | end |
| 53 | </syntaxhighlight> |
| 54 | {{out}} |
| 55 | <pre> |
| 56 | a 97 |
| 57 | 97 a |
| 58 | </pre> |