hare

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

commit 1c380b16964b571a708ab8be43aa211a8eda35f1
parent 4db28160f3273a1f84d64337571590c5206e6483
Author: Drew DeVault <sir@cmpwn.com>
Date:   Tue,  2 Jan 2024 12:36:32 +0100

rt: add abort hooks

So that other modules or third-parties can handle aborts themselves.

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

Diffstat:
Mrt/+freebsd/platform_abort.ha | 2+-
Mrt/+linux/platform_abort.ha | 2+-
Mrt/+openbsd/platform_abort.ha | 2+-
Mrt/abort+test.ha | 13+++++++++++++
Mrt/abort.ha | 21++++++++++++++++++---
5 files changed, 34 insertions(+), 6 deletions(-)

diff --git a/rt/+freebsd/platform_abort.ha b/rt/+freebsd/platform_abort.ha @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MPL-2.0 // (c) Hare authors <https://harelang.org> -fn platform_abort(path: *str, line: u64, col: u64, msg: str) void = { +fn platform_abort(path: *str, line: u64, col: u64, msg: str) never = { const prefix = "Abort: "; const sep = ":"; const sepspace = ": "; diff --git a/rt/+linux/platform_abort.ha b/rt/+linux/platform_abort.ha @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MPL-2.0 // (c) Hare authors <https://harelang.org> -fn platform_abort(path: *str, line: u64, col: u64, msg: str) void = { +fn platform_abort(path: *str, line: u64, col: u64, msg: str) never = { const prefix = "Abort: "; const sep = ":"; const sepspace = ": "; diff --git a/rt/+openbsd/platform_abort.ha b/rt/+openbsd/platform_abort.ha @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MPL-2.0 // (c) Hare authors <https://harelang.org> -fn platform_abort(path: *str, line: u64, col: u64, msg: str) void = { +fn platform_abort(path: *str, line: u64, col: u64, msg: str) never = { const prefix = "Abort: "; const sep = ":"; const sepspace = ": "; diff --git a/rt/abort+test.ha b/rt/abort+test.ha @@ -1,6 +1,19 @@ // SPDX-License-Identifier: MPL-2.0 // (c) Hare authors <https://harelang.org> +// Signature for abort handler function. +export type abort_handler = fn( + path: *str, + line: u64, + col: u64, + msg: str, +) never; + +// Sets a new global runtime abort handler. +export fn onabort(handler: *abort_handler) void = { + return; // no-op on +test (XXX: Do something here?) +}; + export type abort_reason = struct { path: nullable *str, line: u64, diff --git a/rt/abort.ha b/rt/abort.ha @@ -1,13 +1,28 @@ // SPDX-License-Identifier: MPL-2.0 // (c) Hare authors <https://harelang.org> +// Signature for abort handler function. +export type abort_handler = fn( + path: *str, + line: u64, + col: u64, + msg: str, +) never; + +let handle_abort: *abort_handler = &platform_abort; + +// Sets a new global runtime abort handler. +export fn onabort(handler: *abort_handler) void = { + handle_abort = handler; +}; + export @symbol("rt.abort") fn _abort( path: *str, line: u64, col: u64, msg: str, -) void = { - platform_abort(path, line, col, msg); +) never = { + handle_abort(path, line, col, msg); }; // See harec:include/gen.h @@ -23,5 +38,5 @@ const reasons: [_]str = [ ]; export fn abort_fixed(path: *str, line: u64, col: u64, i: u64) void = { - platform_abort(path, line, col, reasons[i]); + handle_abort(path, line, col, reasons[i]); };