lib/strconv: graduate to owned-str returns with Hare-shape base param
i64tos / u64tos / f64tos return a fresh owned str (caller frees via os.free) instead of writing into a caller-supplied [N]u8. Adds typed variants (i32tos / i16tos / i8tos and u32 / u16 / u8) and the missing base parameter on stoi64 / stou64 + typed parse wrappers. Base values are exported as plain-i32 `def`s (strconv.DEC, strconv.HEX_UPPER, ...) rather than a `base` enum: cross-module `strconv.base.DEC` chains miscompile in the cstage cgen — it emits a memory load through `base(SB)` rather than inlining the constant. The Sdef path resolves correctly, so callers say `strconv.DEC` and both cgens lower to an immediate. Also renames strings.byteindex / rbyteindex to strings.indexbyte / rindexbyte, matching bytes.indexbyte and reserving the Hare name `byteindex` for the future `(str | rune)`-needle shape. fmt drops printint / printlnint / fprintint — those were stand-ins for variadic `fmt::println(42)`; with the owned-str graduation the substitute is one call: `fmt.println(strconv.i64tos(42, strconv.DEC))`. strerror is sketched in a comment but not shipped — match arms over the wider `error = !(invalid | overflow)` union still expose a cstage-vs-wwstage spill divergence.
This commit is contained in:
@@ -39,9 +39,12 @@ export fn hassuffix(s: str, suf: str) bool = {
|
||||
return true;
|
||||
};
|
||||
|
||||
// byteindex — first index of byte `c` in `s`. Hare-shaped optional:
|
||||
// (i32 | void). void variant indicates "not found".
|
||||
export fn byteindex(s: str, c: u8) (i32 | void) = {
|
||||
// indexbyte — first byte position of byte `c` in `s`. Mirrors
|
||||
// Hare's strings::byteindex when the needle is a single ASCII rune,
|
||||
// renamed to match bytes.indexbyte and to disambiguate from Hare's
|
||||
// `byteindex(haystack, needle: (str | rune))` which we don't have
|
||||
// the union-arg ABI for yet.
|
||||
export fn indexbyte(s: str, c: u8) (i32 | void) = {
|
||||
let i: i32 = 0;
|
||||
for (i < s.len) {
|
||||
if (s[i] == c) { return i; };
|
||||
@@ -50,9 +53,8 @@ export fn byteindex(s: str, c: u8) (i32 | void) = {
|
||||
return;
|
||||
};
|
||||
|
||||
// rbyteindex — last index of byte `c` in `s`. Mirrors Hare's
|
||||
// strings::rbyteindex.
|
||||
export fn rbyteindex(s: str, c: u8) (i32 | void) = {
|
||||
// rindexbyte — last byte position of byte `c` in `s`.
|
||||
export fn rindexbyte(s: str, c: u8) (i32 | void) = {
|
||||
let i: i32 = s.len - 1;
|
||||
for (i >= 0) {
|
||||
if (s[i] == c) { return i; };
|
||||
|
||||
Reference in New Issue
Block a user