lib/encoding/hex: align to Hare io-streaming surface
The old buffer surface (encodedsize/decodedsize + encode(dst,src) i32 + decode(dst,src) (i32|invalid)) does not exist in Hare — it predates the #94 io vtable and mis-cited hex.ha:175 while implementing a different signature. Replace it with Hare's real surface (ref/hare/encoding/hex/hex.ha): - newencoder(out: io.handle) (:28) — write-only encoder stream. - encode(out: io.handle, in) (size | io.error) (:91). - encodestr(in) str (:68). - decodestr(s) ([]u8 | errors.invalid) (:175). Divergences (documented at-site): - The streaming DECODER (newdecoder/decode_reader, :120,:129) is DEFERRED to #247, blocked on #199b: Hare's decode_reader returns errors::invalid, which fits Hare's io::error (spreads ...errors::error). ww's io.error (lib/io/types.ww:55-62) does not carry errors.invalid, and io.read's (size|eof|error) can't propagate it, so a hex decoder *stream* can't faithfully report invalid hex through io.read yet. decodestr ships as a direct transform meanwhile. - nomem dropped from encodestr/decodestr returns (ww memio.dynamic has no failure path — same memio.string rule-9 carve-out, memio.ww:208). - The local hex.invalid type is deleted in favor of errors.invalid (that was the original divergence). - encode uses a single io.write rather than Hare's io::writeall (ww has none — fmt.fprint:498-501: callers drive write-all over raw io.write; encode_writer is whole-slice so a single write is equivalent). - dump (:212) deferred: ww has no default-arg support and fmt's formattable lacks u64 (#209), so the address column can't be ported faithfully yet. hex is now import-bearing, so it moves off the 900_stdlib standalone- compile list (like fmt/os/strings/bufio/bytes/errors before it); coverage stays at 979_hex_run.c. The stale "mirrors lib/encoding/hex.encode" comments in lib/encoding/utf8/utf8.ww are updated, which regenerates the 6 selfhost combined.ww (5 cmd + test/smoke) (comment-only, byte-id-neutral).
This commit is contained in:
@@ -11,8 +11,7 @@
|
||||
//
|
||||
// - `encoderune` takes a caller-supplied `out: []u8` and returns
|
||||
// the byte count. Hare returns a slice into a `static let buf`;
|
||||
// the caller-buffer form mirrors lib/encoding/hex.encode and
|
||||
// skips the static-buffer/slice-return pair.
|
||||
// the caller-buffer form skips the static-buffer/slice-return pair.
|
||||
//
|
||||
// Deferred (no in-tree caller, follow-up tasks): `appendrune`,
|
||||
// `strencode`, `strdecode`. Hare's string-iteration surface
|
||||
@@ -309,8 +308,8 @@ export fn utf8sz(c: u8) (i32 | invalid) = {
|
||||
// same precondition Hare asserts at ref/hare/encoding/utf8/encode.ha:9.
|
||||
//
|
||||
// Surface deviation: Hare returns `[]u8` (slice into a static buf).
|
||||
// ww uses the caller-buffer form (matches lib/encoding/hex.encode);
|
||||
// caller can reuse a [4]u8 stack scratch across encodes.
|
||||
// ww uses the caller-buffer form; caller can reuse a [4]u8 stack
|
||||
// scratch across encodes.
|
||||
export fn encoderune(out: []u8, r: rune) i32 = {
|
||||
let ch: u32 = r: u32;
|
||||
if (ch >= 0xD800u32) {
|
||||
|
||||
Reference in New Issue
Block a user