hare

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

commit 2d2782ce39cb00448068633542be4705eefa8e3b
parent 16161f396538042ad18382a8206bc80292775880
Author: Drew DeVault <sir@cmpwn.com>
Date:   Mon,  1 Feb 2021 10:07:47 -0500

stdlib: incorporate os::open

Diffstat:
MMakefile | 3++-
Mmain.ha | 13++++++++++++-
Mstdlib.mk | 14++++++++++++++
3 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/Makefile b/Makefile @@ -12,7 +12,7 @@ hare: .s.o: @printf 'AS\t$@\n' - @$(AS) -o $@ $< + @$(AS) -g -o $@ $< include stdlib.mk @@ -25,6 +25,7 @@ $(HARECACHE)/hare.ssa: $(hare_srcs) hare_deps=\ $(stdlib_bytes) \ + $(stdlib_fmt) \ $(stdlib_io) \ $(stdlib_os) \ $(stdlib_strconv) \ diff --git a/main.ha b/main.ha @@ -2,9 +2,20 @@ 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, + err: io::error => { + io::errorln(io::errstr(err)); + os::exit(1); + }, + }; + }; + let buf: [1024]u8 = [0u8...]; for (true) { - match (io::read(os::stdin, buf[..])) { + match (io::read(in, buf[..])) { err: io::error => match (err) { err: io::closed => break, * => abort(), diff --git a/stdlib.mk b/stdlib.mk @@ -103,12 +103,26 @@ $(HARECACHE)/strings/strings.ssa: $(libstrings_srcs) $(libstrings_deps) stdlib_strings=$(HARECACHE)/strings/strings.o +# fmt +libfmt_srcs=\ + $(STDLIB)/fmt/fmt.ha + +libfmt_deps=$(stdlib_rt) $(stdlib_types) $(stdlib_io) + +$(HARECACHE)/fmt/fmt.ssa: $(libfmt_srcs) $(libfmt_deps) + @printf 'HAREC \t$@\n' + @mkdir -p $(HARECACHE)/fmt + @$(HAREC) -o $@ -Nfmt -t$(HARECACHE)/fmt/fmt.td $(libfmt_srcs) + +stdlib_fmt=$(HARECACHE)/fmt/fmt.o + # os libos_srcs=\ $(STDLIB)/os/$(PLATFORM)/environ.ha \ $(STDLIB)/os/$(PLATFORM)/errors.ha \ $(STDLIB)/os/$(PLATFORM)/exit.ha \ $(STDLIB)/os/$(PLATFORM)/fdstream.ha \ + $(STDLIB)/os/$(PLATFORM)/open.ha \ $(STDLIB)/os/$(PLATFORM)/stdfd.ha \ $(STDLIB)/os/environ.ha \ $(STDLIB)/os/stdfd.ha