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-diag.om

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