hare

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

commit 131b3302730a1c3747bc7dd0cade52794b7aa40f
parent 33fc975ce07a10ec73cb60a28c6efe8072b0bfac
Author: Drew DeVault <sir@cmpwn.com>
Date:   Sun, 14 Feb 2021 11:10:48 -0500

update stdlib

Diffstat:
Mgen-stdlib | 10+++++++++-
Mmain.ha | 32+++++++++++++++-----------------
Mmk/stdlib.mk | 30++++++++++++++++++++++++++++--
3 files changed, 52 insertions(+), 20 deletions(-)

diff --git a/gen-stdlib b/gen-stdlib @@ -94,6 +94,13 @@ ascii() { gen_ssa ascii } +bufio() { + printf '# bufio\n' + gen_srcs bufio \ + fixed.ha + gen_ssa bufio io +} + bytes() { printf '# bytes\n' gen_srcs bytes \ @@ -136,7 +143,7 @@ hare_lex() { gen_srcs hare::lex \ token.ha \ lex.ha - gen_ssa hare::lex io strings types + gen_ssa hare::lex io bufio strings types } gensrcs_io() { @@ -247,6 +254,7 @@ types() { printf '# This file is generated by the gen-stdlib script, do not edit it by hand\n\n' modules="ascii +bufio bytes crypto_random encoding_utf8 diff --git a/main.ha b/main.ha @@ -1,25 +1,23 @@ use fmt; +use types; +use hare::lex; use io; use os; +use strconv; export fn main() void = { - if (len(os::args) == 1z) match (io::copy(os::stdout, os::stdin)) { - err: io::error => fmt::fatal("Error: {}", io::errstr(err)), - size => os::exit(0), - }; - - for (let i = 1z; i < len(os::args); i += 1z) { - let in = match (os::open(os::args[i], io::mode::RDONLY)) { - stream: *io::stream => stream, - err: io::error => fmt::fatal("Error: {}: {}", - os::args[i], io::errstr(err)), - }; - defer io::close(in); - - match (io::copy(os::stdout, in)) { - err: io::error => - fmt::fatal("Error: {}", io::errstr(err)), - size => void, + let lexer = lex::lexer_init(os::stdin, "<stdin>"); + for (true) { + match (lex::lex(&lexer)) { + t: (lex::token, lex::location) => { + let tok = t.0, loc = t.1; + fmt::println("{}@{},{}: '{}'", + loc.path, loc.line, loc.col, + lex::tokstr(tok)); + }, + err: lex::error => fmt::fatal("Error: {}", lex::errstr(err)), + io::EOF => break, + * => abort(), }; }; }; diff --git a/mk/stdlib.mk b/mk/stdlib.mk @@ -63,6 +63,9 @@ hare_stdlib_deps+=$(stdlib_rt) stdlib_ascii=$(HARECACHE)/ascii/ascii.o hare_stdlib_deps+=$(stdlib_ascii) +stdlib_bufio=$(HARECACHE)/bufio/bufio.o +hare_stdlib_deps+=$(stdlib_bufio) + stdlib_bytes=$(HARECACHE)/bytes/bytes.o hare_stdlib_deps+=$(stdlib_bytes) @@ -106,6 +109,16 @@ $(HARECACHE)/ascii/ascii.ssa: $(stdlib_ascii_srcs) $(stdlib_rt) @HARECACHE=$(HARECACHE) $(HAREC) $(HAREFLAGS) -o $@ -Nascii \ -t$(HARECACHE)/ascii/ascii.td $(stdlib_ascii_srcs) +# bufio +stdlib_bufio_srcs= \ + $(STDLIB)/bufio/fixed.ha + +$(HARECACHE)/bufio/bufio.ssa: $(stdlib_bufio_srcs) $(stdlib_rt) $(stdlib_io) + @printf 'HAREC \t$@\n' + @mkdir -p $(HARECACHE)/bufio + @HARECACHE=$(HARECACHE) $(HAREC) $(HAREFLAGS) -o $@ -Nbufio \ + -t$(HARECACHE)/bufio/bufio.td $(stdlib_bufio_srcs) + # bytes stdlib_bytes_srcs= \ $(STDLIB)/bytes/contains.ha \ @@ -159,7 +172,7 @@ stdlib_hare_lex_srcs= \ $(STDLIB)/hare/lex/token.ha \ $(STDLIB)/hare/lex/lex.ha -$(HARECACHE)/hare/lex/hare.lex.ssa: $(stdlib_hare_lex_srcs) $(stdlib_rt) $(stdlib_io) $(stdlib_strings) $(stdlib_types) +$(HARECACHE)/hare/lex/hare.lex.ssa: $(stdlib_hare_lex_srcs) $(stdlib_rt) $(stdlib_io) $(stdlib_bufio) $(stdlib_strings) $(stdlib_types) @printf 'HAREC \t$@\n' @mkdir -p $(HARECACHE)/hare/lex @HARECACHE=$(HARECACHE) $(HAREC) $(HAREFLAGS) -o $@ -Nhare::lex \ @@ -316,6 +329,9 @@ hare_testlib_deps+=$(testlib_rt) testlib_ascii=$(TESTCACHE)/ascii/ascii.o hare_testlib_deps+=$(testlib_ascii) +testlib_bufio=$(TESTCACHE)/bufio/bufio.o +hare_testlib_deps+=$(testlib_bufio) + testlib_bytes=$(TESTCACHE)/bytes/bytes.o hare_testlib_deps+=$(testlib_bytes) @@ -359,6 +375,16 @@ $(TESTCACHE)/ascii/ascii.ssa: $(testlib_ascii_srcs) $(testlib_rt) @HARECACHE=$(TESTCACHE) $(HAREC) $(TESTHAREFLAGS) -o $@ -Nascii \ -t$(TESTCACHE)/ascii/ascii.td $(testlib_ascii_srcs) +# bufio +testlib_bufio_srcs= \ + $(STDLIB)/bufio/fixed.ha + +$(TESTCACHE)/bufio/bufio.ssa: $(testlib_bufio_srcs) $(testlib_rt) $(testlib_io) + @printf 'HAREC \t$@\n' + @mkdir -p $(TESTCACHE)/bufio + @HARECACHE=$(TESTCACHE) $(HAREC) $(TESTHAREFLAGS) -o $@ -Nbufio \ + -t$(TESTCACHE)/bufio/bufio.td $(testlib_bufio_srcs) + # bytes testlib_bytes_srcs= \ $(STDLIB)/bytes/contains.ha \ @@ -412,7 +438,7 @@ testlib_hare_lex_srcs= \ $(STDLIB)/hare/lex/token.ha \ $(STDLIB)/hare/lex/lex.ha -$(TESTCACHE)/hare/lex/hare.lex.ssa: $(testlib_hare_lex_srcs) $(testlib_rt) $(testlib_io) $(testlib_strings) $(testlib_types) +$(TESTCACHE)/hare/lex/hare.lex.ssa: $(testlib_hare_lex_srcs) $(testlib_rt) $(testlib_io) $(testlib_bufio) $(testlib_strings) $(testlib_types) @printf 'HAREC \t$@\n' @mkdir -p $(TESTCACHE)/hare/lex @HARECACHE=$(TESTCACHE) $(HAREC) $(TESTHAREFLAGS) -o $@ -Nhare::lex \