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:
@@ -10,14 +10,17 @@ export fn print(s: str) i64 = {
|
||||
return os.write(1, s.ptr, s.len: u64);
|
||||
};
|
||||
|
||||
export fn println(s: str) void = {
|
||||
os.write(1, s.ptr, s.len: u64);
|
||||
os.write(1, "\n".ptr, 1u64);
|
||||
export fn println(s: str) i64 = {
|
||||
let n: i64 = os.write(1, s.ptr, s.len: u64);
|
||||
if (n < 0) { return n; };
|
||||
let m: i64 = os.write(1, "\n".ptr, 1u64);
|
||||
if (m < 0) { return m; };
|
||||
return n + m;
|
||||
};
|
||||
|
||||
export fn printint(v: i64) void = {
|
||||
let buf: [32]u8;
|
||||
let n: i32 = strconv.i64toa(buf[0:32], v);
|
||||
let n: i32 = strconv.i64tos(buf[0:32], v);
|
||||
os.write(1, buf.ptr, n: u64);
|
||||
};
|
||||
|
||||
@@ -26,10 +29,13 @@ export fn printlnint(v: i64) void = {
|
||||
os.write(1, "\n".ptr, 1u64);
|
||||
};
|
||||
|
||||
// errln — write a message to stderr with a trailing newline.
|
||||
export fn errln(s: str) void = {
|
||||
os.write(2, s.ptr, s.len: u64);
|
||||
os.write(2, "\n".ptr, 1u64);
|
||||
// errorln — write a message to stderr with a trailing newline.
|
||||
export fn errorln(s: str) i64 = {
|
||||
let n: i64 = os.write(2, s.ptr, s.len: u64);
|
||||
if (n < 0) { return n; };
|
||||
let m: i64 = os.write(2, "\n".ptr, 1u64);
|
||||
if (m < 0) { return m; };
|
||||
return n + m;
|
||||
};
|
||||
|
||||
// fprint / fprintln — same as print/println but on an arbitrary fd.
|
||||
@@ -38,14 +44,17 @@ export fn fprint(fd: i32, s: str) i64 = {
|
||||
return os.write(fd, s.ptr, s.len: u64);
|
||||
};
|
||||
|
||||
export fn fprintln(fd: i32, s: str) void = {
|
||||
os.write(fd, s.ptr, s.len: u64);
|
||||
os.write(fd, "\n".ptr, 1u64);
|
||||
export fn fprintln(fd: i32, s: str) i64 = {
|
||||
let n: i64 = os.write(fd, s.ptr, s.len: u64);
|
||||
if (n < 0) { return n; };
|
||||
let m: i64 = os.write(fd, "\n".ptr, 1u64);
|
||||
if (m < 0) { return m; };
|
||||
return n + m;
|
||||
};
|
||||
|
||||
export fn fprintint(fd: i32, v: i64) void = {
|
||||
let buf: [32]u8;
|
||||
let n: i32 = strconv.i64toa(buf[0:32], v);
|
||||
let n: i32 = strconv.i64tos(buf[0:32], v);
|
||||
os.write(fd, buf.ptr, n: u64);
|
||||
};
|
||||
|
||||
@@ -56,10 +65,10 @@ export fn errpos(file: str, line: i32, col: i32, msg: str) void = {
|
||||
os.write(2, file.ptr, file.len: u64);
|
||||
os.write(2, ":".ptr, 1u64);
|
||||
let buf: [32]u8;
|
||||
let n: i32 = strconv.i64toa(buf[0:32], line: i64);
|
||||
let n: i32 = strconv.i64tos(buf[0:32], line: i64);
|
||||
os.write(2, buf.ptr, n: u64);
|
||||
os.write(2, ":".ptr, 1u64);
|
||||
n = strconv.i64toa(buf[0:32], col: i64);
|
||||
n = strconv.i64tos(buf[0:32], col: i64);
|
||||
os.write(2, buf.ptr, n: u64);
|
||||
os.write(2, ": ".ptr, 2u64);
|
||||
os.write(2, msg.ptr, msg.len: u64);
|
||||
|
||||
Reference in New Issue
Block a user