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:
@@ -146,7 +146,7 @@ static const struct row rows[] = {
|
||||
"fn main() i32 = {\n"
|
||||
" let buf: [32]u8;\n"
|
||||
" let s: []u8 = buf[0:32];\n"
|
||||
" let n: i32 = strconv.i64toa(s, 12345);\n"
|
||||
" let n: i32 = strconv.i64tos(s, 12345);\n"
|
||||
" os.write(1, buf.ptr, n: u64);\n"
|
||||
" os.write(1, \"\\n\".ptr, 1u64);\n"
|
||||
" return n;\n"
|
||||
@@ -703,14 +703,14 @@ static const struct row rows[] = {
|
||||
" };\n"
|
||||
" return acc;\n"
|
||||
"};", 13 }, /* 1 byte written to fd 1, plus len(\"write failed\")=12 */
|
||||
/* strconv.parse64: fallible signed decimal. Two successful
|
||||
/* strconv.stoi64: fallible signed decimal. Two successful
|
||||
* parses contribute their values; one bad parse contributes
|
||||
* the error message length (20 = len(\"parse: invalid digit\")). */
|
||||
{ "use strconv;\n"
|
||||
"fn main() i32 = {\n"
|
||||
" let r1: (i64 | str) = strconv.parse64(\"42\");\n"
|
||||
" let r2: (i64 | str) = strconv.parse64(\"-7\");\n"
|
||||
" let r3: (i64 | str) = strconv.parse64(\"abc\");\n"
|
||||
" let r1: (i64 | str) = strconv.stoi64(\"42\");\n"
|
||||
" let r2: (i64 | str) = strconv.stoi64(\"-7\");\n"
|
||||
" let r3: (i64 | str) = strconv.stoi64(\"abc\");\n"
|
||||
" let acc: i32 = 0;\n"
|
||||
" match (r1) {\n"
|
||||
" case let v: i64 => acc += v: i32;\n"
|
||||
@@ -726,12 +726,12 @@ static const struct row rows[] = {
|
||||
" };\n"
|
||||
" return acc;\n"
|
||||
"};", 55 }, /* 42 + (-7) + 20 */
|
||||
/* strconv.parseu64: success path 123, error path captures
|
||||
/* strconv.stou64: success path 123, error path captures
|
||||
* len(\"parse: invalid digit\") = 20 for the leading-sign reject. */
|
||||
{ "use strconv;\n"
|
||||
"fn main() i32 = {\n"
|
||||
" let r1: (u64 | str) = strconv.parseu64(\"123\");\n"
|
||||
" let r2: (u64 | str) = strconv.parseu64(\"-1\");\n"
|
||||
" let r1: (u64 | str) = strconv.stou64(\"123\");\n"
|
||||
" let r2: (u64 | str) = strconv.stou64(\"-1\");\n"
|
||||
" let acc: i32 = 0;\n"
|
||||
" match (r1) {\n"
|
||||
" case let v: u64 => acc += v: i32;\n"
|
||||
@@ -743,17 +743,17 @@ static const struct row rows[] = {
|
||||
" };\n"
|
||||
" return acc;\n"
|
||||
"};", 143 }, /* 123 + 20 */
|
||||
/* strings.indexbyte (Plan 9 -1) and strings.index (substring). */
|
||||
/* strings.byteindex (Plan 9 -1) and strings.index (substring). */
|
||||
{ "use strings;\n"
|
||||
"fn main() i32 = {\n"
|
||||
" let s: str = \"hello, world\";\n"
|
||||
" let i1: i32 = strings.indexbyte(s, 44u8);\n"
|
||||
" let i2: i32 = strings.indexbyte(s, 122u8);\n"
|
||||
" let i1: i32 = strings.byteindex(s, 44u8);\n"
|
||||
" let i2: i32 = strings.byteindex(s, 122u8);\n"
|
||||
" let i3: i32 = strings.index(s, \"world\");\n"
|
||||
" let i4: i32 = strings.index(s, \"nope\");\n"
|
||||
" return i1 + i2 + i3 + i4;\n"
|
||||
"};", 10 }, /* 5 + (-1) + 7 + (-1) */
|
||||
/* bytes.indexsub: substring search over []u8. */
|
||||
/* bytes.index: substring search over []u8. */
|
||||
{ "use bytes;\n"
|
||||
"fn main() i32 = {\n"
|
||||
" let buf: [12]u8;\n"
|
||||
@@ -762,15 +762,15 @@ static const struct row rows[] = {
|
||||
" buf[8] = 111u8; buf[9] = 114u8; buf[10] = 108u8; buf[11] = 100u8;\n"
|
||||
" let needle: [3]u8;\n"
|
||||
" needle[0] = 119u8; needle[1] = 111u8; needle[2] = 114u8;\n"
|
||||
" return bytes.indexsub(buf[0:12], needle[0:3]);\n"
|
||||
" return bytes.index(buf[0:12], needle[0:3]);\n"
|
||||
"};", 7 },
|
||||
/* errors.equal — sentinel comparison through a (T | error) union.
|
||||
* Sets up two errors, dispatches each, and confirms the matching
|
||||
* sentinel detection. */
|
||||
{ "use errors;\n"
|
||||
"fn parse(n: i64) (i64 | errors.error) = {\n"
|
||||
" if (n < 0) { return errors.eEOF; };\n"
|
||||
" if (n == 0) { return errors.eShortRead; };\n"
|
||||
" if (n < 0) { return errors.eof; };\n"
|
||||
" if (n == 0) { return errors.underread; };\n"
|
||||
" return n;\n"
|
||||
"};\n"
|
||||
"fn main() i32 = {\n"
|
||||
@@ -780,18 +780,18 @@ static const struct row rows[] = {
|
||||
" match (r1) {\n"
|
||||
" case let v: i64 => acc += -100;\n"
|
||||
" case let e: errors.error =>\n"
|
||||
" if (errors.equal(e, errors.eEOF)) { acc += 1; }\n"
|
||||
" if (errors.equal(e, errors.eof)) { acc += 1; }\n"
|
||||
" else { acc += -100; };\n"
|
||||
" };\n"
|
||||
" match (r2) {\n"
|
||||
" case let v: i64 => acc += -100;\n"
|
||||
" case let e: errors.error =>\n"
|
||||
" if (errors.equal(e, errors.eShortRead)) { acc += 10; }\n"
|
||||
" if (errors.equal(e, errors.underread)) { acc += 10; }\n"
|
||||
" else { acc += -100; };\n"
|
||||
" };\n"
|
||||
" return acc;\n"
|
||||
"};", 11 },
|
||||
/* bufio.takeline: drain successive '\\n'-terminated lines from a
|
||||
/* bufio.readline: drain successive '\\n'-terminated lines from a
|
||||
* pre-filled buffer, then a trailing fragment that returns the
|
||||
* `linerr` variant carrying \"no newline\" (10 chars). */
|
||||
{ "use bufio;\n"
|
||||
@@ -803,17 +803,17 @@ static const struct row rows[] = {
|
||||
" let b: bufio.buf;\n"
|
||||
" b.s = nil; b.data = raw.ptr; b.cap = 11; b.r = 0; b.w = 11;\n"
|
||||
" let acc: i32 = 0;\n"
|
||||
" let l1: (str | bufio.linerr) = bufio.takeline(&b);\n"
|
||||
" let l1: (str | bufio.linerr) = bufio.readline(&b);\n"
|
||||
" match (l1) {\n"
|
||||
" case let s: str => acc += s.len: i32;\n"
|
||||
" case let e: bufio.linerr => acc += -100;\n"
|
||||
" };\n"
|
||||
" let l2: (str | bufio.linerr) = bufio.takeline(&b);\n"
|
||||
" let l2: (str | bufio.linerr) = bufio.readline(&b);\n"
|
||||
" match (l2) {\n"
|
||||
" case let s: str => acc += s.len: i32;\n"
|
||||
" case let e: bufio.linerr => acc += -100;\n"
|
||||
" };\n"
|
||||
" let l3: (str | bufio.linerr) = bufio.takeline(&b);\n"
|
||||
" let l3: (str | bufio.linerr) = bufio.readline(&b);\n"
|
||||
" match (l3) {\n"
|
||||
" case let s: str => acc += -100;\n"
|
||||
" case let e: bufio.linerr => acc += e.len: i32;\n"
|
||||
|
||||
Reference in New Issue
Block a user