summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--eval.c43
1 files changed, 35 insertions, 8 deletions
diff --git a/eval.c b/eval.c
index 24e4dd92..4c44d10b 100644
--- a/eval.c
+++ b/eval.c
@@ -5693,6 +5693,7 @@ val macro_form_p(val form, val menv)
static val do_macroexpand_1(val form, val menv, val (*lookup)(val, val))
{
val macro;
+ val eh = expand_hook;
#if CONFIG_DEBUG_SUPPORT
uw_frame_t expand_fr;
uw_push_expand(&expand_fr, form, menv);
@@ -5700,14 +5701,40 @@ static val do_macroexpand_1(val form, val menv, val (*lookup)(val, val))
menv = default_null_arg(menv);
- if (consp(form) && (macro = lookup_mac(menv, car(form)))) {
- val mac_expand = expand_macro(form, macro, menv);
- if (mac_expand != form)
- form = rlcp_tree(rlcp_tree(mac_expand, form), macro);
- } else if (bindable(form) && (macro = lookup(menv, form))) {
- val mac_expand = cdr(macro);
- if (mac_expand != form)
- form = rlcp_tree(mac_expand, macro);
+ for (;;) {
+ if (consp(form) && (macro = lookup_mac(menv, car(form)))) {
+ if (eh) {
+ val eh_form = funcall3(eh, form, menv, macro_k);
+ if (eh_form != form) {
+ form = rlcp_tree(eh_form, form);
+ continue;
+ }
+ }
+ {
+ val mac_expand = expand_macro(form, macro, menv);
+ if (mac_expand != form)
+ form = rlcp_tree(rlcp_tree(mac_expand, form), macro);
+ }
+ break;
+ } else if (bindable(form) && (macro = lookup(menv, form))) {
+ val mac_expand = cdr(macro);
+ if (mac_expand != form)
+ form = rlcp_tree(mac_expand, macro);
+ break;
+ } else if (eh && consp(form)) {
+ val op = car(form);
+ if (op == dwim_s || !special_operator_p(op)) {
+ val eh_type = if3(lookup_fun(menv, op),
+ fun_k,
+ if2(op == dwim_s, dwim_s));
+ val eh_form = funcall3(eh, form, menv, eh_type);
+ if (eh_form != form) {
+ form = rlcp_tree(eh_form, form);
+ continue;
+ }
+ }
+ }
+ break;
}
#if CONFIG_DEBUG_SUPPORT