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/prefix.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 / prefix.osc` 23 lines ยท 684 bytes Raw Blame History 1 // entry: prefix_main 2 // expect-run: prefix_main 1 1 0 7 -> 36 3 // expect-run: prefix_main 1 1 2 3 -> 7 4 // expect-run: prefix_main 1 1 0 8 -> trap=BOUNDS 5 // prefix sums in i32 (checked) over an owned array; queries a range sum. 6 fn prefix(a: &mut [i32; 8]) { 7 for i in 1 .. 8 { 8 a[i] = a[i] + a[i - 1]; 9 } 10 } 11 12 fn range_sum(p: &[i32; 8], lo: u8, hi: u8) -> i32 { 13 if lo == 0 { return p[hi]; } 14 return p[hi] - p[lo - 1]; 15 } 16 17 fn prefix_main(x: i32, step: i16, lo: u8, hi: u8) -> i32 { 18 let a: own [i32; 8] = alloc(x); 19 for i in 0 .. 8 { a[i] = a[i] + (step as i32) * (i as i32); } 20 prefix(&mut a); 21 if lo > hi { return 0; } 22 return range_sum(&a, lo, hi); 23 }