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 / scopes.osc
| 1 | // entry: scopes_main early |
| 2 | // inner-scope destruction, moves into inner owners, early returns that |
| 3 | // release several owners (including inside loops). |
| 4 | fn sum4(a: &[u16; 4]) -> u16 { return a[0] + a[1] + a[2] + a[3]; } |
| 5 | |
| 6 | fn scopes_main(x: u16) -> u16 { |
| 7 | let outer: own [u16; 4] = alloc(x); |
| 8 | let mut acc: u16 = 0; |
| 9 | { |
| 10 | let inner: own [u16; 4] = alloc(2); |
| 11 | acc = acc + sum4(&inner); |
| 12 | { |
| 13 | let deeper: own [u16; 4] = inner; |
| 14 | deeper[0] = 9; |
| 15 | acc = acc + sum4(&deeper); |
| 16 | } |
| 17 | } |
| 18 | for i in 0 .. 3 { |
| 19 | let tmp: own [u16; 4] = alloc(i as u16); |
| 20 | acc = acc + sum4(&tmp) + sum4(&outer); |
| 21 | } |
| 22 | return acc; |
| 23 | } |
| 24 | |
| 25 | fn early(x: i32, limit: i32) -> i32 { |
| 26 | let a: own [i32; 3] = alloc(x); |
| 27 | let mut n: i32 = 0; |
| 28 | while n < 50 bound 50 { |
| 29 | let b: own [i32; 2] = alloc(n); |
| 30 | for j in 0 .. 4 { |
| 31 | let c: own [i32; 1] = alloc(j as i32); |
| 32 | if n * 4 + c[0] >= limit { return a[0] + b[0] + c[0]; } |
| 33 | } |
| 34 | n = n + 1; |
| 35 | } |
| 36 | return -7; |
| 37 | } |