hare

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

commit e4d137d5824ee92e7c1343170e494128f3be428d
parent 817e5c0d2bbc5fa608d2a77914e634b323c4443e
Author: Drew DeVault <sir@cmpwn.com>
Date:   Fri,  1 Apr 2022 14:15:02 +0200

io: drop println, errorln

Signed-off-by: Drew DeVault <sir@cmpwn.com>

Diffstat:
Dio/println+freebsd.ha | 37-------------------------------------
Dio/println+linux.ha | 37-------------------------------------
Mmime/system.ha | 5+++--
Mpath/README | 4++--
Mscripts/gen-stdlib | 4+---
Mstdlib.mk | 4----
6 files changed, 6 insertions(+), 85 deletions(-)

diff --git a/io/println+freebsd.ha b/io/println+freebsd.ha @@ -1,37 +0,0 @@ -// License: MPL-2.0 -// (c) 2021 Drew DeVault <sir@cmpwn.com> -use rt; - -// Prints strings to stdout, separated by spaces, and followed by a newline. -// -// The output is unbuffered, and may not have good performance. This is only -// recommended for debugging purposes. See [[fmt::println]] instead. -export fn println(msgs: str...) void = { - for (let i = 0z; i < len(msgs); i += 1) { - let msg = msgs[i]; - rt::write(1, *(&msg: **void): *const char, len(msg)): void; - if (i + 1 < len(msgs)) { - const sp = " "; - rt::write(1, *(&sp: **void): *const char, 1): void; - }; - }; - const linefeed = "\n"; - rt::write(1, *(&linefeed: **void): *const char, 1): void; -}; - -// Prints strings to stderr, separated by spaces, and followed by a newline. -// -// The output is unbuffered, and may not have good performance. This is only -// recommended for debugging purposes. See [[fmt::errorln]] instead. -export fn errorln(msgs: str...) void = { - for (let i = 0z; i < len(msgs); i += 1) { - let msg = msgs[i]; - rt::write(2, *(&msg: **void): *const char, len(msg)): void; - if (i + 1 < len(msgs)) { - const sp = " "; - rt::write(2, *(&sp: **void): *const char, 1): void; - }; - }; - const linefeed = "\n"; - rt::write(2, *(&linefeed: **void): *const char, 1): void; -}; diff --git a/io/println+linux.ha b/io/println+linux.ha @@ -1,37 +0,0 @@ -// License: MPL-2.0 -// (c) 2021 Drew DeVault <sir@cmpwn.com> -use rt; - -// Prints strings to stdout, separated by spaces, and followed by a newline. -// -// The output is unbuffered, and may not have good performance. This is only -// recommended for debugging purposes. See [[fmt::println]] instead. -export fn println(msgs: str...) void = { - for (let i = 0z; i < len(msgs); i += 1) { - let msg = msgs[i]; - rt::write(1, *(&msg: **void): *const char, len(msg)): void; - if (i + 1 < len(msgs)) { - const sp = " "; - rt::write(1, *(&sp: **void): *const char, 1): void; - }; - }; - const linefeed = "\n"; - rt::write(1, *(&linefeed: **void): *const char, 1): void; -}; - -// Prints strings to stderr, separated by spaces, and followed by a newline. -// -// The output is unbuffered, and may not have good performance. This is only -// recommended for debugging purposes. See [[fmt::errorln]] instead. -export fn errorln(msgs: str...) void = { - for (let i = 0z; i < len(msgs); i += 1) { - let msg = msgs[i]; - rt::write(2, *(&msg: **void): *const char, len(msg)): void; - if (i + 1 < len(msgs)) { - const sp = " "; - rt::write(2, *(&sp: **void): *const char, 1): void; - }; - }; - const linefeed = "\n"; - rt::write(2, *(&linefeed: **void): *const char, 1): void; -}; diff --git a/mime/system.ha b/mime/system.ha @@ -1,8 +1,9 @@ // License: MPL-2.0 // (c) 2022 Drew DeVault <sir@cmpwn.com> use bufio; -use errors; use encoding::utf8; +use errors; +use fmt; use fs; use io; use os; @@ -29,7 +30,7 @@ fn load_systemdb() (void | fs::error | io::error) = { case let bytes: []u8 => yield match (strings::try_fromutf8(bytes)) { case utf8::invalid => - io::errorln("Warning: /etc/mime.types contains invalid UTF-8"); + fmt::errorln("Warning: /etc/mime.types contains invalid UTF-8")!; return; case let s: str => yield s; diff --git a/path/README b/path/README @@ -9,10 +9,10 @@ manipulation of filesystem paths. let buf = path::init(); path::add(&buf, "/", "foo", "bar", "baz.txt"); - io::println(path::string(&buf)); // "/foo/bar/baz.txt" + fmt::println(path::string(&buf))!; // "/foo/bar/baz.txt" path::add(&buf, "../.././hello.txt"); - io::println(path::string(&buf)); // "/foo/hello.txt" + fmt::println(path::string(&buf))!; // "/foo/hello.txt" The buffer object includes an array of length [[PATH_MAX]], which can be somewhat large; on Linux it's 4096 bytes. You can allocate this on the stack in diff --git a/scripts/gen-stdlib b/scripts/gen-stdlib @@ -706,7 +706,6 @@ hash_fnv() { gensrcs_io() { gen_srcs -plinux io \ 'arch+$(ARCH).ha' \ - println+linux.ha \ +linux/file.ha \ +linux/mmap.ha \ +linux/vector.ha \ @@ -723,7 +722,6 @@ gensrcs_io() { $* gen_srcs -pfreebsd io \ 'arch+$(ARCH).ha' \ - println+freebsd.ha \ +freebsd/file.ha \ +freebsd/mmap.ha \ +freebsd/vector.ha \ @@ -831,7 +829,7 @@ mime() { parse.ha \ system.ha gen_ssa mime ascii errors string hash::fnv encoding::utf8 bufio \ - errors fs io os + errors fs io os fmt } net() { diff --git a/stdlib.mk b/stdlib.mk @@ -1219,7 +1219,6 @@ $(HARECACHE)/hash/fnv/hash_fnv-any.ssa: $(stdlib_hash_fnv_any_srcs) $(stdlib_rt) # io (+linux) stdlib_io_linux_srcs= \ $(STDLIB)/io/arch+$(ARCH).ha \ - $(STDLIB)/io/println+linux.ha \ $(STDLIB)/io/+linux/file.ha \ $(STDLIB)/io/+linux/mmap.ha \ $(STDLIB)/io/+linux/vector.ha \ @@ -1237,7 +1236,6 @@ stdlib_io_linux_srcs= \ # io (+freebsd) stdlib_io_freebsd_srcs= \ $(STDLIB)/io/arch+$(ARCH).ha \ - $(STDLIB)/io/println+freebsd.ha \ $(STDLIB)/io/+freebsd/file.ha \ $(STDLIB)/io/+freebsd/mmap.ha \ $(STDLIB)/io/+freebsd/vector.ha \ @@ -3113,7 +3111,6 @@ $(TESTCACHE)/hash/fnv/hash_fnv-any.ssa: $(testlib_hash_fnv_any_srcs) $(testlib_r # io (+linux) testlib_io_linux_srcs= \ $(STDLIB)/io/arch+$(ARCH).ha \ - $(STDLIB)/io/println+linux.ha \ $(STDLIB)/io/+linux/file.ha \ $(STDLIB)/io/+linux/mmap.ha \ $(STDLIB)/io/+linux/vector.ha \ @@ -3134,7 +3131,6 @@ testlib_io_linux_srcs= \ # io (+freebsd) testlib_io_freebsd_srcs= \ $(STDLIB)/io/arch+$(ARCH).ha \ - $(STDLIB)/io/println+freebsd.ha \ $(STDLIB)/io/+freebsd/file.ha \ $(STDLIB)/io/+freebsd/mmap.ha \ $(STDLIB)/io/+freebsd/vector.ha \