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/structs_contracts.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 / structs_contracts.osc` 28 lines ยท 776 bytes Raw Blame History 1 // entry: run_req run_ens 2 // OSC-2 structs in contracts: requires reads fields through any struct 3 // parameter; ensures reads fields only through a shared & parameter. 4 struct Win { lo: u16, hi: u16 } 5 6 fn width(w: &mut Win) -> u16 requires w.hi >= w.lo { 7 w.lo = w.lo + 0; 8 return w.hi - w.lo; 9 } 10 11 fn clampv(w: &Win, v: u16) -> u16 ensures result >= w.lo { 12 if v < w.lo { return v; } 13 return v; 14 } 15 16 fn run_req(a: u16, b: u16) -> u16 { 17 let w: own Win = Win { lo: a, hi: b }; 18 return width(&mut w); 19 } 20 21 fn run_ens(a: u16, v: u16) -> u16 { 22 let w: own Win = Win { lo: a, hi: 100 }; 23 return clampv(&w, v); 24 } 25 // expect-run: run_req 3 9 -> 6 26 // expect-run: run_req 9 3 -> trap=REQUIRES 27 // expect-run: run_ens 5 7 -> 7 28 // expect-run: run_ens 5 2 -> trap=ENSURES