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:
@@ -1,92 +1,92 @@
|
||||
// ascii — byte-class predicates and case folding for the ASCII range.
|
||||
// Matches Hare's ascii::isdigit family. Bytes outside 0..127 always
|
||||
// answer `false`. The lexer hot path uses these inline; they are
|
||||
// expected to inline to a couple of compares.
|
||||
// ascii — rune-class predicates and case folding for the ASCII range.
|
||||
// Matches Hare's ascii::isdigit family (rune-taking signature). Runes
|
||||
// outside 0..127 always answer `false`. The lexer hot path uses these
|
||||
// inline; they are expected to inline to a couple of compares.
|
||||
|
||||
export fn isdigit(c: u8) bool = {
|
||||
if (c < 48u8) { return false; };
|
||||
if (c > 57u8) { return false; };
|
||||
export fn isdigit(c: rune) bool = {
|
||||
if (c < 48) { return false; };
|
||||
if (c > 57) { return false; };
|
||||
return true;
|
||||
};
|
||||
|
||||
export fn isupper(c: u8) bool = {
|
||||
if (c < 65u8) { return false; };
|
||||
if (c > 90u8) { return false; };
|
||||
export fn isupper(c: rune) bool = {
|
||||
if (c < 65) { return false; };
|
||||
if (c > 90) { return false; };
|
||||
return true;
|
||||
};
|
||||
|
||||
export fn islower(c: u8) bool = {
|
||||
if (c < 97u8) { return false; };
|
||||
if (c > 122u8) { return false; };
|
||||
export fn islower(c: rune) bool = {
|
||||
if (c < 97) { return false; };
|
||||
if (c > 122) { return false; };
|
||||
return true;
|
||||
};
|
||||
|
||||
export fn isalpha(c: u8) bool = {
|
||||
export fn isalpha(c: rune) bool = {
|
||||
if (isupper(c)) { return true; };
|
||||
return islower(c);
|
||||
};
|
||||
|
||||
export fn isalnum(c: u8) bool = {
|
||||
export fn isalnum(c: rune) bool = {
|
||||
if (isalpha(c)) { return true; };
|
||||
return isdigit(c);
|
||||
};
|
||||
|
||||
// isspace — the C/Hare set: space, tab, NL, VT, FF, CR.
|
||||
export fn isspace(c: u8) bool = {
|
||||
if (c == 32u8) { return true; }; // ' '
|
||||
if (c == 9u8) { return true; }; // '\t'
|
||||
if (c == 10u8) { return true; }; // '\n'
|
||||
if (c == 11u8) { return true; }; // '\v'
|
||||
if (c == 12u8) { return true; }; // '\f'
|
||||
if (c == 13u8) { return true; }; // '\r'
|
||||
export fn isspace(c: rune) bool = {
|
||||
if (c == 32) { return true; }; // ' '
|
||||
if (c == 9) { return true; }; // '\t'
|
||||
if (c == 10) { return true; }; // '\n'
|
||||
if (c == 11) { return true; }; // '\v'
|
||||
if (c == 12) { return true; }; // '\f'
|
||||
if (c == 13) { return true; }; // '\r'
|
||||
return false;
|
||||
};
|
||||
|
||||
export fn ishex(c: u8) bool = {
|
||||
export fn isxdigit(c: rune) bool = {
|
||||
if (isdigit(c)) { return true; };
|
||||
if (c >= 65u8) {
|
||||
if (c <= 70u8) { return true; }; // 'A'..'F'
|
||||
if (c >= 65) {
|
||||
if (c <= 70) { return true; }; // 'A'..'F'
|
||||
};
|
||||
if (c >= 97u8) {
|
||||
if (c <= 102u8) { return true; }; // 'a'..'f'
|
||||
if (c >= 97) {
|
||||
if (c <= 102) { return true; }; // 'a'..'f'
|
||||
};
|
||||
return false;
|
||||
};
|
||||
|
||||
// digitval — value of `c` as a hex/decimal digit, or -1 if not one.
|
||||
// Useful when scanning numeric literals.
|
||||
export fn digitval(c: u8) i32 = {
|
||||
if (isdigit(c)) { return (c - 48u8): i32; };
|
||||
if (c >= 65u8) {
|
||||
if (c <= 70u8) { return ((c - 65u8) + 10u8): i32; };
|
||||
export fn digitval(c: rune) i32 = {
|
||||
if (isdigit(c)) { return (c - 48): i32; };
|
||||
if (c >= 65) {
|
||||
if (c <= 70) { return ((c - 65) + 10): i32; };
|
||||
};
|
||||
if (c >= 97u8) {
|
||||
if (c <= 102u8) { return ((c - 97u8) + 10u8): i32; };
|
||||
if (c >= 97) {
|
||||
if (c <= 102) { return ((c - 97) + 10): i32; };
|
||||
};
|
||||
return -1;
|
||||
};
|
||||
|
||||
// isidstart / isidpart — identifier classes used by the lexer.
|
||||
// Alpha or '_' starts; alnum or '_' continues.
|
||||
export fn isidstart(c: u8) bool = {
|
||||
export fn isidstart(c: rune) bool = {
|
||||
if (isalpha(c)) { return true; };
|
||||
if (c == 95u8) { return true; }; // '_'
|
||||
if (c == 95) { return true; }; // '_'
|
||||
return false;
|
||||
};
|
||||
|
||||
export fn isidpart(c: u8) bool = {
|
||||
export fn isidpart(c: rune) bool = {
|
||||
if (isalnum(c)) { return true; };
|
||||
if (c == 95u8) { return true; };
|
||||
if (c == 95) { return true; };
|
||||
return false;
|
||||
};
|
||||
|
||||
// tolower / toupper — fold ASCII case. Non-letters pass through.
|
||||
export fn tolower(c: u8) u8 = {
|
||||
if (isupper(c)) { return c + 32u8; };
|
||||
export fn tolower(c: rune) rune = {
|
||||
if (isupper(c)) { return c + 32; };
|
||||
return c;
|
||||
};
|
||||
|
||||
export fn toupper(c: u8) u8 = {
|
||||
if (islower(c)) { return c - 32u8; };
|
||||
export fn toupper(c: rune) rune = {
|
||||
if (islower(c)) { return c - 32; };
|
||||
return c;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user