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

31 lines · 892 bytes Raw Blame History
1// entry: f g
2// OSC-3 item 3 (drop flags): an owner moved in the then-branch only. After
3// the `if` it is maybe-moved: its drop flag is set at the declaration and
4// cleared by the move, and its scope-end release runs only when the flag
5// says live. A then-branch that returns leaves the owner definitely live
6// after the `if` (no flag).
7fn take(x: own [u8; 2]) -> u8 { return x[0] + x[1]; }
8
9fn f(k: u8) -> u8 {
10 let a: own [u8; 2] = alloc(k & 15);
11 let b: own [u8; 2] = alloc(4);
12 let mut r: u8 = 0;
13 if k > 3 { r = take(a); }
14 return r + b[0];
15}
16
17fn g(k: u8) -> u8 {
18 let a: own [u8; 2] = alloc(1);
19 if k == 1 {
20 let m: own [u8; 2] = a;
21 m[0] = 9;
22 return m[0] + m[1];
23 }
24 a[1] = k & 7;
25 return a[0] + a[1];
26}
27// expect-run: f 5 -> 14
28// expect-run: f 2 -> 4
29// expect-run: f 20 -> 12
30// expect-run: g 1 -> 10
31// expect-run: g 5 -> 6