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 / fold-trap.om

81 lines · 2103 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note Contract section 4 lines 102-104 and 105-108: an all-constant operation that would trap inside an
3note unrolled or inlined body is not folded and stays the run-time trap with its OM-1 code; conversion
4note range checks are kept. One stdin byte selects a case; values printed before the trap show order:
5note A 999, then unrolled div 100 i: trap 2 at i = 0 exit 102, stdout 999
6note B unrolled int add 2147483646 i: 2147483646 2147483647, trap 1 exit 101
7note C unrolled uchar add 254 i: 254 255, conversion trap 5 exit 105
8note D unrolled shl 1 add 62 i: 2^62 2^63, shift trap 7 exit 107
9note E unrolled int mul 1073741824 add i 1: 1073741824, trap 1 exit 101
10note F unrolled int div -2147483648 sub i 1: min / -1 at i = 0, trap 1 exit 101
11note G 999, then unrolled rem 7 i: trap 2 at i = 0 exit 102, stdout 999
12note H inline cv 255, cv 256 (uchar a): 255, conversion trap 5 exit 105
13note I inline dv 100 4, dv 100 0 (div a b): 25, trap 2 exit 102
14note ps v prints v, or 7777 for a negative v (only a wrongly folded, wrapped value is negative).
15note Twin fold-trap-rolled.om (unroll and inline removed) has the same expectations:
16note oracle/s3s4/exp/fold-trap-*.out (python3, oracle/s3s4/oracle.py).
17om2
18fn cv a ulong to uchar inline
19ret uchar a
20end
21fn dv a ulong b ulong to ulong inline
22ret div a b
23end
24fn ps v int to void
25if lt v 0
26pu 7777
27else
28pu ulong v
29end
30end
31fn main to int
32s = new uchar 1 0
33r = read 0 s 0 1
34k = get s 0
35if eq k 65
36pu 999
37for i ulong 4 unroll
38pu div 100 i
39end
40end
41if eq k 66
42for i int 4 unroll
43ps add 2147483646 i
44end
45end
46if eq k 67
47for i ulong 4 unroll
48pu ulong uchar add 254 i
49end
50end
51if eq k 68
52for i ulong 4 unroll
53pu shl 1 add 62 i
54end
55end
56if eq k 69
57for i int 4 unroll
58ps mul 1073741824 add i 1
59end
60end
61if eq k 70
62for i int 4 unroll
63ps add 5 div -2147483648 sub i 1
64end
65end
66if eq k 71
67pu 999
68for i ulong 4 unroll
69pu rem 7 i
70end
71end
72if eq k 72
73pu ulong cv 255
74pu ulong cv 256
75end
76if eq k 73
77pu dv 100 4
78pu dv 100 0
79end
80ret 0
81end