interplane.Get Omega
Read in your language

omega-rosetta

aien-dev/omega-rosetta

Brought by drakestapleton

branch main Branches Tags History

omega-rosetta / tasks / copy-a-string / copy-a-string.om

38 lines · 904 bytes Raw Blame History
1note Rosetta Code task "Copy a string": https://rosettacode.org/wiki/Copy_a_string
2note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3om2
4text nl "\n"
5text src "Hello"
6text tsrc "source: "
7text tcp "copy: "
8note emit writes every byte of a to stdout; a short write is retried, an error exits 1
9fn emit a view uchar * to void
10o = ulong 0
11while lt o len a bound 4096
12k = write 1 a o sub len a o
13if le k 0
14exit 1
15end
16o = add o ulong k
17end
18end
19note copyto copies s into d at offset off and returns the offset after it (past the end traps 3)
20fn copyto d edit uchar * off ulong s view uchar * to ulong
21for i ulong len s
22put d add off i get s i
23end
24ret add off len s
25end
26fn main to int
27note a text is read-only; copying it into a local array gives an independent, writable string
28c = new uchar 16 0
29n = copyto c 0 src
30put c 0 74
31emit tsrc
32emit src
33emit nl
34emit tcp
35emit part c 0 n
36emit nl
37ret 0
38end