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 / arrays.osc
| 1 | // entry: arr_main |
| 2 | // expect-run: arr_main 1 2 3 -> 59 |
| 3 | // alloc, move, borrow, reborrow, index read and write, own/&/&mut params. |
| 4 | fn consume(a: own [u32; 8]) -> u32 { |
| 5 | let mut s: u32 = 0; |
| 6 | for i in 0 .. 8 { s = s + a[i]; } |
| 7 | return s; |
| 8 | } |
| 9 | |
| 10 | fn scale(a: &mut [u32; 8], k: u32) { |
| 11 | for i in 0 .. 8 { a[i] = a[i] * k; } |
| 12 | } |
| 13 | |
| 14 | fn peek(a: &[u32; 8], i: u8) -> u32 { return a[i]; } |
| 15 | |
| 16 | fn arr_main(v: u32, k: u32, i: u8) -> u32 { |
| 17 | let a: own [u32; 8] = alloc(v); |
| 18 | a[3] = 7; |
| 19 | scale(&mut a, k); |
| 20 | { |
| 21 | let r: &mut [u32; 8] = &mut a; |
| 22 | r[0] = r[0] + 1; |
| 23 | let tmp: own [u32; 8] = alloc(1); |
| 24 | tmp[1] = r[1]; |
| 25 | } |
| 26 | let x: u32 = peek(&a, i % 8); |
| 27 | let b: own [u32; 8] = a; |
| 28 | b[7] = x; |
| 29 | let mut y: u32 = 0; |
| 30 | { |
| 31 | let s: &[u32; 8] = &b; |
| 32 | let s2: &[u32; 8] = &s; |
| 33 | y = s[2] + peek(&b, 7) + peek(&s2, 1); |
| 34 | } |
| 35 | return consume(b) + y; |
| 36 | } |