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/slices/sum_bytes.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 / slices / sum_bytes.osc` 48 lines ยท 1434 bytes Raw Blame History 1 // slice-entry: sum at at_i64 first_or_zero length_of 2 // External byte slice (docs/osc/OSC-EXT-BYTES-DESIGN.md): a bytes parameter is a read-only borrowed 3 // buffer passed as pointer + length; b[i] is a u8 zero-extended to u64 and is checked against b.len. 4 // slice-run: sum bytes:`0102030405` -> 15 5 // slice-run: sum bytes:ff -> 255 6 // slice-run: sum bytes: -> 0 7 // slice-run: sum bytes:NULL -> 0 8 // slice-run: at bytes:0a141e 0 -> 10 9 // slice-run: at bytes:0a141e 2 -> 30 10 // slice-run: at bytes:0a141e 3 -> trap=BOUNDS 11 // slice-run: at bytes:0a141e `18446744073709551615` -> trap=BOUNDS 12 // slice-run: at bytes: 0 -> trap=BOUNDS 13 // slice-run: at bytes:NULL 0 -> trap=BOUNDS 14 // slice-run: at_i64 bytes:0a141e -1 -> trap=BOUNDS 15 // slice-run: at_i64 bytes:0a141e -`9223372036854775808` -> trap=BOUNDS 16 // slice-run: at_i64 bytes:0a141e 1 -> 20 17 // slice-run: first_or_zero bytes:80 -> 128 18 // slice-run: first_or_zero bytes: -> 0 19 // slice-run: length_of bytes:010203 -> 3 20 // slice-run: length_of bytes:NULL -> 0 21 fn sum(b: bytes) -> u64 { 22 let mut s: u64 = 0; 23 let mut i: u64 = 0; 24 while i < b.len bound 4096 { 25 s = s + b[i]; 26 i = i + 1; 27 } 28 return s; 29 } 30 31 fn at(b: bytes, i: u64) -> u64 { 32 return b[i]; 33 } 34 35 fn at_i64(b: bytes, i: i64) -> u64 { 36 return b[i]; 37 } 38 39 fn first_or_zero(b: bytes) -> u64 { 40 if b.len == 0 { 41 return 0; 42 } 43 return b[0]; 44 } 45 46 fn length_of(b: bytes) -> u64 { 47 return b.len; 48 }