omega-rosetta
aien-dev/omega-rosetta
Brought by drakestapleton
omega-rosetta / drafts / rosettacode / copy-a-string.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 src "Hello" |
| 8 | text tsrc "source: " |
| 9 | text tcp "copy: " |
| 10 | note emit writes every byte of a to stdout; a short write is retried, an error exits 1 |
| 11 | fn emit a view uchar * to void |
| 12 | o = ulong 0 |
| 13 | while lt o len a bound 4096 |
| 14 | k = write 1 a o sub len a o |
| 15 | if le k 0 |
| 16 | exit 1 |
| 17 | end |
| 18 | o = add o ulong k |
| 19 | end |
| 20 | end |
| 21 | note copyto copies s into d at offset off and returns the offset after it (past the end traps 3) |
| 22 | fn copyto d edit uchar * off ulong s view uchar * to ulong |
| 23 | for i ulong len s |
| 24 | put d add off i get s i |
| 25 | end |
| 26 | ret add off len s |
| 27 | end |
| 28 | fn main to int |
| 29 | note a text is read-only; copying it into a local array gives an independent, writable string |
| 30 | c = new uchar 16 0 |
| 31 | n = copyto c 0 src |
| 32 | put c 0 74 |
| 33 | emit tsrc |
| 34 | emit src |
| 35 | emit nl |
| 36 | emit tcp |
| 37 | emit part c 0 n |
| 38 | emit nl |
| 39 | ret 0 |
| 40 | end |
| 41 | </syntaxhighlight> |
| 42 | {{out}} |
| 43 | <pre> |
| 44 | source: Hello |
| 45 | copy: Jello |
| 46 | </pre> |