hare

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

commit 78a8255df679a44a899b8ec7e86a12b1ce70a378
parent 7ce2904d1ff1f84462dd4622f8f3fc8d1d28ae03
Author: Bor Grošelj Simić <bgs@turminal.net>
Date:   Sun, 14 May 2023 23:14:04 +0200

rt: update abort for non-constant assert changes in harec

References: https://todo.sr.ht/~sircmpwn/hare/109
Signed-off-by: Bor Grošelj Simić <bgs@turminal.net>

Diffstat:
Mrt/+freebsd/platform_abort.ha | 5++++-
Mrt/+linux/platform_abort.ha | 5++++-
Mrt/abort+test.ha | 10++++++----
Mrt/abort.ha | 6++++--
4 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/rt/+freebsd/platform_abort.ha b/rt/+freebsd/platform_abort.ha @@ -1,10 +1,13 @@ // License: MPL-2.0 // (c) 2021 Drew DeVault <sir@cmpwn.com> -fn platform_abort(msg: str) void = { +fn platform_abort(loc: str, msg: str) void = { const prefix = "Abort: "; + const sep = ": "; const linefeed = "\n"; write(STDERR_FILENO, *(&prefix: **void): *const u8, len(prefix)): void; + write(STDERR_FILENO, *(&loc: **void): *const u8, len(prefix)): void; + write(STDERR_FILENO, *(&sep: **void): *const u8, len(prefix)): void; write(STDERR_FILENO, *(&msg: **void): *const u8, len(msg)): void; write(STDERR_FILENO, *(&linefeed: **void): *const u8, 1): void; kill(getpid(), SIGABRT): void; diff --git a/rt/+linux/platform_abort.ha b/rt/+linux/platform_abort.ha @@ -1,10 +1,13 @@ // License: MPL-2.0 // (c) 2021 Drew DeVault <sir@cmpwn.com> -fn platform_abort(msg: str) void = { +fn platform_abort(loc: str, msg: str) void = { const prefix = "Abort: "; + const sep = ": "; const linefeed = "\n"; write(STDERR_FILENO, *(&prefix: **void): *const u8, len(prefix)): void; + write(STDERR_FILENO, *(&loc: **void): *const u8, len(prefix)): void; + write(STDERR_FILENO, *(&sep: **void): *const u8, len(prefix)): void; write(STDERR_FILENO, *(&msg: **void): *const u8, len(msg)): void; write(STDERR_FILENO, *(&linefeed: **void): *const u8, 1): void; kill(getpid(), SIGABRT): void; diff --git a/rt/abort+test.ha b/rt/abort+test.ha @@ -10,13 +10,13 @@ export type abort_reason = struct { export let jmp: nullable *jmpbuf = null; export let reason: abort_reason = abort_reason { ... }; -export @noreturn @symbol("rt.abort") fn _abort(msg: str) void = { +export @noreturn @symbol("rt.abort") fn _abort(loc: str, msg: str) void = { match (jmp) { case let j: *jmpbuf => - reason = abort_reason { loc = "", msg = msg }; + reason = abort_reason { loc = loc, msg = msg }; longjmp(j, 1); case null => - platform_abort(msg); + platform_abort(loc, msg); }; }; @@ -28,6 +28,8 @@ const reasons: [_]str = [ "static insert/append exceeds slice capacity", // 3 "execution reached unreachable code (compiler bug)", // 4 "slice allocation capacity smaller than initializer" // 5 + "assertion failed", // 6 + "error occured", // 7 ]; export @noreturn fn abort_fixed(loc: str, i: int) void = { @@ -36,6 +38,6 @@ export @noreturn fn abort_fixed(loc: str, i: int) void = { reason = abort_reason { loc = loc, msg = reasons[i] }; longjmp(j, 1); case null => - platform_abort(reasons[i]); + platform_abort(loc, reasons[i]); }; }; diff --git a/rt/abort.ha b/rt/abort.ha @@ -1,8 +1,8 @@ // License: MPL-2.0 // (c) 2021 Drew DeVault <sir@cmpwn.com> -export @noreturn @symbol("rt.abort") fn _abort(msg: str) void = { - platform_abort(msg); +export @noreturn @symbol("rt.abort") fn _abort(loc: str, msg: str) void = { + platform_abort(loc, msg); }; // See harec:include/gen.h @@ -13,6 +13,8 @@ const reasons: [_]str = [ "static insert/append exceeds slice capacity", // 3 "execution reached unreachable code (compiler bug)", // 4 "slice allocation capacity smaller than initializer" // 5 + "assertion failed", // 6 + "error occured", // 7 ]; export @noreturn fn abort_fixed(loc: str, i: int) void = {