add global identifier table

This commit is contained in:
Yuichi Nishiwaki 2013-11-26 08:30:30 -08:00
parent ce3e2b939c
commit a2e1f21b29
3 changed files with 14 additions and 1 deletions

View File

@ -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;

View File

@ -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 */

View File

@ -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;