From ec9797df2a589d0a8cd36beb632956a1ec1f6bfc Mon Sep 17 00:00:00 2001 From: Zuhaitz Méndez Fernández de Aránguiz Date: Tue, 13 Jan 2026 01:01:40 +0000 Subject: More general solution #15 --- std/core.zc | 11 ++++++++++- std/string.zc | 3 +-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/std/core.zc b/std/core.zc index bfa82ea..910bfa6 100644 --- a/std/core.zc +++ b/std/core.zc @@ -5,4 +5,13 @@ include include include -var __zen_hash_seed: usize = 14695981039346656037; \ No newline at end of file +var __zen_hash_seed: usize = 14695981039346656037; + +raw { +void _zen_panic(const char* file, int line, const char* func, const char* msg) { + fprintf(stderr, "%s:%d (%s): Panic: %s\n", file, line, func, msg); + exit(1); +} +} + +#define panic(msg) _zen_panic(__FILE__, __LINE__, __func__, msg) \ No newline at end of file diff --git a/std/string.zc b/std/string.zc index e45d399..4e0ba03 100644 --- a/std/string.zc +++ b/std/string.zc @@ -58,8 +58,7 @@ impl String { fn substring(self, start: usize, len: usize) -> String { if (start + len > self.length()) { - fprintf(stderr, "%s:%d (%s): Panic: substring out of bounds\n", __FILE__, __LINE__, __func__); - exit(1); + panic("substring out of bounds"); } var v = Vec::new(); // Manual copy -- cgit v1.2.3