From 1215202f669cbcc80da8244c5faf86463f1c176d Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Sat, 5 Apr 2014 01:23:20 +0900 Subject: [PATCH] cleanup --- src/macro.c | 75 ++++++++++++++++++++++++++--------------------------- 1 file changed, 37 insertions(+), 38 deletions(-) diff --git a/src/macro.c b/src/macro.c index b2a5275c..2ef59598 100644 --- a/src/macro.c +++ b/src/macro.c @@ -45,9 +45,6 @@ pic_find_rename(pic_state *pic, struct pic_senv *senv, pic_sym sym, pic_sym *ren return true; } -static pic_value macroexpand(pic_state *, pic_value, struct pic_senv *, pic_value); -static pic_value macroexpand_list(pic_state *, pic_value, struct pic_senv *, pic_value); - struct pic_senv * pic_null_syntactic_env(pic_state *pic) { @@ -88,6 +85,8 @@ pic_core_syntactic_env(pic_state *pic) return senv; } +static pic_value macroexpand(pic_state *, pic_value, struct pic_senv *, pic_value); + static struct pic_senv * push_scope(pic_state *pic, pic_value formals, struct pic_senv *up, pic_value assoc_box) { @@ -250,6 +249,41 @@ macroexpand(pic_state *pic, pic_value expr, struct pic_senv *senv, pic_value ass return v; } +static pic_value +macroexpand_list(pic_state *pic, pic_value list, struct pic_senv *senv, pic_value assoc_box) +{ + int ai = pic_gc_arena_preserve(pic); + pic_value v, vs; + + /* macroexpand in order */ + vs = pic_nil_value(); + while (pic_pair_p(list)) { + v = pic_car(pic, list); + + vs = pic_cons(pic, macroexpand(pic, v, senv, assoc_box), vs); + list = pic_cdr(pic, list); + + pic_gc_arena_restore(pic, ai); + pic_gc_protect(pic, vs); + pic_gc_protect(pic, list); + } + + list = macroexpand(pic, list, senv, assoc_box); + + /* reverse the result */ + pic_for_each (v, vs) { + list = pic_cons(pic, v, list); + + pic_gc_arena_restore(pic, ai); + pic_gc_protect(pic, vs); + pic_gc_protect(pic, list); + } + + pic_gc_arena_restore(pic, ai); + pic_gc_protect(pic, list); + return list; +} + static pic_sym macroexpand_symbol(pic_state *pic, pic_sym sym, struct pic_senv *senv, pic_value assoc_box) { @@ -613,41 +647,6 @@ macroexpand_node(pic_state *pic, pic_value expr, struct pic_senv *senv, pic_valu UNREACHABLE(); } -static pic_value -macroexpand_list(pic_state *pic, pic_value list, struct pic_senv *senv, pic_value assoc_box) -{ - int ai = pic_gc_arena_preserve(pic); - pic_value v, vs; - - /* macroexpand in order */ - vs = pic_nil_value(); - while (pic_pair_p(list)) { - v = pic_car(pic, list); - - vs = pic_cons(pic, macroexpand(pic, v, senv, assoc_box), vs); - list = pic_cdr(pic, list); - - pic_gc_arena_restore(pic, ai); - pic_gc_protect(pic, vs); - pic_gc_protect(pic, list); - } - - list = macroexpand(pic, list, senv, assoc_box); - - /* reverse the result */ - pic_for_each (v, vs) { - list = pic_cons(pic, v, list); - - pic_gc_arena_restore(pic, ai); - pic_gc_protect(pic, vs); - pic_gc_protect(pic, list); - } - - pic_gc_arena_restore(pic, ai); - pic_gc_protect(pic, list); - return list; -} - pic_value pic_macroexpand(pic_state *pic, pic_value expr) {