lib/ww/lex: replace putuint with strconv.u64tos (Wave-2 hand-rolled->lib)
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -6790,6 +6790,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
|
||||
@@ -6871,32 +6872,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);
|
||||
|
||||
@@ -6790,6 +6790,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
|
||||
@@ -6871,32 +6872,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);
|
||||
|
||||
Reference in New Issue
Block a user