C bootstrap (phases 0-9):
cmd/wwc, cmd/6c, cmd/6a, cmd/6l, cmd/ww, rt, lib/*.
ww-side self-host (phase 10):
selfhost/cmd/wwc — ww-cgen frontend; bootstrap fixed point.
selfhost/cmd/6a — assembler; byte-identical to C 6a (test 991).
selfhost/cmd/6l — linker w/ archive (.a) support; byte-identical
to C 6l (test 992).
selfhost/cmd/ww — driver (build/run/version); byte-identical to
C ww (test 993).
make test: 15/15. make bootstrap: ww2.s == ww3.s, ww2.o == ww3.o,
ww2 == ww3 byte-identical, with the full ww-tooled chain.
52 lines
1.0 KiB
Plaintext
52 lines
1.0 KiB
Plaintext
// bytes — slice operations over []u8.
|
|
|
|
export fn equal(a: []u8, b: []u8) bool = {
|
|
let i: i32 = 0;
|
|
for (i < a.len) {
|
|
if (i >= b.len) { return false; };
|
|
if (a[i] != b[i]) { return false; };
|
|
i += 1;
|
|
};
|
|
return i == b.len;
|
|
};
|
|
|
|
export fn indexbyte(s: []u8, c: u8) i32 = {
|
|
let i: i32 = 0;
|
|
for (i < s.len) {
|
|
if (s[i] == c) { return i; };
|
|
i += 1;
|
|
};
|
|
return -1;
|
|
};
|
|
|
|
export fn copy(dst: []u8, src: []u8) i32 = {
|
|
let n: i32 = dst.len;
|
|
if (src.len < n) { n = src.len; };
|
|
let i: i32 = 0;
|
|
for (i < n) {
|
|
dst[i] = src[i];
|
|
i += 1;
|
|
};
|
|
return n;
|
|
};
|
|
|
|
// indexsub — first index of `sub` in `s`, or -1. Mirrors
|
|
// strings.index but on []u8. Empty `sub` matches at 0.
|
|
export fn indexsub(s: []u8, sub: []u8) i32 = {
|
|
if (sub.len == 0) { return 0; };
|
|
if (sub.len > s.len) { return -1; };
|
|
let last: i32 = s.len - sub.len;
|
|
let i: i32 = 0;
|
|
for (i <= last) {
|
|
let j: i32 = 0;
|
|
let ok: bool = true;
|
|
for (j < sub.len) {
|
|
if (s[i + j] != sub[j]) { ok = false; j = sub.len; }
|
|
else { j += 1; };
|
|
};
|
|
if (ok) { return i; };
|
|
i += 1;
|
|
};
|
|
return -1;
|
|
};
|