Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/seed/qualification/om2/sec/s3s4/fold-trap.om # 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 Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / seed / qualification / om2 / sec / s3s4 / fold-trap.om` 81 lines ยท 2103 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 2 note Contract section 4 lines 102-104 and 105-108: an all-constant operation that would trap inside an 3 note unrolled or inlined body is not folded and stays the run-time trap with its OM-1 code; conversion 4 note range checks are kept. One stdin byte selects a case; values printed before the trap show order: 5 note A 999, then unrolled div 100 i: trap 2 at i = 0 exit 102, stdout 999 6 note B unrolled int add `2147483646` i: `2147483646` `2147483647`, trap 1 exit 101 7 note C unrolled uchar add 254 i: 254 255, conversion trap 5 exit 105 8 note D unrolled shl 1 add 62 i: 2^62 2^63, shift trap 7 exit 107 9 note E unrolled int mul `1073741824` add i 1: `1073741824`, trap 1 exit 101 10 note F unrolled int div -`2147483648` sub i 1: min / -1 at i = 0, trap 1 exit 101 11 note G 999, then unrolled rem 7 i: trap 2 at i = 0 exit 102, stdout 999 12 note H inline cv 255, cv 256 (uchar a): 255, conversion trap 5 exit 105 13 note I inline dv 100 4, dv 100 0 (div a b): 25, trap 2 exit 102 14 note ps v prints v, or 7777 for a negative v (only a wrongly folded, wrapped value is negative). 15 note Twin fold-trap-rolled.om (unroll and inline removed) has the same expectations: 16 note oracle/s3s4/exp/fold-trap-*.out (python3, oracle/s3s4/oracle.py). 17 om2 18 fn cv a ulong to uchar inline 19 ret uchar a 20 end 21 fn dv a ulong b ulong to ulong inline 22 ret div a b 23 end 24 fn ps v int to void 25 if lt v 0 26 pu 7777 27 else 28 pu ulong v 29 end 30 end 31 fn main to int 32 s = new uchar 1 0 33 r = read 0 s 0 1 34 k = get s 0 35 if eq k 65 36 pu 999 37 for i ulong 4 unroll 38 pu div 100 i 39 end 40 end 41 if eq k 66 42 for i int 4 unroll 43 ps add `2147483646` i 44 end 45 end 46 if eq k 67 47 for i ulong 4 unroll 48 pu ulong uchar add 254 i 49 end 50 end 51 if eq k 68 52 for i ulong 4 unroll 53 pu shl 1 add 62 i 54 end 55 end 56 if eq k 69 57 for i int 4 unroll 58 ps mul `1073741824` add i 1 59 end 60 end 61 if eq k 70 62 for i int 4 unroll 63 ps add 5 div -`2147483648` sub i 1 64 end 65 end 66 if eq k 71 67 pu 999 68 for i ulong 4 unroll 69 pu rem 7 i 70 end 71 end 72 if eq k 72 73 pu ulong cv 255 74 pu ulong cv 256 75 end 76 if eq k 73 77 pu dv 100 4 78 pu dv 100 0 79 end 80 ret 0 81 end