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:
@@ -17,7 +17,7 @@ type buf = struct {
|
||||
w: i32, // write cursor (for writers)
|
||||
};
|
||||
|
||||
export fn rinit(b: *buf, s: streamp, data: *u8, cap: i32) void = {
|
||||
export fn init(b: *buf, s: streamp, data: *u8, cap: i32) void = {
|
||||
b.s = s;
|
||||
b.data = data;
|
||||
b.cap = cap;
|
||||
@@ -25,18 +25,10 @@ export fn rinit(b: *buf, s: streamp, data: *u8, cap: i32) void = {
|
||||
b.w = 0;
|
||||
};
|
||||
|
||||
// peek1 — look at the next byte without consuming. Returns -1 on
|
||||
// empty buffer; the caller is responsible for refilling via the
|
||||
// stream when this happens.
|
||||
export fn peek1(b: *buf) i32 = {
|
||||
if (b.r < b.w) {
|
||||
return b.data[b.r]: i32;
|
||||
};
|
||||
return -1;
|
||||
};
|
||||
|
||||
// take1 — pop one byte. -1 if empty.
|
||||
export fn take1(b: *buf) i32 = {
|
||||
// readbyte — pop one byte. -1 if empty. Hare name (transliterated
|
||||
// from `read_byte`); the `-1`-for-EOF return is the sanctioned subset
|
||||
// of Hare's `(u8 | EOF | error)`.
|
||||
export fn readbyte(b: *buf) i32 = {
|
||||
if (b.r < b.w) {
|
||||
let c: u8 = b.data[b.r];
|
||||
b.r += 1;
|
||||
@@ -45,27 +37,23 @@ export fn take1(b: *buf) i32 = {
|
||||
return -1;
|
||||
};
|
||||
|
||||
// avail — bytes left to read out of the buffer.
|
||||
export fn avail(b: *buf) i32 = {
|
||||
return b.w - b.r;
|
||||
};
|
||||
|
||||
// Distinct alias so `(str | linerr)` has two variant types the
|
||||
// tagged-union machinery can keep apart at the tag level. The error
|
||||
// variant carries a short description; callers compare with errors.equal
|
||||
// or just inspect by length.
|
||||
type linerr = str;
|
||||
|
||||
// takeline — Hare-style fallible line read. Drains the buffer up to
|
||||
// (but not including) the next '\n' and advances the cursor past the
|
||||
// newline. Returns the line as a borrowed str on success, or a linerr
|
||||
// describing why no line was available:
|
||||
// readline — Hare-style fallible line read (name transliterated from
|
||||
// `read_line`). Drains the buffer up to (but not including) the next
|
||||
// '\n' and advances the cursor past the newline. Returns the line as
|
||||
// a borrowed str on success, or a linerr describing why no line was
|
||||
// available:
|
||||
// - "eof" when the buffer is empty
|
||||
// - "no newline" when the buffer contains data but no '\n'
|
||||
//
|
||||
// The returned str borrows from the underlying buffer; callers must
|
||||
// consume it (or copy) before refilling.
|
||||
export fn takeline(b: *buf) (str | linerr) = {
|
||||
export fn readline(b: *buf) (str | linerr) = {
|
||||
if (b.r >= b.w) { return "eof": linerr; };
|
||||
let i: i32 = b.r;
|
||||
for (i < b.w) {
|
||||
|
||||
Reference in New Issue
Block a user