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 / casts.osc
| 1 | // entry: narrow sign_flip widen chain |
| 2 | // expect-run: narrow 127 -> 127 |
| 3 | // expect-run: narrow 128 -> trap=CAST |
| 4 | // expect-run: sign_flip 4294967295 -> trap=CAST |
| 5 | // expect-run: chain 100 -> 75 |
| 6 | // `as` between integer types; out-of-range traps CAST. |
| 7 | fn narrow(x: i64) -> i8 { return x as i8; } |
| 8 | fn sign_flip(x: i32) -> u32 { return x as u32; } |
| 9 | fn widen(x: u8, y: i16) -> i64 { return (x as i64) * 1000 + (y as i64); } |
| 10 | fn chain(x: u16) -> i16 { |
| 11 | let a: u32 = x as u32; |
| 12 | let b: i64 = a as i64; |
| 13 | let c: u64 = (b * 3) as u64; |
| 14 | return (c / 4) as i16; |
| 15 | } |