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 / apps / aienos-site / om / omega-reference / vendor / skills / omega-encoding / examples / fnv1a32.om

55 lines · 932 bytes Raw Blame History
1note fnv1a32: read all of stdin (at most 65535 bytes), write its FNV-1a 32-bit hash as 4 little-endian bytes
2note exit 0 ok, 2 read error or input of 65536 bytes or more, 3 short or failed write
3global inb uchar 65536
4global outb uchar 4
5fn rdall to long
6t = ulong 0
7while lt t len inb bound 65536
8k = read 0 inb t sub len inb t
9if lt k 0
10ret k
11end
12if eq k 0
13ret long t
14end
15t = add t ulong k
16end
17ret neg long 27
18end
19fn fnv n ulong to uint
20h = uint 2166136261
21for i ulong n
22h = mul xor h uint get inb i 16777619
23end
24ret h
25end
26fn put4 h uint to void
27put outb 0 uchar and h 255
28put outb 1 uchar and shr h 8 255
29put outb 2 uchar and shr h 16 255
30put outb 3 uchar and shr h 24 255
31end
32fn wrall n ulong to long
33d = ulong 0
34while lt d n bound 4
35w = write 1 outb d sub n d
36if le w 0
37ret w
38end
39d = add d ulong w
40end
41ret long d
42end
43fn main to int
44r = rdall
45if lt r 0
46ret 2
47end
48h = fnv ulong r
49put4 h
50w = wrall 4
51if ne w 4
52ret 3
53end
54ret 0
55end