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

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