From dbb52e25fe49360f3125803a69e7ce3a4b652da6 Mon Sep 17 00:00:00 2001 From: Hojun-Cho Date: Wed, 3 Jun 2026 00:01:50 +0900 Subject: [PATCH] w6a/parse: write diagnostics with str .len (fix perr truncation) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit perr() in parse.ww wrote the "w6a: " prefix with a hand-counted length of 4, but the string is 5 bytes — the trailing space was dropped, so every assembler diagnostic printed as "w6a:" with no separating space. Replace the prefix length (and the ": " / "\n" literal writes in the same function) with the string's own .len via the local-binding idiom, fixing the off-by-one and closing the hand-count class here. Uses str-variable .len (correct on both stages), not "literal".len (cstage miscompile, #14), so this is byte-identical cs==ww. Verified: w6a_ww on a bad input now writes "w6a: : \n" with the space restored; w6c and w6c_ww emit byte-identical asm for the regenerated main.combined.ww. --- selfhost/cmd/w6a/main.combined.ww | 9 ++++++--- selfhost/cmd/w6a/parse.ww | 9 ++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/selfhost/cmd/w6a/main.combined.ww b/selfhost/cmd/w6a/main.combined.ww index fabe6ba9..c528154f 100644 --- a/selfhost/cmd/w6a/main.combined.ww +++ b/selfhost/cmd/w6a/main.combined.ww @@ -3299,12 +3299,15 @@ export fn intern(a: *asm_, name: str) *asym = { }; fn perr(a: *asm_, msg: str) void = { - os.write(2, "w6a: ".ptr, 4u64); + let pfx: str = "w6a: "; + os.write(2, pfx.ptr, pfx.len: u64); let f: str = a.file; os.write(2, f.ptr, f.len: u64); - os.write(2, ": ".ptr, 2u64); + let sep: str = ": "; + os.write(2, sep.ptr, sep.len: u64); os.write(2, msg.ptr, msg.len: u64); - os.write(2, "\n".ptr, 1u64); + let nl: str = "\n"; + os.write(2, nl.ptr, nl.len: u64); a.errs += 1; }; diff --git a/selfhost/cmd/w6a/parse.ww b/selfhost/cmd/w6a/parse.ww index 085c4751..dd11bf56 100644 --- a/selfhost/cmd/w6a/parse.ww +++ b/selfhost/cmd/w6a/parse.ww @@ -170,12 +170,15 @@ export fn intern(a: *asm_, name: str) *asym = { }; fn perr(a: *asm_, msg: str) void = { - os.write(2, "w6a: ".ptr, 4u64); + let pfx: str = "w6a: "; + os.write(2, pfx.ptr, pfx.len: u64); let f: str = a.file; os.write(2, f.ptr, f.len: u64); - os.write(2, ": ".ptr, 2u64); + let sep: str = ": "; + os.write(2, sep.ptr, sep.len: u64); os.write(2, msg.ptr, msg.len: u64); - os.write(2, "\n".ptr, 1u64); + let nl: str = "\n"; + os.write(2, nl.ptr, nl.len: u64); a.errs += 1; };