rt: move slice append helpers from lib/slices/ into libwwrt.a

This commit is contained in:
2026-05-11 16:56:46 +09:00
parent 8ffe6dbee6
commit 5408160d49
5 changed files with 23 additions and 34 deletions

View File

@@ -1,49 +0,0 @@
// 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;
};