From 9cef0547ba0ec81ce6051bb1cba9db5671e08e64 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Wed, 14 Oct 2015 06:49:33 -0700 Subject: New way of handling exceptions without unwinding. * eval.c (handler_bind_s): New symbol variable. (op_handler_bind): New static function. (do_expand): Traverse handler-bind forms. (eval_init): Initialize handler_bind_s variable and register handler-bind operator. * lisplib.c (except_set_entries, except_instantiate): New functions. (lisplib_init): Register new functions in dl_table. * parser.c (intr_s): New symbol variable. (repl_intr): Throw exception of type intr, rather than error. This way we can interrupt accidental exception handling loops involving exceptions derived from error. (parse_init): Initialize intr_s. * share/txr/stdlib/except.tl: New file, defines handle macro. * unwind.c (uw_push_handler): New function. (invoke_handler): New static function. (uw_throw): Search loop looks for and processes handlers in addition to catches. * unwind.h (uw_frtype_t): New enum member, UW_HANDLE. (struct uw_catch): Move member visible so it is in the same position as in struct uw_handler. (struct uw_handler): New struct type. (union uw_frame): New member ha of type struct uw_handler. (uw_push_handler): Function declared. * txr.1: Added introductory paragraphs to Exception Handling section. Documented handler-bind and handle. Some minor errors corrected. --- parser.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'parser.c') diff --git a/parser.c b/parser.c index ccff6a3f..9cdb0a85 100644 --- a/parser.c +++ b/parser.c @@ -57,6 +57,7 @@ val parser_s, unique_s; val listener_hist_len_s, listener_multi_line_p_s; +val intr_s; static val stream_parser_hash; @@ -587,7 +588,7 @@ static char *provide_atom(lino_t *l, const char *str, int n, void *ctx) static val repl_intr(val signo, val async_p) { - uw_throw(error_s, lit("intr")); + uw_throw(intr_s, lit("intr")); } static val read_eval_ret_last(val env, val in_stream, val out_stream) @@ -793,6 +794,7 @@ val parser_eof(val parser) void parse_init(void) { parser_s = intern(lit("parser"), user_package); + intr_s = intern(lit("intr"), user_package); listener_hist_len_s = intern(lit("*listener-hist-len*"), user_package); listener_multi_line_p_s = intern(lit("*listener-multi-line-p*"), user_package); unique_s = gensym(nil); -- cgit v1.2.3