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-matching / string-matching.om

74 lines · 1297 bytes Raw Blame History
1note Rosetta Code task "String matching": https://rosettacode.org/wiki/String_matching
2note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3om2
4text nl "\n"
5text sp " "
6text hay "tacoloco"
7text nd "co"
8text tst "starts with: "
9text tct "found at:"
10text ten "ends with: "
11text tyes "yes"
12text tno "no"
13note emit writes every byte of a to stdout; a short write is retried, an error exits 1
14fn emit a view uchar * to void
15o = ulong 0
16while lt o len a bound 4096
17k = write 1 a o sub len a o
18if le k 0
19exit 1
20end
21o = add o ulong k
22end
23end
24note emitu writes n in decimal; 20 digits hold every ulong
25fn emitu n ulong to void
26d = new uchar 20 0
27i = ulong 20
28v = n
29while true bound 20
30i = sub i 1
31put d i uchar add rem v 10 48
32v = div v 10
33if eq v 0
34break
35end
36end
37emit part d i sub 20 i
38end
39fn emitb b bool to void
40if b
41emit tyes
42else
43emit tno
44end
45end
46note at tells whether t occurs in s at offset i (false when it would run past the end)
47fn at2 s view uchar * t view uchar * i ulong to bool
48if gt add i len t len s
49ret false
50end
51for j ulong len t
52if ne get s add i j get t j
53ret false
54end
55end
56ret true
57end
58fn main to int
59emit tst
60emitb at2 hay nd 0
61emit nl
62emit tct
63for i ulong len hay
64if at2 hay nd i
65emit sp
66emitu i
67end
68end
69emit nl
70emit ten
71emitb at2 hay nd sub len hay len nd
72emit nl
73ret 0
74end