hare

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

commit 760beba083fa7ef67a20d914c764a99bf34e4b4e
parent e271e93934b0e0a06e9d6e53c6e1bff7edd64d0e
Author: Drew DeVault <sir@cmpwn.com>
Date:   Mon,  1 Feb 2021 17:39:45 -0500

Rig up encoding::utf8

Diffstat:
MMakefile | 1+
Mmain.ha | 42++++++++++++++++++------------------------
Mstdlib.mk | 15+++++++++++++++
3 files changed, 34 insertions(+), 24 deletions(-)

diff --git a/Makefile b/Makefile @@ -25,6 +25,7 @@ $(HARECACHE)/hare.ssa: $(hare_srcs) hare_deps=\ $(stdlib_bytes) \ + $(stdlib_encoding_utf8) \ $(stdlib_fmt) \ $(stdlib_io) \ $(stdlib_os) \ diff --git a/main.ha b/main.ha @@ -1,30 +1,24 @@ +use encoding::utf8; +use strings; use io; -use os; export fn main() void = { - if (len(os::args) == 1z) { - match (io::copy(os::stdout, os::stdin)) { - err: io::error => fatal(io::errstr(err)), - size => void, + const expected = ['こ', 'ん', 'に', 'ち', 'は']; + let decoder = utf8::decode("こんにちは"); + let i = 0z; + for (true) { + match (utf8::next(&decoder)) { + r: rune => { + assert(r == expected[i]); + i += 1z; + }, + void => { + assert(i == len(expected)); + break; + }, + utf8::more => abort("more"), + utf8::invalid => abort("invalid"), }; - return; }; - - 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, - }; - }; -}; - -@noreturn fn fatal(why: str) void = { - io::errorln(why); - os::exit(1); + io::println("tada!"); }; diff --git a/stdlib.mk b/stdlib.mk @@ -106,6 +106,21 @@ $(HARECACHE)/strings/strings.ssa: $(libstrings_srcs) $(libstrings_deps) stdlib_strings=$(HARECACHE)/strings/strings.o +# encoding/utf8 +# XXX: Also has ordering issues +libencoding_utf8_srcs=\ + $(STDLIB)/encoding/utf8/rune.ha \ + $(STDLIB)/encoding/utf8/decode.ha + +libencoding_utf8_deps=$(stdlib_rt) $(stdlib_types) $(stdlib_strings) + +$(HARECACHE)/encoding/utf8/encoding.utf8.ssa: $(libencoding_utf8_srcs) $(libencoding_utf8_deps) + @printf 'HAREC \t$@\n' + @mkdir -p $(HARECACHE)/encoding/utf8 + @$(HAREC) -o $@ -Nencoding::utf8 -t$(HARECACHE)/encoding/utf8/encoding.utf8.td $(libencoding_utf8_srcs) + +stdlib_encoding_utf8=$(HARECACHE)/encoding/utf8/encoding.utf8.o + # fmt libfmt_srcs=\ $(STDLIB)/fmt/fmt.ha