From 381ed58bff8959beb074055e232ce0060e55712c Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Sat, 7 Dec 2013 05:36:14 -0800 Subject: [PATCH] add global library table --- include/picrin.h | 3 ++- src/gc.c | 8 +++----- src/macro.c | 14 ++++++++------ src/state.c | 6 +++--- 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/include/picrin.h b/include/picrin.h index ea107174..ebf43a7b 100644 --- a/include/picrin.h +++ b/include/picrin.h @@ -57,7 +57,8 @@ typedef struct { pic_value *globals; size_t glen, gcapa; - struct pic_senv *global_senv; + pic_value lib_tbl; + struct pic_lib *lib; struct pic_irep **irep; size_t ilen, icapa; diff --git a/src/gc.c b/src/gc.c index b2cd56a0..4c6ac3f0 100644 --- a/src/gc.c +++ b/src/gc.c @@ -463,15 +463,13 @@ gc_mark_phase(pic_state *pic) gc_mark(pic, pic->globals[i]); } - /* macros */ - if (pic->global_senv) { - gc_mark_object(pic, (struct pic_object *)pic->global_senv); - } - /* pool */ for (i = 0; i < pic->plen; ++i) { gc_mark(pic, pic->pool[i]); } + + /* library table */ + gc_mark(pic, pic->lib_tbl); } static void diff --git a/src/macro.c b/src/macro.c index e750d9a3..b64a263f 100644 --- a/src/macro.c +++ b/src/macro.c @@ -7,6 +7,7 @@ #include "picrin/pair.h" #include "picrin/proc.h" #include "picrin/macro.h" +#include "picrin/lib.h" #include "xhash/xhash.h" #define FALLTHROUGH ((void)0) @@ -65,7 +66,7 @@ pic_core_syntactic_env(pic_state *pic) static struct pic_senv * new_global_senv(pic_state *pic) { - return pic->global_senv; + return pic->lib->senv; } static struct pic_senv * @@ -160,17 +161,18 @@ static void pic_defsyntax(pic_state *pic, const char *name, struct pic_proc *macro, struct pic_senv *mac_env) { struct pic_syntax *stx; + struct pic_senv *global_senv = pic->lib->senv; int idx; stx = pic_syntax_new_macro(pic, pic_intern_cstr(pic, name), macro, mac_env); - idx = pic->global_senv->xlen; - if (idx >= pic->global_senv->xcapa) { + idx = global_senv->xlen; + if (idx >= global_senv->xcapa) { pic_abort(pic, "macro table overflow"); } - pic->global_senv->stx[idx] = stx; - xh_put(pic->global_senv->tbl, name, ~idx); - pic->global_senv->xlen++; + global_senv->stx[idx] = stx; + xh_put(global_senv->tbl, name, ~idx); + global_senv->xlen++; } void diff --git a/src/state.c b/src/state.c index cc65d132..18e7b5c7 100644 --- a/src/state.c +++ b/src/state.c @@ -65,9 +65,9 @@ pic_open(int argc, char *argv[], char **envp) pic->glen = 0; pic->gcapa = PIC_GLOBALS_SIZE; - /* syntactic env */ - pic->global_senv = NULL; /* prevent gc from hanging during marking phase */ - pic->global_senv = pic_core_syntactic_env(pic); + /* libraries */ + pic->lib_tbl = pic_nil_value(); + pic->lib = NULL; /* pool */ pic->pool = (pic_value *)calloc(PIC_POOL_SIZE, sizeof(pic_value));