add global library table

This commit is contained in:
Yuichi Nishiwaki 2013-12-07 05:36:14 -08:00
parent 931565d4ce
commit 381ed58bff
4 changed files with 16 additions and 15 deletions

View File

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

View File

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

View File

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

View File

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