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 / slices / zz_narrow_idx.osc

20 lines · 1005 bytes Raw Blame History
1// slice-entry: w8 w32 w64 neg mul shl
2// Narrow and wrapping index arithmetic: unsigned types wrap modulo 2^w, so w8(i) reads b[(i+255) mod 256].
3// slice-run: w8 bytes:aabb 1 -> 170
4// slice-run: w8 bytes:aabb 0 -> trap=BOUNDS
5// slice-run: w32 bytes:aabb 1 -> 170
6// slice-run: w32 bytes:aabb 0 -> trap=BOUNDS
7// slice-run: w64 bytes:aabb 1 -> 170
8// slice-run: w64 bytes:aabb 0 -> trap=BOUNDS
9// slice-run: neg bytes:aabb 1 -> 170
10// slice-run: neg bytes:aabb 0 -> trap=BOUNDS
11// slice-run: mul bytes:aabbccdd 1 -> 204
12// slice-run: mul bytes:aabbccdd 2 -> trap=BOUNDS
13// slice-run: shl bytes:aabb 0 -> 170
14// slice-run: shl bytes:aabb 1 -> trap=BOUNDS
15fn w8(b: bytes, i: u8) -> u64 { return b[i + 255]; }
16fn w32(b: bytes, i: u32) -> u64 { return b[i + 4294967295]; }
17fn w64(b: bytes, i: u64) -> u64 { return b[i + 18446744073709551615]; }
18fn neg(b: bytes, i: i32) -> u64 { return b[i - 1]; }
19fn mul(b: bytes, i: u64) -> u64 { return b[i * 2]; }
20fn shl(b: bytes, i: u64) -> u64 { return b[i << 63]; }