cosmetic changes

This commit is contained in:
Yuichi Nishiwaki 2014-07-13 20:06:08 +09:00
parent e1cba4b48e
commit 601b54ba1f
1 changed files with 54 additions and 54 deletions

View File

@ -11,31 +11,7 @@
#include "picrin/error.h"
#include "picrin/dict.h"
struct pic_senv *
pic_null_syntactic_environment(pic_state *pic)
{
struct pic_senv *senv;
senv = (struct pic_senv *)pic_obj_alloc(pic, sizeof(struct pic_senv), PIC_TT_SENV);
senv->up = NULL;
xh_init_int(&senv->renames, sizeof(pic_sym));
pic_define_syntactic_keyword(pic, senv, pic->sDEFINE_LIBRARY);
pic_define_syntactic_keyword(pic, senv, pic->sIMPORT);
pic_define_syntactic_keyword(pic, senv, pic->sEXPORT);
return senv;
}
void
pic_define_syntactic_keyword(pic_state *pic, struct pic_senv *senv, pic_sym sym)
{
pic_put_rename(pic, senv, sym, sym);
if (pic->lib && pic->lib->senv == senv) {
pic_export(pic, sym);
}
}
static pic_value macroexpand(pic_state *, pic_value, struct pic_senv *, struct pic_dict *);
pic_sym
pic_add_rename(pic_state *pic, struct pic_senv *senv, pic_sym sym)
@ -94,35 +70,6 @@ find_macro(pic_state *pic, pic_sym rename)
return xh_val(e, struct pic_macro *);
}
void
pic_defmacro(pic_state *pic, const char *name, struct pic_proc *macro)
{
pic_sym sym, rename;
/* symbol registration */
sym = pic_intern_cstr(pic, name);
rename = pic_add_rename(pic, pic->lib->senv, sym);
define_macro(pic, rename, macro, NULL);
/* auto export! */
pic_export(pic, sym);
}
static pic_value macroexpand_node(pic_state *, pic_value, struct pic_senv *, struct pic_dict *);
static pic_value
macroexpand(pic_state *pic, pic_value expr, struct pic_senv *senv, struct pic_dict *cxt)
{
size_t ai = pic_gc_arena_preserve(pic);
pic_value v;
v = macroexpand_node(pic, expr, senv, cxt);
pic_gc_arena_restore(pic, ai);
pic_gc_protect(pic, v);
return v;
}
static struct pic_senv *
push_scope(pic_state *pic, pic_value formals, struct pic_senv *up, struct pic_dict *cxt)
{
@ -579,6 +526,19 @@ macroexpand_node(pic_state *pic, pic_value expr, struct pic_senv *senv, struct p
UNREACHABLE();
}
static pic_value
macroexpand(pic_state *pic, pic_value expr, struct pic_senv *senv, struct pic_dict *cxt)
{
size_t ai = pic_gc_arena_preserve(pic);
pic_value v;
v = macroexpand_node(pic, expr, senv, cxt);
pic_gc_arena_restore(pic, ai);
pic_gc_protect(pic, v);
return v;
}
pic_value
pic_macroexpand(pic_state *pic, pic_value expr)
{
@ -601,6 +561,46 @@ pic_macroexpand(pic_state *pic, pic_value expr)
return v;
}
struct pic_senv *
pic_null_syntactic_environment(pic_state *pic)
{
struct pic_senv *senv;
senv = (struct pic_senv *)pic_obj_alloc(pic, sizeof(struct pic_senv), PIC_TT_SENV);
senv->up = NULL;
xh_init_int(&senv->renames, sizeof(pic_sym));
pic_define_syntactic_keyword(pic, senv, pic->sDEFINE_LIBRARY);
pic_define_syntactic_keyword(pic, senv, pic->sIMPORT);
pic_define_syntactic_keyword(pic, senv, pic->sEXPORT);
return senv;
}
void
pic_define_syntactic_keyword(pic_state *pic, struct pic_senv *senv, pic_sym sym)
{
pic_put_rename(pic, senv, sym, sym);
if (pic->lib && pic->lib->senv == senv) {
pic_export(pic, sym);
}
}
void
pic_defmacro(pic_state *pic, const char *name, struct pic_proc *macro)
{
pic_sym sym, rename;
/* symbol registration */
sym = pic_intern_cstr(pic, name);
rename = pic_add_rename(pic, pic->lib->senv, sym);
define_macro(pic, rename, macro, NULL);
/* auto export! */
pic_export(pic, sym);
}
static pic_value
pic_macro_gensym(pic_state *pic)
{