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