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/pass_down.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 / pass_down.osc` 46 lines ยท 1190 bytes Raw Blame History 1 // slice-entry: total scan_and_mark 2 // A slice goes down whole (pointer and length: two registers) to a callee's slice parameter of the same type. 3 // slice-run: total bytes:`01020304` -> 10 4 // slice-run: total bytes: -> 0 5 // slice-run: scan_and_mark bytes:`00ff00ff` cells:4 -> 2 cells=0,1,0,1 6 // slice-run: scan_and_mark bytes:`00ff00ff` cells:3 -> 2 cells=0,1,0 7 // slice-run: scan_and_mark bytes:0100 cells:NULL -> 1 8 fn add_at(b: bytes, i: u64) -> u64 { 9 return b[i]; 10 } 11 12 fn total(b: bytes) -> u64 { 13 let mut s: u64 = 0; 14 let mut i: u64 = 0; 15 while i < b.len bound 4096 { 16 s = s + add_at(b, i); 17 i = i + 1; 18 } 19 return s; 20 } 21 22 fn mark(c: cells, i: u64, v: u64) { 23 c[i] = v; 24 } 25 26 fn nonzero(b: bytes, i: u64) -> u64 { 27 if b[i] != 0 { 28 return 1; 29 } 30 return 0; 31 } 32 33 // counts the non-zero bytes and marks them in c when c has room (two slices, one scalar, six registers) 34 fn scan_and_mark(b: bytes, c: cells) -> u64 { 35 let mut n: u64 = 0; 36 let mut i: u64 = 0; 37 while i < b.len bound 4096 { 38 let z: u64 = nonzero(b, i); 39 n = n + z; 40 if i < c.len { 41 mark(c, i, z); 42 } 43 i = i + 1; 44 } 45 return n; 46 }