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_full.osc

32 lines · 853 bytes Raw Blame History
1// entry: fill cond_fill
2// OSC-2 arenas: an allocation whose capacity cannot be decided statically
3// (inside a loop or a branch) is checked at run time: TRAP ARENA_FULL.
4// expect-run: fill 3 -> 3
5// expect-run: fill 4 -> trap=ARENA_FULL
6// expect-run: cond_fill 0 -> 2
7// expect-run: cond_fill 1 -> trap=ARENA_FULL
8fn fill(n: u8) -> u32 {
9 let mut s: u32 = 0;
10 arena r bound 10 {
11 let mut i: u8 = 0;
12 while i < n bound 20 {
13 let a: own [u32; 3] in r = alloc(i as u32);
14 s = s + a[0];
15 i = i + 1;
16 }
17 }
18 return s;
19}
20
21fn cond_fill(c: u8) -> u32 {
22 let mut s: u32 = 0;
23 arena r bound 4 {
24 let a: own [u32; 2] in r = alloc(1);
25 if c > 0 {
26 let b: own [u32; 3] in r = alloc(2);
27 s = b[0];
28 }
29 s = s + a[0] + 1;
30 }
31 return s;
32}