commit 92afe81232ffca34df036cc8d0712b3bad8fecee
parent 07759c39a999a00756834fc00a3f5f2360ebe5b5
Author: Ember Sawady <ecs@d2evs.net>
Date: Wed, 6 Sep 2023 08:11:38 +0000
update for abort abi change
Signed-off-by: Ember Sawady <ecs@d2evs.net>
Diffstat:
5 files changed, 59 insertions(+), 23 deletions(-)
diff --git a/rt/+freebsd/platform_abort.ha b/rt/+freebsd/platform_abort.ha
@@ -1,13 +1,21 @@
// License: MPL-2.0
// (c) 2021 Drew DeVault <sir@cmpwn.com>
-fn platform_abort(loc: str, msg: str) void = {
+fn platform_abort(path: *str, line: u64, col: u64, msg: str) void = {
const prefix = "Abort: ";
- const sep = ": ";
+ const sep = ":";
+ const sepspace = ": ";
const linefeed = "\n";
write(STDERR_FILENO, *(&prefix: **opaque): *const u8, len(prefix)): void;
- write(STDERR_FILENO, *(&loc: **opaque): *const u8, len(loc)): void;
+ write(STDERR_FILENO, *(path: **opaque): *const u8, len(path)): void;
write(STDERR_FILENO, *(&sep: **opaque): *const u8, len(sep)): void;
+ let (line, z) = u64tos(line);
+ write(STDERR_FILENO, line, z): void;
+ write(STDERR_FILENO, *(&sep: **opaque): *const u8, len(sep)): void;
+ let (col, z) = u64tos(col);
+ write(STDERR_FILENO, col, z): void;
+ write(STDERR_FILENO, *(&sepspace: **opaque): *const u8,
+ len(sepspace)): void;
write(STDERR_FILENO, *(&msg: **opaque): *const u8, len(msg)): void;
write(STDERR_FILENO, *(&linefeed: **opaque): *const u8, 1): void;
kill(getpid(), SIGABRT): void;
diff --git a/rt/+linux/platform_abort.ha b/rt/+linux/platform_abort.ha
@@ -1,13 +1,21 @@
// License: MPL-2.0
// (c) 2021 Drew DeVault <sir@cmpwn.com>
-fn platform_abort(loc: str, msg: str) void = {
+fn platform_abort(path: *str, line: u64, col: u64, msg: str) void = {
const prefix = "Abort: ";
- const sep = ": ";
+ const sep = ":";
+ const sepspace = ": ";
const linefeed = "\n";
write(STDERR_FILENO, *(&prefix: **opaque): *const u8, len(prefix)): void;
- write(STDERR_FILENO, *(&loc: **opaque): *const u8, len(loc)): void;
+ write(STDERR_FILENO, *(path: **opaque): *const u8, len(path)): void;
write(STDERR_FILENO, *(&sep: **opaque): *const u8, len(sep)): void;
+ let (line, z) = u64tos(line);
+ write(STDERR_FILENO, line, z): void;
+ write(STDERR_FILENO, *(&sep: **opaque): *const u8, len(sep)): void;
+ let (col, z) = u64tos(col);
+ write(STDERR_FILENO, col, z): void;
+ write(STDERR_FILENO, *(&sepspace: **opaque): *const u8,
+ len(sepspace)): void;
write(STDERR_FILENO, *(&msg: **opaque): *const u8, len(msg)): void;
write(STDERR_FILENO, *(&linefeed: **opaque): *const u8, 1): void;
kill(getpid(), SIGABRT): void;
diff --git a/rt/abort+test.ha b/rt/abort+test.ha
@@ -3,20 +3,32 @@
// (c) 2021 Ember Sawady <ecs@d2evs.net>
export type abort_reason = struct {
- loc: str,
+ path: nullable *str,
+ line: u64,
+ col: u64,
msg: str,
};
export let jmp: nullable *jmpbuf = null;
export let reason: abort_reason = abort_reason { ... };
-export @symbol("rt.abort") fn _abort(loc: str, msg: str) void = {
+export @symbol("rt.abort") fn _abort(
+ path: *str,
+ line: u64,
+ col: u64,
+ msg: str,
+) void = {
match (jmp) {
case let j: *jmpbuf =>
- reason = abort_reason { loc = loc, msg = msg };
+ reason = abort_reason {
+ path = path,
+ line = line,
+ col = col,
+ msg = msg,
+ };
longjmp(j, 1);
case null =>
- platform_abort(loc, msg);
+ platform_abort(path, line, col, msg);
};
};
@@ -32,6 +44,6 @@ const reasons: [_]str = [
"error occurred", // 7
];
-export fn abort_fixed(loc: str, i: int) void = {
- _abort(loc, reasons[i]);
+export fn abort_fixed(path: *str, line: u64, col: u64, i: u64) void = {
+ _abort(path, line, col, reasons[i]);
};
diff --git a/rt/abort.ha b/rt/abort.ha
@@ -1,8 +1,13 @@
// License: MPL-2.0
// (c) 2021 Drew DeVault <sir@cmpwn.com>
-export @symbol("rt.abort") fn _abort(loc: str, msg: str) void = {
- platform_abort(loc, msg);
+export @symbol("rt.abort") fn _abort(
+ path: *str,
+ line: u64,
+ col: u64,
+ msg: str,
+) void = {
+ platform_abort(path, line, col, msg);
};
// See harec:include/gen.h
@@ -17,6 +22,6 @@ const reasons: [_]str = [
"error occurred", // 7
];
-export fn abort_fixed(loc: str, i: int) void = {
- platform_abort(loc, reasons[i]);
+export fn abort_fixed(path: *str, line: u64, col: u64, i: u64) void = {
+ platform_abort(path, line, col, reasons[i]);
};
diff --git a/test/+test.ha b/test/+test.ha
@@ -102,14 +102,17 @@ export @symbol("__test_main") fn main() size = {
if (len(ctx.failures) > 0) {
fmt::println("Failures:")!;
for (let i = 0z; i < len(ctx.failures); i += 1) {
- if (ctx.failures[i].reason.loc != "") {
- fmt::printfln("{}: {}: {}",
+ match (ctx.failures[i].reason.path) {
+ case null =>
+ fmt::printfln("{}: {}",
ctx.failures[i].test,
- ctx.failures[i].reason.loc,
ctx.failures[i].reason.msg)!;
- } else {
- fmt::printfln("{}: {}",
+ case let path: *str =>
+ fmt::printfln("{}: {}:{}:{}: {}",
ctx.failures[i].test,
+ *path,
+ ctx.failures[i].reason.line,
+ ctx.failures[i].reason.col,
ctx.failures[i].reason.msg)!;
};
};
@@ -255,8 +258,8 @@ fn fail(test: test, n: int) failure = {
return failure {
test = test.name,
reason = rt::abort_reason {
- loc = "",
msg = "Segmentation fault",
+ ...
},
};
case =>
@@ -264,8 +267,8 @@ fn fail(test: test, n: int) failure = {
return failure {
test = test.name,
reason = rt::abort_reason {
- loc = "",
msg = "Reason unknown",
+ ...
},
};
};