From e9c3f75fd13b0abf25938f4ad0a75c6f4ac490ad Mon Sep 17 00:00:00 2001 From: Hojun-Cho Date: Tue, 12 May 2026 02:12:33 +0900 Subject: [PATCH] lib: graduate utf8.runesz and bufio.readbyte to (i32 | void) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Both used the -1 sentinel return; both had no external callers, so the graduation is purely the API-shape change. utf8.runesz uses void for "rune outside legal range"; bufio.readbyte uses void for EOF (empty buffer). The full Hare shapes ((size | invalid) and (u8 | EOF | io::error)) are still richer than this — those richer returns arrive when utf8 grows an explicit invalid type and bufio wires through io::stream's error path. --- lib/bufio/bufio.ww | 11 ++++++----- lib/encoding/utf8/utf8.ww | 9 +++++---- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/lib/bufio/bufio.ww b/lib/bufio/bufio.ww index e44482c8..14b2b65f 100644 --- a/lib/bufio/bufio.ww +++ b/lib/bufio/bufio.ww @@ -25,16 +25,17 @@ export fn init(b: *buf, s: streamp, data: *u8, cap: i32) void = { b.w = 0; }; -// 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 = { +// readbyte — pop one byte. void variant signals EOF (empty buffer). +// Hare name; the (i32 | void) shape is a subset of Hare's full +// (u8 | EOF | io::error) — error reporting from the underlying +// stream will arrive when bufio actually wires up to io::stream. +export fn readbyte(b: *buf) (i32 | void) = { if (b.r < b.w) { let c: u8 = b.data[b.r]; b.r += 1; return c: i32; }; - return -1; + return; }; // Distinct alias so `(str | linerr)` has two variant types the diff --git a/lib/encoding/utf8/utf8.ww b/lib/encoding/utf8/utf8.ww index dc1f651e..0185f7d6 100644 --- a/lib/encoding/utf8/utf8.ww +++ b/lib/encoding/utf8/utf8.ww @@ -2,13 +2,14 @@ // subset (no over-long encodings, no surrogates). def MAX: rune = 1114111; // 0x10FFFF -def BAD: rune = -1; -export fn runesz(r: rune) i32 = { - if (r < 0) { return -1; }; +// runesz — encoded byte length of `r` as UTF-8. void variant means +// `r` is outside the legal range (negative, > 0x10FFFF). +export fn runesz(r: rune) (i32 | void) = { + if (r < 0) { return; }; if (r < 128) { return 1; }; if (r < 2048) { return 2; }; if (r < 65536) { return 3; }; if (r <= MAX) { return 4; }; - return -1; + return; };