lib: α-batch-2 rt.malloc → alloc([], N)! (path/shlex/fmt/ostest)
Phase 0 #8 second α-batch. 7 sites: lib/path/path.ww `join` ×4, lib/shlex/shlex.ww `dupstr`, lib/fmt/fmt.ww `asprintf` tight-copy, lib/os/ostest.ww `test_alloc_free_roundtrip`. Same dup-pilot pattern (4c07ef0,47918d3): `alloc([], N)!` + `buf.len = N;` + `return strings.frombytes(buf);`. Side effects: - path/shlex/fmt: import switches `rt` → `strings` (callers now reference `strings.frombytes`, not `rt.malloc` direct). - ostest.ww: `import rt;` retained — the alloc builtin lowers to `CALL malloc(SB)` which resolves via rt's @symbol("rt_malloc") decl. Other files reach rt transitively via `import strings`; ostest only imports os, so it needs the explicit rt import. - shlex stale comment "avoid strings dep" stripped — strings is now in scope. Verified make test 132/132 + 995_self_rebuild byte-identity. Advances #43.
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
|
||||
package path;
|
||||
|
||||
import rt;
|
||||
import strings;
|
||||
|
||||
def SEP: u8 = 47u8; // '/'
|
||||
|
||||
@@ -95,31 +95,25 @@ export fn extension(p: str) str = {
|
||||
// two-arg join (no variadic).
|
||||
export fn join(a: str, b: str) str = {
|
||||
if (abs(b)) {
|
||||
let buf: *u8 = rt.malloc(b.len: u64): *u8;
|
||||
let buf: []u8 = alloc([], b.len: u64)!;
|
||||
let i: i32 = 0;
|
||||
for (i < b.len) { buf[i] = b[i]; i += 1; };
|
||||
let r: str;
|
||||
r.ptr = buf;
|
||||
r.len = b.len;
|
||||
return r;
|
||||
buf.len = b.len;
|
||||
return strings.frombytes(buf);
|
||||
};
|
||||
if (a.len == 0) {
|
||||
let buf: *u8 = rt.malloc(b.len: u64): *u8;
|
||||
let buf: []u8 = alloc([], b.len: u64)!;
|
||||
let i: i32 = 0;
|
||||
for (i < b.len) { buf[i] = b[i]; i += 1; };
|
||||
let r: str;
|
||||
r.ptr = buf;
|
||||
r.len = b.len;
|
||||
return r;
|
||||
buf.len = b.len;
|
||||
return strings.frombytes(buf);
|
||||
};
|
||||
if (b.len == 0) {
|
||||
let buf: *u8 = rt.malloc(a.len: u64): *u8;
|
||||
let buf: []u8 = alloc([], a.len: u64)!;
|
||||
let i: i32 = 0;
|
||||
for (i < a.len) { buf[i] = a[i]; i += 1; };
|
||||
let r: str;
|
||||
r.ptr = buf;
|
||||
r.len = a.len;
|
||||
return r;
|
||||
buf.len = a.len;
|
||||
return strings.frombytes(buf);
|
||||
};
|
||||
// Trim trailing '/' from a; b never starts with '/' here (checked
|
||||
// above via abs(b)).
|
||||
@@ -129,14 +123,12 @@ export fn join(a: str, b: str) str = {
|
||||
an -= 1;
|
||||
};
|
||||
let total: i32 = an + 1 + b.len;
|
||||
let buf: *u8 = rt.malloc(total: u64): *u8;
|
||||
let buf: []u8 = alloc([], total: u64)!;
|
||||
let i: i32 = 0;
|
||||
for (i < an) { buf[i] = a[i]; i += 1; };
|
||||
buf[an] = SEP;
|
||||
let j: i32 = 0;
|
||||
for (j < b.len) { buf[an + 1 + j] = b[j]; j += 1; };
|
||||
let r: str;
|
||||
r.ptr = buf;
|
||||
r.len = total;
|
||||
return r;
|
||||
buf.len = total;
|
||||
return strings.frombytes(buf);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user