Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/tests/compiler/progs/handles_basic.osc # 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 Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers 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 7 fn 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 20 fn 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 }