hare

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

commit e271e93934b0e0a06e9d6e53c6e1bff7edd64d0e
parent 31eda300b8ae6e669c14df8933653c738594a9ca
Author: Drew DeVault <sir@cmpwn.com>
Date:   Mon,  1 Feb 2021 13:02:40 -0500

main.ha: finish 'cat' example implementation

Diffstat:
Mmain.ha | 30++++++++++++++----------------
Mstdlib.mk | 5++++-
2 files changed, 18 insertions(+), 17 deletions(-)

diff --git a/main.ha b/main.ha @@ -2,26 +2,24 @@ use io; use os; export fn main() void = { - let in = os::stdin; - if (len(os::args) > 1z) { - in = match (os::open(os::args[1], io::mode::RDONLY)) { - stream: *io::stream => stream, + if (len(os::args) == 1z) { + match (io::copy(os::stdout, os::stdin)) { err: io::error => fatal(io::errstr(err)), + size => void, }; + return; }; - defer io::close(in); - let buf: [1024]u8 = [0u8...]; - for (true) { - match (io::read(in, buf[..])) { - err: io::error => match (err) { - io::closed => break, - * => fatal(io::errstr(err)), - }, - n: size => match (io::write(os::stdout, buf[..n])) { - err: io::error => fatal(io::errstr(err)), - * => void, - }, + for (let i = 1z; i < len(os::args); i += 1z) { + let in: *io::stream = match (os::open(os::args[i], io::mode::RDONLY)) { + stream: *io::stream => stream, + err: io::error => fatal(io::errstr(err)), + }; + defer io::close(in); + + match (io::copy(os::stdout, in)) { + err: io::error => fatal(io::errstr(err)), + size => void, }; }; }; diff --git a/stdlib.mk b/stdlib.mk @@ -76,9 +76,12 @@ $(HARECACHE)/strconv/strconv.ssa: $(stdlib_rt) $(stdlib_bytes) $(stdlib_types) stdlib_strconv=$(HARECACHE)/strconv/strconv.o # io +# XXX: Sort me only after fixing forward references to alias types +# Sort it to see what the problem is if you don't understand libio_srcs=\ - $(STDLIB)/io/println.ha \ $(STDLIB)/io/types.ha \ + $(STDLIB)/io/copy.ha \ + $(STDLIB)/io/println.ha \ $(STDLIB)/io/stream.ha $(HARECACHE)/io/io.ssa: $(libio_srcs) $(stdlib_rt)