From 30cbdd5c4f5b853409ae925a20a72f373617a3f1 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Tue, 9 Jun 2015 20:20:56 +0900 Subject: [PATCH] cleanup macro.h --- extlib/benz/include/picrin/macro.h | 4 ---- extlib/benz/lib.c | 16 +++++++++++++++- extlib/benz/macro.c | 26 -------------------------- extlib/benz/state.c | 2 ++ extlib/benz/vm.c | 10 ++++++++++ 5 files changed, 27 insertions(+), 31 deletions(-) diff --git a/extlib/benz/include/picrin/macro.h b/extlib/benz/include/picrin/macro.h index 076c8c15..c0f6fef3 100644 --- a/extlib/benz/include/picrin/macro.h +++ b/extlib/benz/include/picrin/macro.h @@ -19,8 +19,6 @@ struct pic_env { #define pic_env_p(v) (pic_type(v) == PIC_TT_ENV) #define pic_env_ptr(v) ((struct pic_env *)pic_ptr(v)) -struct pic_env *pic_null_syntactic_environment(pic_state *); - bool pic_identifier_p(pic_state *pic, pic_value obj); bool pic_identifier_eq_p(pic_state *, struct pic_env *, pic_sym *, struct pic_env *, pic_sym *); @@ -30,8 +28,6 @@ pic_sym *pic_add_rename(pic_state *, struct pic_env *, pic_sym *); bool pic_find_rename(pic_state *, struct pic_env *, pic_sym *, pic_sym ** /* = NULL */); void pic_put_rename(pic_state *, struct pic_env *, pic_sym *, pic_sym *); -void pic_define_syntactic_keyword(pic_state *, struct pic_env *, pic_sym *, pic_sym *); - #if defined(__cplusplus) } #endif diff --git a/extlib/benz/lib.c b/extlib/benz/lib.c index 6ece6a1f..e39e0f48 100644 --- a/extlib/benz/lib.c +++ b/extlib/benz/lib.c @@ -4,6 +4,18 @@ #include "picrin.h" +static void +setup_default_env(pic_state *pic, struct pic_env *env) +{ + void pic_define_syntactic_keyword(pic_state *, struct pic_env *, pic_sym *, pic_sym *); + + pic_define_syntactic_keyword(pic, env, pic->sDEFINE_LIBRARY, pic->rDEFINE_LIBRARY); + pic_define_syntactic_keyword(pic, env, pic->sIMPORT, pic->rIMPORT); + pic_define_syntactic_keyword(pic, env, pic->sEXPORT, pic->rEXPORT); + pic_define_syntactic_keyword(pic, env, pic->sIN_LIBRARY, pic->rIN_LIBRARY); + pic_define_syntactic_keyword(pic, env, pic->sCOND_EXPAND, pic->rCOND_EXPAND); +} + struct pic_lib * pic_make_library(pic_state *pic, pic_value name) { @@ -15,9 +27,11 @@ pic_make_library(pic_state *pic, pic_value name) pic_errorf(pic, "library name already in use: ~s", name); } - env = pic_null_syntactic_environment(pic); + env = pic_make_env(pic, NULL); exports = pic_make_dict(pic); + setup_default_env(pic, env); + lib = (struct pic_lib *)pic_obj_alloc(pic, sizeof(struct pic_lib), PIC_TT_LIB); lib->name = name; lib->env = env; diff --git a/extlib/benz/macro.c b/extlib/benz/macro.c index fbda5faf..b12c6bc6 100644 --- a/extlib/benz/macro.c +++ b/extlib/benz/macro.c @@ -381,32 +381,6 @@ pic_make_env(pic_state *pic, struct pic_env *up) return env; } -struct pic_env * -pic_null_syntactic_environment(pic_state *pic) -{ - struct pic_env *env; - - env = pic_make_env(pic, NULL); - - pic_define_syntactic_keyword(pic, env, pic->sDEFINE_LIBRARY, pic->rDEFINE_LIBRARY); - pic_define_syntactic_keyword(pic, env, pic->sIMPORT, pic->rIMPORT); - pic_define_syntactic_keyword(pic, env, pic->sEXPORT, pic->rEXPORT); - pic_define_syntactic_keyword(pic, env, pic->sIN_LIBRARY, pic->rIN_LIBRARY); - pic_define_syntactic_keyword(pic, env, pic->sCOND_EXPAND, pic->rCOND_EXPAND); - - return env; -} - -void -pic_define_syntactic_keyword(pic_state *pic, struct pic_env *env, pic_sym *sym, pic_sym *rsym) -{ - pic_put_rename(pic, env, sym, rsym); - - if (pic->lib && pic->lib->env == env) { - pic_export(pic, sym); - } -} - static pic_value defmacro_call(pic_state *pic) { diff --git a/extlib/benz/state.c b/extlib/benz/state.c index 6e174dd1..adc7b921 100644 --- a/extlib/benz/state.c +++ b/extlib/benz/state.c @@ -96,6 +96,8 @@ pic_init_features(pic_state *pic) static void pic_init_core(pic_state *pic) { + void pic_define_syntactic_keyword(pic_state *, struct pic_env *, pic_sym *, pic_sym *); + pic_init_features(pic); pic_deflibrary (pic, "(picrin base)") { diff --git a/extlib/benz/vm.c b/extlib/benz/vm.c index d8c4d390..995a6dac 100644 --- a/extlib/benz/vm.c +++ b/extlib/benz/vm.c @@ -393,6 +393,16 @@ pic_get_args(pic_state *pic, const char *format, ...) return argc; } +void +pic_define_syntactic_keyword(pic_state *pic, struct pic_env *env, pic_sym *sym, pic_sym *rsym) +{ + pic_put_rename(pic, env, sym, rsym); + + if (pic->lib && pic->lib->env == env) { + pic_export(pic, sym); + } +} + void pic_define_noexport(pic_state *pic, const char *name, pic_value val) {