From 464ecdd4527a303077b2d308b725d45e973352b6 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Sat, 29 Mar 2014 08:52:59 +0900 Subject: [PATCH 1/4] call symbol_rename as much as possible --- src/macro.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/macro.c b/src/macro.c index 5db52872..cc3b202c 100644 --- a/src/macro.c +++ b/src/macro.c @@ -831,7 +831,7 @@ ir_macro_wrap(pic_state *pic, pic_value expr, struct pic_senv *use_env, pic_valu { if (pic_sym_p(expr)) { pic_value ren; - ren = macroexpand(pic, expr, use_env); + ren = pic_sym_value(symbol_rename(pic, pic_sym(expr), use_env)); *assoc = pic_acons(pic, ren, expr, *assoc); return ren; } From c5d9972d2e1854be86151f7d9ecd911db649fb10 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Sat, 29 Mar 2014 08:57:15 +0900 Subject: [PATCH 2/4] macro transformer should never return macro objects --- src/macro.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/macro.c b/src/macro.c index cc3b202c..7f10d25d 100644 --- a/src/macro.c +++ b/src/macro.c @@ -848,18 +848,12 @@ ir_macro_wrap(pic_state *pic, pic_value expr, struct pic_senv *use_env, pic_valu static pic_value ir_macro_unwrap(pic_state *pic, pic_value expr, struct pic_senv *mac_env, pic_value *assoc) { - if (pic_sym_p(expr) || pic_macro_p(expr)) { + if (pic_sym_p(expr)) { pic_value r; if (pic_test(r = pic_assq(pic, expr, *assoc))) { return pic_cdr(pic, r); } - r = macroexpand(pic, expr, mac_env); - if (pic_macro_p(r)) { - return expr; - } - else { - return r; - } + return pic_sym_value(symbol_rename(pic, pic_sym(expr), mac_env)); } else if (pic_pair_p(expr)) { return pic_cons(pic, From 0b5862486497753ee5b01073f8a39fc5f4415f28 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Sat, 29 Mar 2014 09:00:37 +0900 Subject: [PATCH 3/4] no need to handle set!/if/begin syntaces at macroexpansion stage --- src/macro.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/macro.c b/src/macro.c index 7f10d25d..a0f5721c 100644 --- a/src/macro.c +++ b/src/macro.c @@ -445,10 +445,6 @@ macroexpand_node(pic_state *pic, pic_value expr, struct pic_senv *senv) return pic_cons(pic, pic_symbol_value(tag), macroexpand_list(pic, pic_cdr(pic, expr), senv)); } - else if (tag == pic->sSETBANG || tag == pic->sIF || tag == pic->sBEGIN) { - return pic_cons(pic, car, macroexpand_list(pic, pic_cdr(pic, expr), senv)); - } - else if (tag == pic->sQUOTE) { return pic_cons(pic, car, pic_cdr(pic, expr)); } From 7b73b37bec56ab74b1b6dc3a03b70701d9018329 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Sat, 29 Mar 2014 09:04:14 +0900 Subject: [PATCH 4/4] cleanup --- src/macro.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/macro.c b/src/macro.c index a0f5721c..7a5bbe83 100644 --- a/src/macro.c +++ b/src/macro.c @@ -826,10 +826,10 @@ static pic_value ir_macro_wrap(pic_state *pic, pic_value expr, struct pic_senv *use_env, pic_value *assoc) { if (pic_sym_p(expr)) { - pic_value ren; - ren = pic_sym_value(symbol_rename(pic, pic_sym(expr), use_env)); - *assoc = pic_acons(pic, ren, expr, *assoc); - return ren; + pic_value r; + r = pic_sym_value(symbol_rename(pic, pic_sym(expr), use_env)); + *assoc = pic_acons(pic, r, expr, *assoc); + return r; } else if (pic_pair_p(expr)) { return pic_cons(pic,