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