From d0abe2d193b3d1bfb11a1bee6a915e664a9cb25a Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Wed, 10 Sep 2014 01:41:10 +0900 Subject: [PATCH] add pic->feature --- gc.c | 2 ++ include/picrin.h | 5 ++++- init.c | 9 +++++++++ state.c | 4 ++++ 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/gc.c b/gc.c index 9520e40a..f52d2fd7 100644 --- a/gc.c +++ b/gc.c @@ -618,6 +618,8 @@ gc_mark_phase(pic_state *pic) } } + gc_mark(pic, pic->features); + /* readers */ gc_mark_trie(pic, pic->reader->trie); diff --git a/include/picrin.h b/include/picrin.h index fff10cbb..ac03feb6 100644 --- a/include/picrin.h +++ b/include/picrin.h @@ -87,6 +87,8 @@ typedef struct { struct pic_lib *PICRIN_BASE; struct pic_lib *PICRIN_USER; + pic_value features; + xhash syms; /* name to symbol */ xhash sym_names; /* symbol to name */ int sym_cnt; @@ -137,10 +139,11 @@ void pic_gc_arena_restore(pic_state *, size_t); pic_state *pic_open(int argc, char *argv[], char **envp); void pic_close(pic_state *); +void pic_add_feature(pic_state *, const char *); + void pic_define(pic_state *, const char *, pic_value); /* automatic export */ pic_value pic_ref(pic_state *, struct pic_lib *, const char *); void pic_set(pic_state *, struct pic_lib *, const char *, pic_value); - pic_value pic_funcall(pic_state *pic, const char *name, pic_list args); struct pic_proc *pic_get_proc(pic_state *); diff --git a/init.c b/init.c index a5e70d71..77e16524 100644 --- a/init.c +++ b/init.c @@ -8,6 +8,12 @@ #include "picrin/macro.h" #include "picrin/error.h" +void +pic_add_feature(pic_state *pic, const char *feature) +{ + pic_push(pic, pic_sym_value(pic_intern_cstr(pic, feature)), pic->features); +} + void pic_init_bool(pic_state *); void pic_init_pair(pic_state *); void pic_init_port(pic_state *); @@ -42,6 +48,9 @@ pic_init_core(pic_state *pic) { size_t ai = pic_gc_arena_preserve(pic); + pic_add_feature(pic, "picrin"); + pic_add_feature(pic, "ieee-float"); + pic_deflibrary (pic, "(picrin base)") { pic_define_syntactic_keyword(pic, pic->lib->env, pic->sDEFINE, pic->rDEFINE); pic_define_syntactic_keyword(pic, pic->lib->env, pic->sSETBANG, pic->rSETBANG); diff --git a/state.c b/state.c index 0b2b5123..07d85892 100644 --- a/state.c +++ b/state.c @@ -57,6 +57,9 @@ pic_open(int argc, char *argv[], char **envp) /* macros */ xh_init_int(&pic->macros, sizeof(struct pic_macro *)); + /* features */ + pic->features = pic_nil_value(); + /* libraries */ pic->libs = pic_nil_value(); pic->lib = NULL; @@ -184,6 +187,7 @@ pic_close(pic_state *pic) pic->arena_idx = 0; pic->err = NULL; xh_clear(&pic->macros); + pic->features = pic_nil_value(); pic->libs = pic_nil_value(); /* free all heap objects */