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 / 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
8fn add_at(b: bytes, i: u64) -> u64 {
9 return b[i];
10}
11
12fn 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
22fn mark(c: cells, i: u64, v: u64) {
23 c[i] = v;
24}
25
26fn 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)
34fn 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}