add global library table
This commit is contained in:
parent
931565d4ce
commit
381ed58bff
|
@ -57,7 +57,8 @@ typedef struct {
|
||||||
pic_value *globals;
|
pic_value *globals;
|
||||||
size_t glen, gcapa;
|
size_t glen, gcapa;
|
||||||
|
|
||||||
struct pic_senv *global_senv;
|
pic_value lib_tbl;
|
||||||
|
struct pic_lib *lib;
|
||||||
|
|
||||||
struct pic_irep **irep;
|
struct pic_irep **irep;
|
||||||
size_t ilen, icapa;
|
size_t ilen, icapa;
|
||||||
|
|
8
src/gc.c
8
src/gc.c
|
@ -463,15 +463,13 @@ gc_mark_phase(pic_state *pic)
|
||||||
gc_mark(pic, pic->globals[i]);
|
gc_mark(pic, pic->globals[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* macros */
|
|
||||||
if (pic->global_senv) {
|
|
||||||
gc_mark_object(pic, (struct pic_object *)pic->global_senv);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* pool */
|
/* pool */
|
||||||
for (i = 0; i < pic->plen; ++i) {
|
for (i = 0; i < pic->plen; ++i) {
|
||||||
gc_mark(pic, pic->pool[i]);
|
gc_mark(pic, pic->pool[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* library table */
|
||||||
|
gc_mark(pic, pic->lib_tbl);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
14
src/macro.c
14
src/macro.c
|
@ -7,6 +7,7 @@
|
||||||
#include "picrin/pair.h"
|
#include "picrin/pair.h"
|
||||||
#include "picrin/proc.h"
|
#include "picrin/proc.h"
|
||||||
#include "picrin/macro.h"
|
#include "picrin/macro.h"
|
||||||
|
#include "picrin/lib.h"
|
||||||
#include "xhash/xhash.h"
|
#include "xhash/xhash.h"
|
||||||
|
|
||||||
#define FALLTHROUGH ((void)0)
|
#define FALLTHROUGH ((void)0)
|
||||||
|
@ -65,7 +66,7 @@ pic_core_syntactic_env(pic_state *pic)
|
||||||
static struct pic_senv *
|
static struct pic_senv *
|
||||||
new_global_senv(pic_state *pic)
|
new_global_senv(pic_state *pic)
|
||||||
{
|
{
|
||||||
return pic->global_senv;
|
return pic->lib->senv;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct pic_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)
|
pic_defsyntax(pic_state *pic, const char *name, struct pic_proc *macro, struct pic_senv *mac_env)
|
||||||
{
|
{
|
||||||
struct pic_syntax *stx;
|
struct pic_syntax *stx;
|
||||||
|
struct pic_senv *global_senv = pic->lib->senv;
|
||||||
int idx;
|
int idx;
|
||||||
|
|
||||||
stx = pic_syntax_new_macro(pic, pic_intern_cstr(pic, name), macro, mac_env);
|
stx = pic_syntax_new_macro(pic, pic_intern_cstr(pic, name), macro, mac_env);
|
||||||
|
|
||||||
idx = pic->global_senv->xlen;
|
idx = global_senv->xlen;
|
||||||
if (idx >= pic->global_senv->xcapa) {
|
if (idx >= global_senv->xcapa) {
|
||||||
pic_abort(pic, "macro table overflow");
|
pic_abort(pic, "macro table overflow");
|
||||||
}
|
}
|
||||||
pic->global_senv->stx[idx] = stx;
|
global_senv->stx[idx] = stx;
|
||||||
xh_put(pic->global_senv->tbl, name, ~idx);
|
xh_put(global_senv->tbl, name, ~idx);
|
||||||
pic->global_senv->xlen++;
|
global_senv->xlen++;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -65,9 +65,9 @@ pic_open(int argc, char *argv[], char **envp)
|
||||||
pic->glen = 0;
|
pic->glen = 0;
|
||||||
pic->gcapa = PIC_GLOBALS_SIZE;
|
pic->gcapa = PIC_GLOBALS_SIZE;
|
||||||
|
|
||||||
/* syntactic env */
|
/* libraries */
|
||||||
pic->global_senv = NULL; /* prevent gc from hanging during marking phase */
|
pic->lib_tbl = pic_nil_value();
|
||||||
pic->global_senv = pic_core_syntactic_env(pic);
|
pic->lib = NULL;
|
||||||
|
|
||||||
/* pool */
|
/* pool */
|
||||||
pic->pool = (pic_value *)calloc(PIC_POOL_SIZE, sizeof(pic_value));
|
pic->pool = (pic_value *)calloc(PIC_POOL_SIZE, sizeof(pic_value));
|
||||||
|
|
Loading…
Reference in New Issue