summaryrefslogtreecommitdiffstats
path: root/eval.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2015-02-21 06:07:57 -0800
committerKaz Kylheku <kaz@kylheku.com>2015-02-21 06:07:57 -0800
commit563b6367a572bc50f8fbec2aeff255c258407862 (patch)
treedc907e344c6e3526f1215a1cd5ab2b018b32d74d /eval.c
parent3f93ddf1acc8b6d3647dec31e7329987d452daa5 (diff)
downloadtxr-563b6367a572bc50f8fbec2aeff255c258407862.tar.gz
txr-563b6367a572bc50f8fbec2aeff255c258407862.tar.bz2
txr-563b6367a572bc50f8fbec2aeff255c258407862.zip
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.
Diffstat (limited to 'eval.c')
-rw-r--r--eval.c29
1 files changed, 26 insertions, 3 deletions
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);