add gc on/off flag

This commit is contained in:
Yuichi Nishiwaki 2015-01-19 12:14:29 +09:00
parent 3fc49b59be
commit ccc7a2beed
3 changed files with 25 additions and 12 deletions

View File

@ -760,6 +760,10 @@ pic_gc_run(pic_state *pic)
struct heap_page *page; struct heap_page *page;
#endif #endif
if (! pic->gc_enable) {
return;
}
#if DEBUG #if DEBUG
puts("gc run!"); puts("gc run!");
#endif #endif

View File

@ -119,6 +119,7 @@ typedef struct {
struct pic_reader *reader; struct pic_reader *reader;
bool gc_enable;
struct pic_heap *heap; struct pic_heap *heap;
struct pic_object **arena; struct pic_object **arena;
size_t arena_size, arena_idx; size_t arena_size, arena_idx;

View File

@ -25,6 +25,9 @@ pic_open(int argc, char *argv[], char **envp)
pic = malloc(sizeof(pic_state)); pic = malloc(sizeof(pic_state));
/* turn off GC */
pic->gc_enable = false;
/* root block */ /* root block */
pic->wind = NULL; pic->wind = NULL;
@ -67,11 +70,10 @@ pic_open(int argc, char *argv[], char **envp)
pic->libs = pic_nil_value(); pic->libs = pic_nil_value();
pic->lib = NULL; pic->lib = NULL;
/* reader */ /* GC arena */
pic->reader = malloc(sizeof(struct pic_reader)); pic->arena = calloc(PIC_ARENA_SIZE, sizeof(struct pic_object **));
pic->reader->typecase = PIC_CASE_DEFAULT; pic->arena_size = PIC_ARENA_SIZE;
pic->reader->trie = pic_make_trie(pic); pic->arena_idx = 0;
xh_init_int(&pic->reader->labels, sizeof(pic_value));
/* raised error object */ /* raised error object */
pic->err = pic_undef_value(); pic->err = pic_undef_value();
@ -81,17 +83,13 @@ pic_open(int argc, char *argv[], char **envp)
pic->xSTDOUT = NULL; pic->xSTDOUT = NULL;
pic->xSTDERR = NULL; pic->xSTDERR = NULL;
/* GC arena */
pic->arena = calloc(PIC_ARENA_SIZE, sizeof(struct pic_object **));
pic->arena_size = PIC_ARENA_SIZE;
pic->arena_idx = 0;
/* native stack marker */ /* native stack marker */
pic->native_stack_start = &t; pic->native_stack_start = &t;
ai = pic_gc_arena_preserve(pic);
#define S(slot,name) pic->slot = pic_intern_cstr(pic, name); #define S(slot,name) pic->slot = pic_intern_cstr(pic, name);
ai = pic_gc_arena_preserve(pic);
S(sDEFINE, "define"); S(sDEFINE, "define");
S(sLAMBDA, "lambda"); S(sLAMBDA, "lambda");
S(sIF, "if"); S(sIF, "if");
@ -138,7 +136,6 @@ pic_open(int argc, char *argv[], char **envp)
#define R(slot,name) pic->slot = pic_gensym(pic, pic_intern_cstr(pic, name)); #define R(slot,name) pic->slot = pic_gensym(pic, pic_intern_cstr(pic, name));
ai = pic_gc_arena_preserve(pic);
R(rDEFINE, "define"); R(rDEFINE, "define");
R(rLAMBDA, "lambda"); R(rLAMBDA, "lambda");
R(rIF, "if"); R(rIF, "if");
@ -163,6 +160,12 @@ pic_open(int argc, char *argv[], char **envp)
pic->wind->depth = 0; pic->wind->depth = 0;
pic->wind->in = pic->wind->out = NULL; pic->wind->in = pic->wind->out = NULL;
/* reader */
pic->reader = malloc(sizeof(struct pic_reader));
pic->reader->typecase = PIC_CASE_DEFAULT;
pic->reader->trie = pic_make_trie(pic);
xh_init_int(&pic->reader->labels, sizeof(pic_value));
/* init readers */ /* init readers */
pic_init_reader(pic); pic_init_reader(pic);
@ -176,6 +179,11 @@ pic_open(int argc, char *argv[], char **envp)
pic->xSTDOUT = pic_make_standard_port(pic, xstdout, PIC_PORT_OUT); pic->xSTDOUT = pic_make_standard_port(pic, xstdout, PIC_PORT_OUT);
pic->xSTDERR = pic_make_standard_port(pic, xstderr, PIC_PORT_OUT); pic->xSTDERR = pic_make_standard_port(pic, xstderr, PIC_PORT_OUT);
pic_gc_arena_restore(pic, ai);
/* turn on GC */
pic->gc_enable = true;
pic_init_core(pic); pic_init_core(pic);
return pic; return pic;