hare

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

commit 793016983bd2f69b9f1d02104573d0b8faf91ed8
parent a4370b1b1648c5fb1007bf5b3ffd11309088eb3e
Author: Eyal Sawady <ecs@d2evs.net>
Date:   Wed, 10 Mar 2021 14:27:39 -0500

rt::abort_fixed: update for location printing

Diffstat:
Mrt/+linux/abort.ha | 11++++++++++-
Mrt/+test/abort.ha | 7+++++--
Mrt/+test/start.ha | 15++++++++++++---
3 files changed, 27 insertions(+), 6 deletions(-)

diff --git a/rt/+linux/abort.ha b/rt/+linux/abort.ha @@ -13,4 +13,13 @@ const reasons: [_]str = [ "out of memory", // 2 ]; -export @noreturn fn abort_fixed(i: int) void = _abort(reasons[i]); +export @noreturn fn abort_fixed(loc: str, i: int) void = { + 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); + kill(getpid(), SIGABRT); +}; diff --git a/rt/+test/abort.ha b/rt/+test/abort.ha @@ -1,5 +1,5 @@ export @noreturn @symbol("rt.abort") fn _abort(msg: str) void = { - reason = msg; + reason = abort_reason { loc = "", msg = msg }; longjmp(&jmp, 1); }; @@ -10,4 +10,7 @@ const reasons: [_]str = [ "out of memory", // 2 ]; -export @noreturn fn abort_fixed(i: int) void = _abort(reasons[i]); +export @noreturn fn abort_fixed(loc: str, i: int) void = { + reason = abort_reason { loc = loc, msg = reasons[i] }; + longjmp(&jmp, 1); +}; diff --git a/rt/+test/start.ha b/rt/+test/start.ha @@ -3,6 +3,11 @@ type test = struct { func: *fn() void, }; +type abort_reason = struct { + loc: str, + msg: str, +}; + const @symbol("__init_array_start") init_start: [*]*fn() void; const @symbol("__init_array_end") init_end: [*]*fn() void; const @symbol("__fini_array_start") fini_start: [*]*fn() void; @@ -11,7 +16,7 @@ const @symbol("__test_array_start") test_start: [*]test; const @symbol("__test_array_end") test_end: [*]test; let jmp: jmpbuf = jmpbuf { ... }; -let reason: str = ""; +let reason: abort_reason = abort_reason { ... }; export @noreturn fn start_ha() void = { const ninit = (&init_end: uintptr - &init_start: uintptr): size @@ -28,7 +33,7 @@ export @noreturn fn start_ha() void = { }; }; - let failures: [](str, str) = []; + let failures: [](str, abort_reason) = []; let npass = 0z, nfail = 0z; print("Running "); print(ztos(ntest)); @@ -66,7 +71,11 @@ export @noreturn fn start_ha() void = { for (let i = 0z; i < nfail; i += 1) { print(failures[i].0); print(": "); - print(failures[i].1); + if (len(failures[i].1.loc) != 0) { + print(failures[i].1.loc); + print(": "); + }; + print(failures[i].1.msg); print("\n"); }; };