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 / structs_dtor.osc
| 1 | // entry: dtor |
| 2 | // OSC-2 structs: deterministic destruction. Owners are released at scope |
| 3 | // end in reverse declaration order, structs and arrays alike, using the same |
| 4 | // alloc/release events as arrays. A moved-from struct is not released again. |
| 5 | // The release order is asserted by test_osc_compiler (serials 3 2 4 1). |
| 6 | struct Pair { a: u32, b: u32 } |
| 7 | |
| 8 | fn dtor(k: u32) -> u32 { |
| 9 | let p: own Pair = Pair { a: k, b: 1 }; |
| 10 | { |
| 11 | let arr: own [u32; 2] = alloc(2); |
| 12 | let q: own Pair = Pair { a: arr[0], b: arr[1] }; |
| 13 | p.b = q.a + q.b; |
| 14 | } |
| 15 | let r: own Pair = Pair { a: 9, b: 9 }; |
| 16 | let s: own Pair = r; |
| 17 | return p.a + p.b + s.a; |
| 18 | } |
| 19 | // expect-run: dtor 1 -> 14 |