hare

The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit e1c3d8d76fee48f8b55738595d55342900496835
parent 4dcb5171fbb4c3cdcf5a3fc44c4943a7344afb59
Author: Drew DeVault <sir@cmpwn.com>
Date:   Tue, 16 Feb 2021 09:39:35 -0500

io, strings: style

Diffstat:
Mio/copy.ha | 2+-
Mio/stream.ha | 5++++-
Mio/strings.ha | 6++----
Mstrings/utf8.ha | 2+-
4 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/io/copy.ha b/io/copy.ha @@ -8,7 +8,7 @@ export fn copy(dest: *stream, src: *stream) (error | size) = { unsupported => void, // Use fallback * => return err, }, - s: size => return s, + s: size => return s, }, }; diff --git a/io/stream.ha b/io/stream.ha @@ -70,14 +70,17 @@ export fn tell(s: *stream) (off | error) = { }; }; -// A [stream] which always returns EOF. +// A [stream] which always reads EOF and discards any writes. export let empty: *io::stream = null: *io::stream; // TODO: This can be removed when globals can reference other globals @init fn init() void = { static let s = io::stream { ... }; s.reader = &empty_read; + s.writer = &empty_write; empty = &s; }; fn empty_read(s: *stream, buf: []u8) (size | EOF | error) = EOF; + +fn empty_write(s: *stream, buf: const []u8) (size | error) = len(buf); diff --git a/io/strings.ha b/io/strings.ha @@ -7,9 +7,8 @@ use types; export fn getrune(in: *io::stream) (rune | utf8::invalid | EOF | error) = { let b: [4]u8 = [0...]; match (read(in, b[..1])) { + e: (error | EOF) => return e, n: size => assert(n == 1), - err: error => return err, - EOF => return EOF, }; const sz = utf8::utf8sz(b[0]); @@ -22,9 +21,8 @@ export fn getrune(in: *io::stream) (rune | utf8::invalid | EOF | error) = { }; match (read(in, b[1..sz])) { + e: (error | EOF) => return e, n: size => assert(n == sz - 1), - err: error => return err, - EOF => return EOF, }; let dec = utf8::decode(b[..sz]); diff --git a/strings/utf8.ha b/strings/utf8.ha @@ -17,7 +17,7 @@ export fn from_utf8_unsafe(in: []u8) str = { // [encoding::utf8::decode] instead. export fn from_utf8(in: []u8) str = { let s = from_utf8_unsafe(in); - assert(utf8::valid(s)); + assert(utf8::valid(s), "attempted to load invalid UTF-8 string"); return s; };