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 / string-prepend.wiki

49 lines · 1158 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 s0 "World"
8text pre "Hello, "
9note emit writes every byte of a to stdout; a short write is retried, an error exits 1
10fn emit a view uchar * to void
11o = ulong 0
12while lt o len a bound 4096
13k = write 1 a o sub len a o
14if le k 0
15exit 1
16end
17o = add o ulong k
18end
19end
20note copyto copies s into d at offset off and returns the offset after it (past the end traps 3)
21fn copyto d edit uchar * off ulong s view uchar * to ulong
22for i ulong len s
23put d add off i get s i
24end
25ret add off len s
26end
27note prepend moves the n bytes of b right by len p (last byte first), then copies p in front
28fn prepend b edit uchar * n ulong p view uchar * to ulong
29k = len p
30for i ulong n
31j = sub sub n 1 i
32put b add j k get b j
33end
34r = copyto b 0 p
35ret add n k
36end
37fn main to int
38b = new uchar 64 0
39n = copyto b 0 s0
40n = prepend b n pre
41emit part b 0 n
42emit nl
43ret 0
44end
45</syntaxhighlight>
46{{out}}
47<pre>
48Hello, World
49</pre>