interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / si / rosetta / tasks / string-comparison / string-comparison.om

87 lines · 1369 bytes Raw Blame History
1note Rosetta Code task "String comparison": https://rosettacode.org/wiki/String_comparison
2note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3om2
4text nl "\n"
5text sp " "
6text a1 "alpha"
7text b1 "beta"
8text a2 "Hello"
9text b2 "hello"
10text a3 "abc"
11text b3 "abcd"
12text teq " eq="
13text tlt " lt="
14text tgt " gt="
15text tci " equal-ignoring-case="
16text tyes "yes"
17text tno "no"
18note emit writes every byte of a to stdout; a short write is retried, an error exits 1
19fn emit a view uchar * to void
20o = ulong 0
21while lt o len a bound 4096
22k = write 1 a o sub len a o
23if le k 0
24exit 1
25end
26o = add o ulong k
27end
28end
29fn emitb b bool to void
30if b
31emit tyes
32else
33emit tno
34end
35end
36note cmp is byte order: -1, 0 or 1; a proper prefix sorts first; ci folds ASCII case first
37fn cmp a view uchar * b view uchar * ci bool to int
38n = len a
39if lt len b n
40n = len b
41end
42for i ulong n
43x = get a i
44y = get b i
45if and ci and ge x 65 le x 90
46x = add x 32
47end
48if and ci and ge y 65 le y 90
49y = add y 32
50end
51if lt x y
52ret -1
53end
54if gt x y
55ret 1
56end
57end
58if lt len a len b
59ret -1
60end
61if gt len a len b
62ret 1
63end
64ret 0
65end
66fn show a view uchar * b view uchar * to void
67c = cmp a b false
68emit a
69emit sp
70emit b
71emit teq
72emitb eq c 0
73emit tlt
74emitb lt c 0
75emit tgt
76emitb gt c 0
77emit tci
78emitb eq cmp a b true 0
79emit nl
80end
81fn main to int
82show a1 b1
83show a2 b2
84show a3 b3
85show b3 a3
86ret 0
87end