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 / handles_basic.osc

31 lines · 816 bytes Raw Blame History
1// entry: basic reuse
2// OSC-3 item 2: versioned handles. A handle is a copyable (slot, generation)
3// value of one function-local pool; it never owns its slot. Freeing bumps the
4// slot generation, so the slot is reused by the next allocation.
5// expect-run: basic 5 -> 23
6// expect-run: reuse 2 -> 8
7fn basic(k: i64) -> i64 {
8 let mut s: i64 = 0;
9 pool p: [i64; 2] {
10 let a: handle p = p.alloc(k);
11 let b: handle p = p.alloc(10);
12 p[a] = p[a] + p[b];
13 s = p[a] + 8;
14 p.free(b);
15 p.free(a);
16 }
17 return s;
18}
19
20fn reuse(k: i64) -> i64 {
21 let mut s: i64 = 0;
22 pool p: [i64; 1] {
23 let mut h: handle p = p.alloc(k);
24 let c: handle p = h;
25 s = p[c];
26 p.free(h);
27 h = p.alloc(k * 3);
28 s = s + p[h];
29 }
30 return s;
31}