interplane.Get Omega
Read in your language

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

branch main Branches Tags History

omega-mv / tests / compiler / progs / arena_borrows.osc

29 lines · 789 bytes Raw Blame History
1// entry: borrows
2// OSC-2 arenas: shared and mutable borrows of arena objects inside the block,
3// passed to & and &mut parameters; all borrows end before the arena dies.
4// expect-run: borrows 2 -> 24
5fn sum4(a: &[u32; 4]) -> u32 {
6 return a[0] + a[1] + a[2] + a[3];
7}
8
9fn bump(a: &mut [u32; 4], k: u32) {
10 for i in 0 .. 4 { a[i] = a[i] + k; }
11}
12
13fn borrows(k: u32) -> u32 {
14 let mut s: u32 = 0;
15 arena r bound 8 {
16 let a: own [u32; 4] in r = alloc(1);
17 bump(&mut a, k);
18 {
19 let m: &mut [u32; 4] = &mut a;
20 m[0] = m[0] + 5;
21 let t: &[u32; 4] = &m;
22 s = sum4(&t);
23 }
24 let b: own [u32; 4] in r = alloc(0);
25 let rb: &[u32; 4] = &a;
26 s = s + rb[3] - b[0] + 6 - 2;
27 }
28 return s;
29}