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 / seed / qualification / om2 / sec / s3s4 / rot-trap.om

89 lines · 1635 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note Contract section 3 lines 79-81: n must be in 0..w-1; n >= w traps 7 at run time, including a
3note constant n (OM-1 compiles a constant out-of-range shift to the run-time trap). One byte of stdin
4note selects one rotation: A-D constant n = w (one per width), E-H run-time n = w, I-L run-time n > w
5note (w+1 and the type maximum), M-O constant n > w, P a control (rotr uint by 31, no trap).
6note Program mode: a trap exits 100 + 7 = 107 with nothing printed; P prints one line and exits 0.
7om2
8fn rr8 x uchar n uchar to uchar
9ret rotr x n
10end
11fn rl8 x uchar n uchar to uchar
12ret rotl x n
13end
14fn rr16 x ushort n ushort to ushort
15ret rotr x n
16end
17fn rl16 x ushort n ushort to ushort
18ret rotl x n
19end
20fn rr32 x uint n uint to uint
21ret rotr x n
22end
23fn rl32 x uint n uint to uint
24ret rotl x n
25end
26fn rr64 x ulong n ulong to ulong
27ret rotr x n
28end
29fn rl64 x ulong n ulong to ulong
30ret rotl x n
31end
32fn main to int
33s = new uchar 1 0
34r = read 0 s 0 1
35k = get s 0
36a = uchar 177
37b = ushort 45508
38c = uint 4041331395
39d = ulong 9305357566071262703
40if eq k 65
41pu ulong rotr a 8
42end
43if eq k 66
44pu ulong rotl b 16
45end
46if eq k 67
47pu ulong rotr c 32
48end
49if eq k 68
50pu rotl d 64
51end
52if eq k 69
53pu ulong rl8 a 8
54end
55if eq k 70
56pu ulong rr16 b 16
57end
58if eq k 71
59pu ulong rl32 c 32
60end
61if eq k 72
62pu rr64 d 64
63end
64if eq k 73
65pu ulong rr8 a 9
66end
67if eq k 74
68pu ulong rl16 b 65535
69end
70if eq k 75
71pu ulong rr32 c 4294967295
72end
73if eq k 76
74pu rl64 d 18446744073709551615
75end
76if eq k 77
77pu ulong rotr c 33
78end
79if eq k 78
80pu rotl d 65
81end
82if eq k 79
83pu ulong rotl a 255
84end
85if eq k 80
86pu ulong rotr c 31
87end
88ret 0
89end