hare

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

abort.ha (1041B)


      1 // SPDX-License-Identifier: MPL-2.0
      2 // (c) Hare authors <https://harelang.org>
      3 
      4 // Signature for abort handler function.
      5 export type abort_handler = fn(
      6 	path: *str,
      7 	line: u64,
      8 	col: u64,
      9 	msg: str,
     10 ) never;
     11 
     12 let handle_abort: *abort_handler = &platform_abort;
     13 
     14 // Sets a new global runtime abort handler.
     15 export fn onabort(handler: *abort_handler) void = {
     16 	handle_abort = handler;
     17 };
     18 
     19 export @symbol("rt.abort") fn _abort(
     20 	path: *str,
     21 	line: u64,
     22 	col: u64,
     23 	msg: str,
     24 ) never = {
     25 	handle_abort(path, line, col, msg);
     26 };
     27 
     28 // See harec:include/gen.h
     29 const reasons: [_]str = [
     30 	"slice or array access out of bounds",			// 0
     31 	"type assertion failed",				// 1
     32 	"out of memory",					// 2
     33 	"static insert/append exceeds slice capacity",		// 3
     34 	"execution reached unreachable code (compiler bug)",	// 4
     35 	"slice allocation capacity smaller than initializer",	// 5
     36 	"assertion failed",					// 6
     37 	"error occurred",					// 7
     38 ];
     39 
     40 export fn abort_fixed(path: *str, line: u64, col: u64, i: u64) void = {
     41 	handle_abort(path, line, col, reasons[i]);
     42 };