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

24 lines · 795 bytes Raw Blame History
1// entry: fields_rw pick_bits
2// OSC-2 structs: declaration, literal (each field once), field reads and
3// writes, array fields with dynamic indexes and a BOUNDS trap.
4struct Pt { x: i32, y: i32, ok: bool }
5struct Rec { tag: u8, vals: [i16; 4], n: u64 }
6
7fn fields_rw(a: i32, b: i32) -> i32 {
8 let p: own Pt = Pt { y: b, x: a, ok: a > b };
9 p.x = p.x - p.y;
10 if p.ok { p.y = 7; }
11 return p.x + p.y;
12}
13
14fn pick_bits(i: u8, v: i16) -> i64 {
15 let r: own Rec = Rec { tag: i, vals: [v; 4], n: 3 };
16 r.vals[1] = v - 1;
17 r.n = r.n + (r.tag as u64);
18 return (r.vals[i] as i64) + (r.n as i64);
19}
20// expect-run: fields_rw 5 2 -> 10
21// expect-run: fields_rw 1 4 -> 1
22// expect-run: pick_bits 1 10 -> 13
23// expect-run: pick_bits 3 -2 -> 4
24// expect-run: pick_bits 4 0 -> trap=BOUNDS