selfhost/cmd: astrndup → strings.dup view (γ-2); drop wcc.astrndup
The final 2 astrndup callers in w6a (main.ww fname capture and the
dupstr wrapper in parse.ww) now use the uniform γ-1 shape:
let view: str;
view.ptr = src;
view.len = n: i32;
out = strings.dup(view);
With both call sites converted, wcc.astrndup is dead and removed
from selfhost/cmd/wcc/mem.ww. amalloc + arena bootstrap stay
(other callers; #7 Phase B/C territory).
The two `// astrndup until #11 (w6a types shadow) is fixed.`
WHY-pointers are obsolete (#11 landed in 6696e95) and dropped per
CLAUDE.md rule 8.
dupstr in parse.ww keeps its (*arena, *u8, u64) signature; the
vestigial *arena param is tracked by task #10.
Verified 132/132 incl. 991_w6a_ww + 995_self_rebuild byte-identity.
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -9,6 +9,7 @@ package main;
|
||||
import os;
|
||||
import rt;
|
||||
import mem;
|
||||
import strings;
|
||||
import opcodes;
|
||||
import lex;
|
||||
import parse;
|
||||
@@ -114,8 +115,10 @@ export fn main(argc: i32, argv: **u8) i32 = {
|
||||
let ar: *arena = newarena();
|
||||
let s: asm_;
|
||||
let nlen: u64 = cstrlen(src);
|
||||
// astrndup until #11 (w6a types shadow) is fixed.
|
||||
let fname: str = astrndup(ar, src, nlen);
|
||||
let view: str;
|
||||
view.ptr = src;
|
||||
view.len = nlen: i32;
|
||||
let fname: str = strings.dup(view);
|
||||
init(&s, ar, fname, buf, blen);
|
||||
|
||||
if (parse(&s) != 0) { return 1; };
|
||||
|
||||
@@ -14,6 +14,7 @@ package w6a;
|
||||
|
||||
import os;
|
||||
import mem;
|
||||
import strings;
|
||||
import lex;
|
||||
import opcodes;
|
||||
|
||||
@@ -179,9 +180,11 @@ fn perr(a: *asm_, msg: str) void = {
|
||||
};
|
||||
|
||||
// dupstr — copy n bytes from p into a fresh heap str.
|
||||
// astrndup until #11 (w6a types shadow) is fixed.
|
||||
fn dupstr(a: *arena, p: *u8, n: u64) str = {
|
||||
return astrndup(a, p, n);
|
||||
let view: str;
|
||||
view.ptr = p;
|
||||
view.len = n: i32;
|
||||
return strings.dup(view);
|
||||
};
|
||||
|
||||
// ---- line iteration & whitespace --------------------------------------
|
||||
|
||||
@@ -833,24 +833,6 @@ export fn amalloc(a: *arena, n: u64) *void = {
|
||||
return p: *void;
|
||||
};
|
||||
|
||||
// astrndup — copy `n` bytes into the arena and produce a NUL-terminated
|
||||
// view. Returns a `str` whose ptr is arena-owned and whose len is `n`
|
||||
// (the trailing NUL is past `len`, so callers reading exactly n bytes
|
||||
// see no padding). Used by the lexer to capture token text.
|
||||
export fn astrndup(a: *arena, src: *u8, n: u64) str = {
|
||||
let p: *u8 = amalloc(a, n + 1u64): *u8;
|
||||
let i: u64 = 0u64;
|
||||
for (i < n) {
|
||||
p[i] = src[i];
|
||||
i += 1u64;
|
||||
};
|
||||
p[n] = 0u8;
|
||||
let r: str;
|
||||
r.ptr = p;
|
||||
r.len = n: i32;
|
||||
return r;
|
||||
};
|
||||
|
||||
export fn freearena(a: *arena) void = {
|
||||
for (a != nil) {
|
||||
let next: *arena = a.next;
|
||||
|
||||
@@ -833,24 +833,6 @@ export fn amalloc(a: *arena, n: u64) *void = {
|
||||
return p: *void;
|
||||
};
|
||||
|
||||
// astrndup — copy `n` bytes into the arena and produce a NUL-terminated
|
||||
// view. Returns a `str` whose ptr is arena-owned and whose len is `n`
|
||||
// (the trailing NUL is past `len`, so callers reading exactly n bytes
|
||||
// see no padding). Used by the lexer to capture token text.
|
||||
export fn astrndup(a: *arena, src: *u8, n: u64) str = {
|
||||
let p: *u8 = amalloc(a, n + 1u64): *u8;
|
||||
let i: u64 = 0u64;
|
||||
for (i < n) {
|
||||
p[i] = src[i];
|
||||
i += 1u64;
|
||||
};
|
||||
p[n] = 0u8;
|
||||
let r: str;
|
||||
r.ptr = p;
|
||||
r.len = n: i32;
|
||||
return r;
|
||||
};
|
||||
|
||||
export fn freearena(a: *arena) void = {
|
||||
for (a != nil) {
|
||||
let next: *arena = a.next;
|
||||
|
||||
@@ -81,24 +81,6 @@ export fn amalloc(a: *arena, n: u64) *void = {
|
||||
return p: *void;
|
||||
};
|
||||
|
||||
// astrndup — copy `n` bytes into the arena and produce a NUL-terminated
|
||||
// view. Returns a `str` whose ptr is arena-owned and whose len is `n`
|
||||
// (the trailing NUL is past `len`, so callers reading exactly n bytes
|
||||
// see no padding). Used by the lexer to capture token text.
|
||||
export fn astrndup(a: *arena, src: *u8, n: u64) str = {
|
||||
let p: *u8 = amalloc(a, n + 1u64): *u8;
|
||||
let i: u64 = 0u64;
|
||||
for (i < n) {
|
||||
p[i] = src[i];
|
||||
i += 1u64;
|
||||
};
|
||||
p[n] = 0u8;
|
||||
let r: str;
|
||||
r.ptr = p;
|
||||
r.len = n: i32;
|
||||
return r;
|
||||
};
|
||||
|
||||
export fn freearena(a: *arena) void = {
|
||||
for (a != nil) {
|
||||
let next: *arena = a.next;
|
||||
|
||||
@@ -833,24 +833,6 @@ export fn amalloc(a: *arena, n: u64) *void = {
|
||||
return p: *void;
|
||||
};
|
||||
|
||||
// astrndup — copy `n` bytes into the arena and produce a NUL-terminated
|
||||
// view. Returns a `str` whose ptr is arena-owned and whose len is `n`
|
||||
// (the trailing NUL is past `len`, so callers reading exactly n bytes
|
||||
// see no padding). Used by the lexer to capture token text.
|
||||
export fn astrndup(a: *arena, src: *u8, n: u64) str = {
|
||||
let p: *u8 = amalloc(a, n + 1u64): *u8;
|
||||
let i: u64 = 0u64;
|
||||
for (i < n) {
|
||||
p[i] = src[i];
|
||||
i += 1u64;
|
||||
};
|
||||
p[n] = 0u8;
|
||||
let r: str;
|
||||
r.ptr = p;
|
||||
r.len = n: i32;
|
||||
return r;
|
||||
};
|
||||
|
||||
export fn freearena(a: *arena) void = {
|
||||
for (a != nil) {
|
||||
let next: *arena = a.next;
|
||||
|
||||
@@ -833,24 +833,6 @@ export fn amalloc(a: *arena, n: u64) *void = {
|
||||
return p: *void;
|
||||
};
|
||||
|
||||
// astrndup — copy `n` bytes into the arena and produce a NUL-terminated
|
||||
// view. Returns a `str` whose ptr is arena-owned and whose len is `n`
|
||||
// (the trailing NUL is past `len`, so callers reading exactly n bytes
|
||||
// see no padding). Used by the lexer to capture token text.
|
||||
export fn astrndup(a: *arena, src: *u8, n: u64) str = {
|
||||
let p: *u8 = amalloc(a, n + 1u64): *u8;
|
||||
let i: u64 = 0u64;
|
||||
for (i < n) {
|
||||
p[i] = src[i];
|
||||
i += 1u64;
|
||||
};
|
||||
p[n] = 0u8;
|
||||
let r: str;
|
||||
r.ptr = p;
|
||||
r.len = n: i32;
|
||||
return r;
|
||||
};
|
||||
|
||||
export fn freearena(a: *arena) void = {
|
||||
for (a != nil) {
|
||||
let next: *arena = a.next;
|
||||
|
||||
Reference in New Issue
Block a user