w6c,w6l: write diagnostics via str .len (fix off-by-one hand-counts)

The argv-error diagnostics in w6c/main.ww (7 sites) and w6l/main.ww
(13 literal sites) passed hand-counted byte lengths to os.write that
were systematically short by one — every length dropped the final
byte (usually '\n'; "w6l: cannot find -l" dropped the 'l'), so the
diagnostics printed truncated. Replace each magic length with the
string's own .len, which both fixes the off-by-one and closes the
hand-count class by construction.

Uses the local-binding idiom (let m: str = "..."; os.write(2, m.ptr,
m.len: u64);) — the established wcc/err.ww pattern — rather than
"literal".len directly: string-literal .len is miscompiled on cstage
(returns the pointer, not the length; cstage != wwstage), filed as
#14. str-variable .len is correct on both stages, so this is byte-
identical cs==ww and independent of #14. The w6l runtime cstr write
(os.write(2, nm, cstrlen(nm))) is unchanged.
This commit is contained in:
2026-06-02 23:10:47 +09:00
parent 9e82037998
commit 6f9a964a79
4 changed files with 84 additions and 42 deletions

View File

@@ -34615,16 +34615,19 @@ export fn main(argc: i32, argv: **u8) i32 = {
if (cstreq(a, "-o")) {
i += 1;
if (i >= argc) {
os.write(2, "w6c: -o requires arg\n".ptr, 20u64);
let m: str = "w6c: -o requires arg\n";
os.write(2, m.ptr, m.len: u64);
return 2;
};
out = argv[i];
} else { if (a[0u64] == 45u8) {
os.write(2, "w6c: unknown flag\n".ptr, 17u64);
let m: str = "w6c: unknown flag\n";
os.write(2, m.ptr, m.len: u64);
return 2;
} else {
if (src != nil) {
os.write(2, "w6c: only one input\n".ptr, 19u64);
let m: str = "w6c: only one input\n";
os.write(2, m.ptr, m.len: u64);
return 2;
};
src = a;
@@ -34633,7 +34636,8 @@ export fn main(argc: i32, argv: **u8) i32 = {
};
if (src == nil) {
os.write(2, "usage: w6c_ww [-o out.s] file.ww\n".ptr, 32u64);
let m: str = "usage: w6c_ww [-o out.s] file.ww\n";
os.write(2, m.ptr, m.len: u64);
return 2;
};
@@ -34641,7 +34645,8 @@ export fn main(argc: i32, argv: **u8) i32 = {
let blen: u64;
buf, blen = slurp(src);
if (buf == nil) {
os.write(2, "w6c: cannot read input\n".ptr, 22u64);
let m: str = "w6c: cannot read input\n";
os.write(2, m.ptr, m.len: u64);
return 1;
};
@@ -34652,11 +34657,13 @@ export fn main(argc: i32, argv: **u8) i32 = {
let ofd: i32 = os.open(pathstr(out),
os.flag.WRONLY | os.flag.CREATE | os.flag.TRUNC, 420i32); // 0o644
if (ofd < 0) {
os.write(2, "w6c: cannot open output\n".ptr, 23u64);
let m: str = "w6c: cannot open output\n";
os.write(2, m.ptr, m.len: u64);
return 1;
};
if (os.dup2(ofd, 1i32) < 0) {
os.write(2, "w6c: dup2 failed\n".ptr, 16u64);
let m: str = "w6c: dup2 failed\n";
os.write(2, m.ptr, m.len: u64);
os.close(ofd);
return 1;
};

View File

@@ -86,16 +86,19 @@ export fn main(argc: i32, argv: **u8) i32 = {
if (cstreq(a, "-o")) {
i += 1;
if (i >= argc) {
os.write(2, "w6c: -o requires arg\n".ptr, 20u64);
let m: str = "w6c: -o requires arg\n";
os.write(2, m.ptr, m.len: u64);
return 2;
};
out = argv[i];
} else { if (a[0u64] == 45u8) {
os.write(2, "w6c: unknown flag\n".ptr, 17u64);
let m: str = "w6c: unknown flag\n";
os.write(2, m.ptr, m.len: u64);
return 2;
} else {
if (src != nil) {
os.write(2, "w6c: only one input\n".ptr, 19u64);
let m: str = "w6c: only one input\n";
os.write(2, m.ptr, m.len: u64);
return 2;
};
src = a;
@@ -104,7 +107,8 @@ export fn main(argc: i32, argv: **u8) i32 = {
};
if (src == nil) {
os.write(2, "usage: w6c_ww [-o out.s] file.ww\n".ptr, 32u64);
let m: str = "usage: w6c_ww [-o out.s] file.ww\n";
os.write(2, m.ptr, m.len: u64);
return 2;
};
@@ -112,7 +116,8 @@ export fn main(argc: i32, argv: **u8) i32 = {
let blen: u64;
buf, blen = slurp(src);
if (buf == nil) {
os.write(2, "w6c: cannot read input\n".ptr, 22u64);
let m: str = "w6c: cannot read input\n";
os.write(2, m.ptr, m.len: u64);
return 1;
};
@@ -123,11 +128,13 @@ export fn main(argc: i32, argv: **u8) i32 = {
let ofd: i32 = os.open(pathstr(out),
os.flag.WRONLY | os.flag.CREATE | os.flag.TRUNC, 420i32); // 0o644
if (ofd < 0) {
os.write(2, "w6c: cannot open output\n".ptr, 23u64);
let m: str = "w6c: cannot open output\n";
os.write(2, m.ptr, m.len: u64);
return 1;
};
if (os.dup2(ofd, 1i32) < 0) {
os.write(2, "w6c: dup2 failed\n".ptr, 16u64);
let m: str = "w6c: dup2 failed\n";
os.write(2, m.ptr, m.len: u64);
os.close(ofd);
return 1;
};