From 563b6367a572bc50f8fbec2aeff255c258407862 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Sat, 21 Feb 2015 06:07:57 -0800 Subject: Improved error reporting, particularly for macro expansion. * eval.c (last_form_expanded): New variable. (do_expand): New static function; contains previous expand function. (expand): Becomes a wrapper for do_expand, with re-entry counting. (eval_init): GC-protect last_form_expanded. * eval.h (last_form_expanded): Declared. * parser.l (regex_parse, lisp_parse): Just use a simple word for the name of the regex or string parse location, not the entire expression itself. * unwind.c (uw_throw): Check whether expansion was going on when the unhandled exception was thrown and print additional information. --- eval.c | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) (limited to 'eval.c') diff --git a/eval.c b/eval.c index 5721aa85..dce7e949 100644 --- a/eval.c +++ b/eval.c @@ -87,7 +87,7 @@ val opip_s, oand_s, chain_s, chand_s; val special_s, whole_k, symacro_k, fun_k; -val last_form_evaled; +val last_form_evaled, last_form_expanded; val call_f; @@ -2806,7 +2806,7 @@ static val expand_save_specials(val form, val specials) return rlcp(cons(with_saved_vars_s, cons(form, nil)), form); } -val expand(val form, val menv) +static val do_expand(val form, val menv) { val macro = nil; @@ -3023,6 +3023,28 @@ tail: } } +val expand(val form, val menv) +{ + val ret = nil; + static int reentry_count; + + uw_simple_catch_begin; + + reentry_count++; + + last_form_expanded = form; + ret = do_expand(form, menv); + + uw_unwind { + if (--reentry_count == 0) + last_form_expanded = nil; + } + + uw_catch_end; + + return ret; +} + static val macro_form_p(val form, val menv) { menv = default_bool_arg(menv); @@ -3675,7 +3697,8 @@ static val merge_wrap(val seq1, val seq2, val lessfun, val keyfun) void eval_init(void) { protect(&top_vb, &top_fb, &top_mb, &top_smb, &special, &dyn_env, - &op_table, &last_form_evaled, &call_f, convert(val *, 0)); + &op_table, &last_form_evaled, &last_form_expanded, + &call_f, convert(val *, 0)); top_fb = make_hash(t, nil, nil); top_vb = make_hash(t, nil, nil); top_mb = make_hash(t, nil, nil); -- cgit v1.2.3