diff --git a/include/picrin.h b/include/picrin.h index b9a2190a..f71fae63 100644 --- a/include/picrin.h +++ b/include/picrin.h @@ -52,13 +52,17 @@ typedef struct { size_t slen, scapa; int uniq_sym_count; - /* positive for variables, negative for macros (bitwise-not) */ struct xhash *global_tbl; pic_value *globals; size_t glen, gcapa; struct pic_proc **macros; size_t mlen, mcapa; + /* positive for variables, negative for macros (bitwise-not) */ + struct xhash *var_tbl; + struct pic_syntax **stx; + size_t xlen, xcapa; + struct pic_irep **irep; size_t ilen, icapa; pic_value *pool; diff --git a/src/gc.c b/src/gc.c index 23aa1560..fc2f38f2 100644 --- a/src/gc.c +++ b/src/gc.c @@ -357,6 +357,8 @@ gc_mark_phase(pic_state *pic) /* macros */ for (i = 0; i < pic->mlen; ++i) { gc_mark_object(pic, (struct pic_object *)pic->macros[i]); + for (i = 0; i < pic->xlen; ++i) { + gc_mark_object(pic, (struct pic_object *)pic->stx[i]); } /* pool */ diff --git a/src/state.c b/src/state.c index a9218430..80367cab 100644 --- a/src/state.c +++ b/src/state.c @@ -3,6 +3,7 @@ #include "picrin.h" #include "picrin/gc.h" #include "picrin/proc.h" +#include "picrin/macro.h" #include "xhash/xhash.h" void pic_init_core(pic_state *); @@ -67,6 +68,12 @@ pic_open(int argc, char *argv[], char **envp) pic->mlen = 0; pic->mcapa = PIC_MACROS_SIZE; + /* identifier table */ + pic->var_tbl = xh_new(); + pic->stx = (struct pic_syntax **)calloc(PIC_MACROS_SIZE, sizeof(struct pic_syntax *)); + pic->xlen = 0; + pic->xcapa = PIC_MACROS_SIZE; + /* pool */ pic->pool = (pic_value *)calloc(PIC_POOL_SIZE, sizeof(pic_value)); pic->plen = 0;