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 / tests / compiler / progs / shortcircuit.osc
| 1 | // entry: safe_div guarded_index either |
| 2 | // expect-run: safe_div 9 0 -> 0 |
| 3 | // expect-run: safe_div 9 2 -> 1 |
| 4 | // expect-run: guarded_index 4 -> trap=BOUNDS |
| 5 | // expect-run: guarded_index 18446744073709551615 -> 2 |
| 6 | // && and || short-circuit: the right side runs only when needed. |
| 7 | fn safe_div(a: i32, b: i32) -> bool { |
| 8 | return b != 0 && a / b > 3; |
| 9 | } |
| 10 | |
| 11 | fn guarded_index(i: i64) -> i64 { |
| 12 | let a: own [i64; 4] = alloc(9); |
| 13 | if i >= 0 && i < 4 && a[i] == 9 { return 1; } |
| 14 | if i < 0 || a[i] > 0 { return 2; } |
| 15 | return 3; |
| 16 | } |
| 17 | |
| 18 | fn either(a: u8, b: u8) -> bool { |
| 19 | return a == 0 || 200 / a > b; |
| 20 | } |