dynamically allocate GC arena
This commit is contained in:
parent
4bc38ace95
commit
a003b42435
|
@ -105,7 +105,8 @@ typedef struct {
|
|||
struct pic_jmpbuf *try_jmps;
|
||||
|
||||
struct pic_heap *heap;
|
||||
struct pic_object *arena[PIC_ARENA_SIZE];
|
||||
struct pic_object **arena;
|
||||
size_t arena_size;
|
||||
int arena_idx;
|
||||
|
||||
char *native_stack_start;
|
||||
|
|
|
@ -26,7 +26,8 @@ struct pic_cont {
|
|||
|
||||
pic_code *ip;
|
||||
|
||||
struct pic_object *arena[PIC_ARENA_SIZE];
|
||||
struct pic_object **arena;
|
||||
size_t arena_size;
|
||||
int arena_idx;
|
||||
|
||||
pic_value results;
|
||||
|
|
|
@ -139,7 +139,9 @@ save_cont(pic_state *pic, struct pic_cont **c)
|
|||
cont->ip = pic->ip;
|
||||
|
||||
cont->arena_idx = pic->arena_idx;
|
||||
memcpy(cont->arena, pic->arena, sizeof(struct pic_object *) * PIC_ARENA_SIZE);
|
||||
cont->arena_size = pic->arena_size;
|
||||
cont->arena = (struct pic_object **)pic_alloc(pic, sizeof(struct pic_object *) * pic->arena_size);
|
||||
memcpy(cont->arena, pic->arena, sizeof(struct pic_object *) * pic->arena_size);
|
||||
|
||||
cont->results = pic_undef_value();
|
||||
}
|
||||
|
@ -182,7 +184,9 @@ restore_cont(pic_state *pic, struct pic_cont *cont)
|
|||
|
||||
pic->ip = cont->ip;
|
||||
|
||||
memcpy(pic->arena, cont->arena, sizeof(struct pic_object *) * PIC_ARENA_SIZE);
|
||||
pic->arena = (struct pic_object **)pic_realloc(pic, pic->arena, sizeof(struct pic_object *) * cont->arena_size);
|
||||
memcpy(pic->arena, cont->arena, sizeof(struct pic_object *) * cont->arena_size);
|
||||
pic->arena_size = cont->arena_size;
|
||||
pic->arena_idx = cont->arena_idx;
|
||||
|
||||
memcpy(cont->stk_pos, cont->stk_ptr, cont->stk_len);
|
||||
|
|
3
src/gc.c
3
src/gc.c
|
@ -179,7 +179,7 @@ pic_free(pic_state *pic, void *ptr)
|
|||
static void
|
||||
gc_protect(pic_state *pic, struct pic_object *obj)
|
||||
{
|
||||
if (pic->arena_idx >= PIC_ARENA_SIZE) {
|
||||
if (pic->arena_idx >= pic->arena_size) {
|
||||
pic_abort(pic, "arena overflow");
|
||||
}
|
||||
pic->arena[pic->arena_idx++] = obj;
|
||||
|
@ -618,6 +618,7 @@ gc_finalize_object(pic_state *pic, struct pic_object *obj)
|
|||
pic_free(pic, cont->stk_ptr);
|
||||
pic_free(pic, cont->st_ptr);
|
||||
pic_free(pic, cont->ci_ptr);
|
||||
pic_free(pic, cont->arena);
|
||||
PIC_BLK_DECREF(pic, cont->blk);
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -70,6 +70,8 @@ pic_open(int argc, char *argv[], char **envp)
|
|||
pic->try_jmps = NULL;
|
||||
|
||||
/* GC arena */
|
||||
pic->arena = (struct pic_object **)calloc(PIC_ARENA_SIZE, sizeof(struct pic_object **));
|
||||
pic->arena_size = PIC_ARENA_SIZE;
|
||||
pic->arena_idx = 0;
|
||||
|
||||
/* native stack marker */
|
||||
|
@ -153,6 +155,9 @@ pic_close(pic_state *pic)
|
|||
xh_destroy(&pic->global_tbl);
|
||||
xh_destroy(&pic->macros);
|
||||
|
||||
/* free GC arena */
|
||||
free(pic->arena);
|
||||
|
||||
/* free symbol names */
|
||||
xh_begin(&it, &pic->sym_names);
|
||||
while (xh_next(&it)) {
|
||||
|
|
Loading…
Reference in New Issue