lib: rename stdlib surface to Hare names; add endian/math
Sweeping rename so the lib/ surface mirrors Hare's stdlib spellings. - ascii: rune-taking predicates; ishex -> isxdigit - bufio: rinit -> init; take1/takeline -> readbyte/readline - bytes: indexsub -> index - encoding/utf8: runelen -> runesz - errors: eEOF/eShortRead/... -> eof/underread/... - fmt: errln -> errorln; println/fprintln return i64 - os: readfull/writefull -> readall/writeall; unlink -> remove - path: isabs -> abs; drop lastindex (now strings.rbyteindex) - strconv: u64toa/i64toa -> u64tos/i64tos; parse64/parseu64 -> stoi64/stou64 - strings: drop len/isempty; equal -> compare; indexbyte -> byteindex; +rbyteindex - types: drop numeric helpers (moved to math) - new lib/endian (htonu16/ntohu16), lib/math (absi32/absi64) - net: drop htons (use endian.htonu16) Callers in selfhost/, lib/ww/, cmd/w6c/cgen.c, and test/wcc/700_e2e.c updated to match.
This commit is contained in:
@@ -256,12 +256,12 @@ fn pr(fd: i32, n: *node, d: i32) void = {
|
||||
if (n.kind == N_INTLIT) {
|
||||
putc1(fd, 32u8);
|
||||
let buf: [32]u8;
|
||||
let m: i32 = strconv.u64toa(buf[0:32], n.uval);
|
||||
let m: i32 = strconv.u64tos(buf[0:32], n.uval);
|
||||
os.write(fd, buf.ptr, m: u64);
|
||||
} else { if (n.kind == N_RUNELIT) {
|
||||
putc1(fd, 32u8);
|
||||
let buf: [32]u8;
|
||||
let m: i32 = strconv.u64toa(buf[0:32], n.uval);
|
||||
let m: i32 = strconv.u64tos(buf[0:32], n.uval);
|
||||
os.write(fd, buf.ptr, m: u64);
|
||||
} else { if (
|
||||
n.kind == N_STRLIT ||
|
||||
|
||||
@@ -230,18 +230,18 @@ fn escape(l: *lex, out: *i32) bool = {
|
||||
let lo: i32 = lget(l);
|
||||
if (hi < 0) { return false; };
|
||||
if (lo < 0) { return false; };
|
||||
if (!ascii.ishex(hi: u8)) {
|
||||
if (!ascii.isxdigit(hi: rune)) {
|
||||
let cp: pos; curpos(l, &cp);
|
||||
errat(l, &cp, "bad \\x escape");
|
||||
return false;
|
||||
};
|
||||
if (!ascii.ishex(lo: u8)) {
|
||||
if (!ascii.isxdigit(lo: rune)) {
|
||||
let cp: pos; curpos(l, &cp);
|
||||
errat(l, &cp, "bad \\x escape");
|
||||
return false;
|
||||
};
|
||||
let h: i32 = ascii.digitval(hi: u8);
|
||||
let lv: i32 = ascii.digitval(lo: u8);
|
||||
let h: i32 = ascii.digitval(hi: rune);
|
||||
let lv: i32 = ascii.digitval(lo: rune);
|
||||
*out = (h << 4) | lv;
|
||||
return true;
|
||||
};
|
||||
@@ -255,7 +255,7 @@ fn scandecimalrun(l: *lex) void = {
|
||||
for (true) {
|
||||
let c: i32 = lpeek(l, 0u64);
|
||||
if (c < 0) { break; };
|
||||
if (!ascii.isdigit(c: u8)) {
|
||||
if (!ascii.isdigit(c: rune)) {
|
||||
if (c != 95) { break; };
|
||||
};
|
||||
lget(l);
|
||||
@@ -266,7 +266,7 @@ fn scanhexrun(l: *lex) void = {
|
||||
for (true) {
|
||||
let c: i32 = lpeek(l, 0u64);
|
||||
if (c < 0) { break; };
|
||||
if (!ascii.ishex(c: u8)) {
|
||||
if (!ascii.isxdigit(c: rune)) {
|
||||
if (c != 95) { break; };
|
||||
};
|
||||
lget(l);
|
||||
@@ -305,7 +305,7 @@ fn scanexp(l: *lex) void = {
|
||||
for (true) {
|
||||
let c: i32 = lpeek(l, 0u64);
|
||||
if (c < 0) { break; };
|
||||
if (!ascii.isdigit(c: u8)) { break; };
|
||||
if (!ascii.isdigit(c: rune)) { break; };
|
||||
lget(l);
|
||||
};
|
||||
};
|
||||
@@ -390,12 +390,12 @@ fn lexnum(l: *lex, start: *pos, out: *tok) void = {
|
||||
|
||||
let pc: i32 = lpeek(l, 0u64);
|
||||
if (pc >= 0) {
|
||||
if (ascii.isidstart(pc: u8)) {
|
||||
if (ascii.isidstart(pc: rune)) {
|
||||
let sb: u64 = l.lpos;
|
||||
for (true) {
|
||||
let cc: i32 = lpeek(l, 0u64);
|
||||
if (cc < 0) { break; };
|
||||
if (!ascii.isidpart(cc: u8)) { break; };
|
||||
if (!ascii.isidpart(cc: rune)) { break; };
|
||||
lget(l);
|
||||
};
|
||||
let sl: u64 = l.lpos - sb;
|
||||
@@ -439,7 +439,7 @@ fn lexident(l: *lex, start: *pos, out: *tok) void = {
|
||||
for (true) {
|
||||
let c: i32 = lpeek(l, 0u64);
|
||||
if (c < 0) { break; };
|
||||
if (!ascii.isidpart(c: u8)) { break; };
|
||||
if (!ascii.isidpart(c: rune)) { break; };
|
||||
lget(l);
|
||||
};
|
||||
let n: u64 = l.lpos - begin;
|
||||
@@ -588,8 +588,8 @@ export fn lexnext(l: *lex, out: *tok) void = {
|
||||
let c: i32 = lpeek(l, 0u64);
|
||||
|
||||
if (c >= 0) {
|
||||
if (ascii.isidstart(c: u8)) { lexident(l, &start, out); return; };
|
||||
if (ascii.isdigit(c: u8)) { lexnum(l, &start, out); return; };
|
||||
if (ascii.isidstart(c: rune)) { lexident(l, &start, out); return; };
|
||||
if (ascii.isdigit(c: rune)) { lexnum(l, &start, out); return; };
|
||||
};
|
||||
|
||||
if (c == 34) { lget(l); lexstr(l, &start, out); return; };
|
||||
|
||||
@@ -372,10 +372,10 @@ export fn tokprint(fd: i32, t: *tok) void = {
|
||||
};
|
||||
fputcbyte(fd, 58u8); // ':'
|
||||
let buf: [32]u8;
|
||||
let n: i32 = strconv.i64toa(buf[0:32], t.line: i64);
|
||||
let n: i32 = strconv.i64tos(buf[0:32], t.line: i64);
|
||||
os.write(fd, buf.ptr, n: u64);
|
||||
fputcbyte(fd, 58u8);
|
||||
n = strconv.i64toa(buf[0:32], t.col: i64);
|
||||
n = strconv.i64tos(buf[0:32], t.col: i64);
|
||||
os.write(fd, buf.ptr, n: u64);
|
||||
fputcbyte(fd, 32u8); // ' '
|
||||
fputsstr(fd, tokname(t.kind));
|
||||
@@ -391,11 +391,11 @@ export fn tokprint(fd: i32, t: *tok) void = {
|
||||
fputq(fd, ttext.ptr, ttext.len);
|
||||
} else { if (t.kind == TK_INT) {
|
||||
fputcbyte(fd, 32u8);
|
||||
n = strconv.u64toa(buf[0:32], t.uval);
|
||||
n = strconv.u64tos(buf[0:32], t.uval);
|
||||
os.write(fd, buf.ptr, n: u64);
|
||||
} else { if (t.kind == TK_RUNE) {
|
||||
fputcbyte(fd, 32u8);
|
||||
n = strconv.u64toa(buf[0:32], t.uval);
|
||||
n = strconv.u64tos(buf[0:32], t.uval);
|
||||
os.write(fd, buf.ptr, n: u64);
|
||||
};};};};};
|
||||
// TK_FLOAT is intentionally not handled here — %g formatting
|
||||
|
||||
Reference in New Issue
Block a user