lib/ww/lex: replace putuint with strconv.u64tos (Wave-2 hand-rolled->lib)

This commit is contained in:
2026-06-03 03:50:47 +09:00
parent 05609dcc34
commit 7d2d2c30ef
3 changed files with 15 additions and 63 deletions

View File

@@ -18,6 +18,7 @@ package lex;
import os;
import ascii;
import strings;
import strconv;
// isidstart / isidpart — identifier classification. Lexer-local
// because the "alpha or '_' / alnum or '_'" set isn't part of Hare's
@@ -99,32 +100,15 @@ fn curpos(l: *lex, out: *pos) void = {
out.col = l.col;
};
// putuint — write `v` (signed, but always non-negative here) to fd 2
// in decimal. Standalone so errat doesn't drag in fmt and create a
// dependency cycle with strconv.
fn putuint(fd: i32, v: i32) void = {
let tmp: [16]u8;
let i: i32 = 0;
let n: i32 = v;
for (n > 0) {
tmp[i] = ((n % 10) + 48): u8;
n = n / 10;
i += 1;
};
if (i == 0) { tmp[0] = 48u8; i = 1; };
let buf: [16]u8;
let m: i32 = 0;
for (i > 0) { i -= 1; buf[m] = tmp[i]; m += 1; };
os.write(fd, buf.ptr, m: u64);
};
fn errat(l: *lex, p: *pos, msg: str) void = {
let pf: str = p.file;
os.write(2, pf.ptr, pf.len: u64);
os.write(2, ":".ptr, 1u64);
putuint(2, p.line);
let ls: str = strconv.u64tos(p.line: u64, strconv.base.DEC);
os.write(2, ls.ptr, ls.len: u64);
os.write(2, ":".ptr, 1u64);
putuint(2, p.col);
let cs: str = strconv.u64tos(p.col: u64, strconv.base.DEC);
os.write(2, cs.ptr, cs.len: u64);
os.write(2, ": error: ".ptr, 9u64);
os.write(2, msg.ptr, msg.len: u64);
os.write(2, "\n".ptr, 1u64);