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/reborrow.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 / reborrow.osc` 38 lines ยท 958 bytes Raw Blame History 1 // entry: rb_main 2 // reborrows through &mut, shared reborrow of a shared borrow, borrow 3 // binding reassignment, &mut parameter reborrowed into another call. 4 fn total(a: &[i32; 6]) -> i32 { 5 let mut s: i32 = 0; 6 for i in 0 .. 6 { s = s + a[i]; } 7 return s; 8 } 9 10 fn bump(a: &mut [i32; 6], k: i32) { 11 for i in 0 .. 6 { a[i] = a[i] + k; } 12 } 13 14 fn twice(a: &mut [i32; 6], k: i32) -> i32 { 15 bump(&mut a, k); 16 { 17 let m: &mut [i32; 6] = &mut a; 18 bump(&mut m, k); 19 m[5] = 0; 20 { 21 let t: &[i32; 6] = &m; 22 let u: &[i32; 6] = &t; 23 if t[0] > 100 { return total(&u); } 24 } 25 } 26 return total(&a); 27 } 28 29 fn rb_main(x: i32, k: i16) -> i32 { 30 let a: own [i32; 6] = alloc(x); 31 let b: own [i32; 6] = alloc(1); 32 let s3: i32 = twice(&mut a, k as i32); 33 let mut cur: &[i32; 6] = &a; 34 let s1: i32 = total(&cur); 35 cur = &b; 36 let s2: i32 = total(&cur); 37 return s1 - s2 + s3; 38 }