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.
50 lines
1.1 KiB
Plaintext
50 lines
1.1 KiB
Plaintext
// slices — generic slice helpers, written without generics.
|
|
//
|
|
// CLAUDE.md forbids generics, so we mint per-element-type variants.
|
|
// Hare's `append` builtin is what these stand in for: each takes a
|
|
// *[]T plus an item, grows the storage if needed, and updates the
|
|
// slice header in place. The user passes `&s` because we mutate
|
|
// through the pointer.
|
|
|
|
use os;
|
|
|
|
export fn appendu8(s: *[]u8, v: u8) void = {
|
|
if (s.len >= s.cap) {
|
|
let nc: i32 = s.cap * 2;
|
|
if (nc < 8) { nc = 8; };
|
|
let np: *u8 = os.alloc(nc: u64): *u8;
|
|
let i: i32 = 0;
|
|
for (i < s.len) {
|
|
np[i] = s.ptr[i];
|
|
i += 1;
|
|
};
|
|
if (s.cap > 0) {
|
|
os.free(s.ptr: *void, s.cap: u64);
|
|
};
|
|
s.ptr = np;
|
|
s.cap = nc;
|
|
};
|
|
s.ptr[s.len] = v;
|
|
s.len += 1;
|
|
};
|
|
|
|
export fn appendi64(s: *[]i64, v: i64) void = {
|
|
if (s.len >= s.cap) {
|
|
let nc: i32 = s.cap * 2;
|
|
if (nc < 8) { nc = 8; };
|
|
let np: *i64 = os.alloc((nc * 8): u64): *i64;
|
|
let i: i32 = 0;
|
|
for (i < s.len) {
|
|
np[i] = s.ptr[i];
|
|
i += 1;
|
|
};
|
|
if (s.cap > 0) {
|
|
os.free(s.ptr: *void, (s.cap * 8): u64);
|
|
};
|
|
s.ptr = np;
|
|
s.cap = nc;
|
|
};
|
|
s.ptr[s.len] = v;
|
|
s.len += 1;
|
|
};
|