abort.ha (800B)
1 export @noreturn @symbol("rt.abort") fn _abort(msg: str) void = { 2 const prefix = "Abort: "; 3 write(2, constchar(prefix), len(prefix)); 4 write(2, constchar(msg), len(msg)); 5 write(2, constchar("\n"), 1); 6 kill(getpid(), SIGABRT); 7 }; 8 9 // See harec:include/gen.h 10 const reasons: [_]str = [ 11 "slice or array access out of bounds", // 0 12 "type assertion failed", // 1 13 "out of memory", // 2 14 "static append exceeds slice capacity", // 3 15 "unreachable code", // 4 16 ]; 17 18 export @noreturn fn abort_fixed(loc: str, i: int) void = { 19 const prefix = "Abort: "; 20 const sep = ": "; 21 write(2, constchar(prefix), len(prefix)); 22 write(2, constchar(loc), len(loc)); 23 write(2, constchar(sep), len(sep)); 24 write(2, constchar(reasons[i]), len(reasons[i])); 25 write(2, constchar("\n"), 1); 26 kill(getpid(), SIGABRT); 27 };