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