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 / examples / om2-tour.om

61 lines · 1139 bytes Raw Blame History
1note OM-2 profile tour: hex, rotr, unroll, fresh, layout, unsized views, part, abstract dup32
2om2
3layout blk 8
4field lo uint at 0 little
5field hi uint at 4 little
6end
7abstract v32 ulong
8holds v32 dup32
9note the erasing constructor: the body must be exactly this line
10fn v32mk x uint to v32
11ret seal v32 or shl ulong x 32 ulong x
12end
13fn seed s edit uint 8 fresh to uint
14for i uint 8 unroll
15put s i add i 0x9e3779b9
16end
17ret get s 7
18end
19fn stamp c edit blk to uint
20put c lo 0x01020304
21put c hi 0x05060708
22ret or get c lo shl get c hi 16
23end
24note a layout field name is read through a layout parameter, not a plain uchar array
25fn rd c view blk to uint
26ret get c lo
27end
28fn fold a view uint * to uint
29x = new uint 1 0
30put x 0 uint len a
31for i uint uint len a
32put x 0 add get x 0 rotr get a i 5
33end
34ret get x 0
35end
36fn main to int
37s = new uint 8 0
38v = seed s
39a = new uint 4 0
40put a 0 v
41put a 1 rotr v 12
42put a 2 0xffffffff
43put a 3 add v 1
44t = fold part a 1 2
45c = new uchar 8 0
46w = stamp c
47u = open v32mk 7
48if ne u or shl ulong 7 32 ulong 7
49ret 9
50end
51if eq t 0
52ret 10
53end
54if ne rd c 0x01020304
55ret 11
56end
57if ne shr w 16 0x070a
58ret 12
59end
60ret 0
61end