cleanup macro.h

This commit is contained in:
Yuichi Nishiwaki 2015-06-09 20:20:56 +09:00
parent 6af60c9e2b
commit 30cbdd5c4f
5 changed files with 27 additions and 31 deletions

View File

@ -19,8 +19,6 @@ struct pic_env {
#define pic_env_p(v) (pic_type(v) == PIC_TT_ENV) #define pic_env_p(v) (pic_type(v) == PIC_TT_ENV)
#define pic_env_ptr(v) ((struct pic_env *)pic_ptr(v)) #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_p(pic_state *pic, pic_value obj);
bool pic_identifier_eq_p(pic_state *, struct pic_env *, pic_sym *, struct pic_env *, pic_sym *); 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 */); 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_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) #if defined(__cplusplus)
} }
#endif #endif

View File

@ -4,6 +4,18 @@
#include "picrin.h" #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 * struct pic_lib *
pic_make_library(pic_state *pic, pic_value name) 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); 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); 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 = (struct pic_lib *)pic_obj_alloc(pic, sizeof(struct pic_lib), PIC_TT_LIB);
lib->name = name; lib->name = name;
lib->env = env; lib->env = env;

View File

@ -381,32 +381,6 @@ pic_make_env(pic_state *pic, struct pic_env *up)
return env; 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 static pic_value
defmacro_call(pic_state *pic) defmacro_call(pic_state *pic)
{ {

View File

@ -96,6 +96,8 @@ pic_init_features(pic_state *pic)
static void static void
pic_init_core(pic_state *pic) 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_init_features(pic);
pic_deflibrary (pic, "(picrin base)") { pic_deflibrary (pic, "(picrin base)") {

View File

@ -393,6 +393,16 @@ pic_get_args(pic_state *pic, const char *format, ...)
return argc; 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 void
pic_define_noexport(pic_state *pic, const char *name, pic_value val) pic_define_noexport(pic_state *pic, const char *name, pic_value val)
{ {