summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2016-05-07 18:19:31 -0700
committerKaz Kylheku <kaz@kylheku.com>2016-05-07 18:19:31 -0700
commit7a3280106d04624a00bddb5abdf74485b9d0dee7 (patch)
tree46769937aa27c60cbfa1164c709ee06406e00978
parent8f1e467559024433853e6ec0a862752c9a546104 (diff)
downloadtxr-7a3280106d04624a00bddb5abdf74485b9d0dee7.tar.gz
txr-7a3280106d04624a00bddb5abdf74485b9d0dee7.tar.bz2
txr-7a3280106d04624a00bddb5abdf74485b9d0dee7.zip
Adding panic macro, which throws a panic exception.
* lib.c (panic_s): New symbol variable. (obj_init): Initialize panic_s. * lib.h (panic_s): Declared. * unwind.c (uw_init): Register panic exception. * unwind.h (panic): New macro.
-rw-r--r--lib.c3
-rw-r--r--lib.h2
-rw-r--r--unwind.c1
-rw-r--r--unwind.h10
4 files changed, 14 insertions, 2 deletions
diff --git a/lib.c b/lib.c
index 1d41ea6b..51a862b5 100644
--- a/lib.c
+++ b/lib.c
@@ -96,7 +96,7 @@ val repeat_s, rep_s, flatten_s, forget_s;
val local_s, merge_s, bind_s, rebind_s, cat_s;
val try_s, catch_s, finally_s, throw_s, defex_s, deffilter_s;
val eof_s, eol_s, assert_s, name_s;
-val error_s, type_error_s, internal_error_s;
+val error_s, type_error_s, internal_error_s, panic_s;
val numeric_error_s, range_error_s;
val query_error_s, file_error_s, process_error_s, syntax_error_s;
val timeout_error_s, system_error_s;
@@ -8613,6 +8613,7 @@ static void obj_init(void)
error_s = intern(lit("error"), user_package);
type_error_s = intern(lit("type-error"), user_package);
internal_error_s = intern(lit("internal-error"), user_package);
+ panic_s = intern(lit("panic"), user_package);
numeric_error_s = intern(lit("numeric-error"), user_package);
range_error_s = intern(lit("range-error"), user_package);
query_error_s = intern(lit("query-error"), user_package);
diff --git a/lib.h b/lib.h
index e84e5eac..3dc75d61 100644
--- a/lib.h
+++ b/lib.h
@@ -426,7 +426,7 @@ extern val repeat_s, rep_s, flatten_s, forget_s;
extern val local_s, merge_s, bind_s, rebind_s, cat_s;
extern val try_s, catch_s, finally_s, throw_s, defex_s, deffilter_s;
extern val eof_s, eol_s, assert_s, name_s;
-extern val error_s, type_error_s, internal_error_s;
+extern val error_s, type_error_s, internal_error_s, panic_s;
extern val numeric_error_s, range_error_s;
extern val query_error_s, file_error_s, process_error_s, syntax_error_s;
extern val system_error_s, timeout_error_s;
diff --git a/unwind.c b/unwind.c
index 7495be1e..9e0de39e 100644
--- a/unwind.c
+++ b/unwind.c
@@ -903,6 +903,7 @@ void uw_init(void)
exception_subtypes = cons(cons(t, nil), exception_subtypes);
uw_register_subtype(type_error_s, error_s);
uw_register_subtype(internal_error_s, error_s);
+ uw_register_subtype(panic_s, error_s);
uw_register_subtype(numeric_error_s, error_s);
uw_register_subtype(range_error_s, error_s);
uw_register_subtype(query_error_s, error_s);
diff --git a/unwind.h b/unwind.h
index fb353b15..615433e3 100644
--- a/unwind.h
+++ b/unwind.h
@@ -235,6 +235,16 @@ noreturn val type_mismatch(val, ...);
nao); \
} while (0)
+#define panic(STR) \
+ do { \
+ extern obj_t *num(cnum); \
+ uw_throwf(panic_s, \
+ lit("~a:~a ~a"), \
+ lit(__FILE__), \
+ num(__LINE__), lit(STR), \
+ nao); \
+ } while (0)
+
#define type_assert(EXPR, ARGS) \
if (!(EXPR)) type_mismatch ARGS