hare

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

commit 90c71c79c94ecd8cab21e7483349b4b16f169fd3
parent a12a210394b64a1b2f3e4d1c33aee121cc55829d
Author: Drew DeVault <sir@cmpwn.com>
Date:   Thu,  1 Apr 2021 13:11:46 -0400

Remove str => *const char cast and nul terminator

Diffstat:
Mio/println.ha | 16++++++++++------
Mrt/+linux/abort.ha | 7++++---
Mrt/+test/run.ha | 2+-
Mrt/abort.ha | 12+++++++-----
Mstrings/concat.ha | 4+---
5 files changed, 23 insertions(+), 18 deletions(-)

diff --git a/io/println.ha b/io/println.ha @@ -7,12 +7,14 @@ use rt; export fn println(msgs: str...) void = { for (let i = 0z; i < len(msgs); i += 1) { let msg = msgs[i]; - rt::write(1, msg: *const char, len(msg)); + rt::write(1, *(&msg: **void): *const char, len(msg)); if (i + 1 < len(msgs)) { - rt::write(1, " ": *const char, 1); + const sp = " "; + rt::write(1, *(&sp: **void): *const char, 1); }; }; - rt::write(1, "\n": *const char, 1); + const linefeed = "\n"; + rt::write(2, *(&linefeed: **void): *const char, 1); }; // Prints strings to stderr, separated by spaces, and followed by a newline. @@ -22,10 +24,12 @@ export fn println(msgs: str...) void = { export fn errorln(msgs: str...) void = { for (let i = 0z; i < len(msgs); i += 1) { let msg = msgs[i]; - rt::write(2, msg: *const char, len(msg)); + rt::write(2, *(&msg: **void): *const char, len(msg)); if (i + 1 < len(msgs)) { - rt::write(2, " ": *const char, 1); + const sp = " "; + rt::write(2, *(&sp: **void): *const char, 1); }; }; - rt::write(2, "\n": *const char, 1); + const linefeed = "\n"; + rt::write(2, *(&linefeed: **void): *const char, 1); }; diff --git a/rt/+linux/abort.ha b/rt/+linux/abort.ha @@ -1,7 +1,8 @@ fn platform_abort(msg: str) void = { const prefix = "Abort: "; - write(2, prefix: *const char, len(prefix)); - write(2, msg: *const char, len(msg)); - write(2, "\n": *const char, 1); + const linefeed = "\n"; + write(2, *(&prefix: **void): *const char, len(prefix)); + write(2, *(&msg: **void): *const char, len(msg)); + write(2, *(&linefeed: **void): *const char, 1); kill(getpid(), SIGABRT); }; diff --git a/rt/+test/run.ha b/rt/+test/run.ha @@ -85,7 +85,7 @@ export fn tests_main() size = { return nfail; }; -fn print(msg: str) void = write(1, msg: *const char, len(msg)); +fn print(msg: str) void = write(1, *(&msg: **void): *const char, len(msg)); fn dots(n: size) void = { // XXX: this is slow, I guess diff --git a/rt/abort.ha b/rt/abort.ha @@ -10,12 +10,14 @@ const reasons: [_]str = [ ]; export @noreturn fn abort_fixed(loc: str, i: int) void = { + // TODO: This is also platform-specific const prefix = "Abort: "; const sep = ": "; - write(2, prefix: *const char, len(prefix)); - write(2, loc: *const char, len(loc)); - write(2, sep: *const char, len(sep)); - write(2, reasons[i]: *const char, len(reasons[i])); - write(2, "\n": *const char, 1); + const linefeed = "\n"; + write(2, *(&prefix: **void): *const char, len(prefix)); + write(2, *(&loc: **void): *const char, len(loc)); + write(2, *(&sep: **void): *const char, len(sep)); + write(2, *(&reasons[i]: **void): *const char, len(reasons[i])); + write(2, *(&linefeed: **void): *const char, 1); kill(getpid(), SIGABRT); }; diff --git a/strings/concat.ha b/strings/concat.ha @@ -4,18 +4,16 @@ export fn concat(strs: str...) str = { for (let i = 0z; i < len(strs); i += 1) { z += len(strs[i]); }; - let new: []u8 = alloc([], z + 1); + let new: []u8 = alloc([], z); for (let i = 0z; i < len(strs); i += 1) { append(new, ...toutf8(strs[i])); }; - append(new, 0); return fromutf8_unsafe(new[..z]); }; @test fn concat() void = { let s = concat("hello ", "world"); assert(s == "hello world"); - assert((s: *const char: *[*]u8)[len(s)] == 0); free(s); s = concat("hello", " ", "world");