interplane.Get Omega
Read in your language

omega-rosetta

aien-dev/omega-rosetta

Brought by drakestapleton

branch main Branches Tags History

omega-rosetta / drafts / rosettacode / copy-a-string.wiki

46 lines · 1066 bytes Raw Blame History
1=={{header|Omegese}}==
2{{works with|omc|sha256 2c824805, aien-dev/omega-mv e5b32567, Linux AArch64}}
3Omega has no imports, so the small output helpers (<code>emit</code> and friends) are part of the program.
4<syntaxhighlight lang="text">
5om2
6text nl "\n"
7text src "Hello"
8text tsrc "source: "
9text tcp "copy: "
10note emit writes every byte of a to stdout; a short write is retried, an error exits 1
11fn emit a view uchar * to void
12o = ulong 0
13while lt o len a bound 4096
14k = write 1 a o sub len a o
15if le k 0
16exit 1
17end
18o = add o ulong k
19end
20end
21note copyto copies s into d at offset off and returns the offset after it (past the end traps 3)
22fn copyto d edit uchar * off ulong s view uchar * to ulong
23for i ulong len s
24put d add off i get s i
25end
26ret add off len s
27end
28fn main to int
29note a text is read-only; copying it into a local array gives an independent, writable string
30c = new uchar 16 0
31n = copyto c 0 src
32put c 0 74
33emit tsrc
34emit src
35emit nl
36emit tcp
37emit part c 0 n
38emit nl
39ret 0
40end
41</syntaxhighlight>
42{{out}}
43<pre>
44source: Hello
45copy: Jello
46</pre>