Merge branch 'fast-callcc'

This commit is contained in:
Yuichi Nishiwaki 2015-07-30 02:52:26 +09:00
commit 71a56a6b75
4 changed files with 22 additions and 21 deletions

View File

@ -11,21 +11,23 @@ struct pic_fullcont {
ptrdiff_t stk_len;
pic_value *st_ptr;
size_t sp_offset, st_len;
size_t sp_offset;
ptrdiff_t st_len;
pic_callinfo *ci_ptr;
size_t ci_offset, ci_len;
size_t ci_offset;
ptrdiff_t ci_len;
struct pic_proc **xp_ptr;
size_t xp_offset, xp_len;
size_t xp_offset;
ptrdiff_t xp_len;
pic_code *ip;
pic_value ptable;
struct pic_object **arena;
size_t arena_size;
int arena_idx;
size_t arena_size, arena_idx;
pic_value results;
};
@ -81,7 +83,7 @@ cont_mark(pic_state *pic, void *data, void (*mark)(pic_state *, pic_value))
}
/* arena */
for (i = 0; i < (size_t)cont->arena_idx; ++i) {
for (i = 0; i < cont->arena_idx; ++i) {
mark(pic, pic_obj_value(cont->arena[i]));
}
@ -184,17 +186,17 @@ restore_cont(pic_state *pic, struct pic_fullcont *cont)
pic->cc = cont->prev_jmp;
pic->cp = cont->cp;
pic->stbase = pic_realloc(pic, pic->stbase, sizeof(pic_value) * cont->st_len);
assert(pic->stend - pic->stbase >= cont->st_len);
memcpy(pic->stbase, cont->st_ptr, sizeof(pic_value) * cont->st_len);
pic->sp = pic->stbase + cont->sp_offset;
pic->stend = pic->stbase + cont->st_len;
pic->cibase = pic_realloc(pic, pic->cibase, sizeof(pic_callinfo) * cont->ci_len);
assert(pic->ciend - pic->cibase >= cont->ci_len);
memcpy(pic->cibase, cont->ci_ptr, sizeof(pic_callinfo) * cont->ci_len);
pic->ci = pic->cibase + cont->ci_offset;
pic->ciend = pic->cibase + cont->ci_len;
pic->xpbase = pic_realloc(pic, pic->xpbase, sizeof(struct pic_proc *) * cont->xp_len);
assert(pic->xpend - pic->xpbase >= cont->xp_len);
memcpy(pic->xpbase, cont->xp_ptr, sizeof(struct pic_proc *) * cont->xp_len);
pic->xp = pic->xpbase + cont->xp_offset;
pic->xpend = pic->xpbase + cont->xp_len;
@ -203,7 +205,7 @@ restore_cont(pic_state *pic, struct pic_fullcont *cont)
pic->ptable = cont->ptable;
pic->arena = pic_realloc(pic, pic->arena, sizeof(struct pic_object *) * cont->arena_size);
assert(pic->arena_size >= 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;

View File

@ -41,6 +41,7 @@ union object {
struct pic_heap {
union header base, *freep;
struct heap_page *pages;
struct pic_reg *regs; /* weak map chain */
};
struct pic_heap *
@ -56,6 +57,8 @@ pic_heap_open(pic_state *pic)
heap->freep = &heap->base;
heap->pages = NULL;
heap->regs = NULL;
return heap;
}
@ -400,8 +403,8 @@ gc_mark_object(pic_state *pic, union object *obj)
case PIC_TT_REG: {
struct pic_reg *reg = (struct pic_reg *)obj;
reg->prev = pic->regs;
pic->regs = reg;
reg->prev = pic->heap->regs;
pic->heap->regs = reg;
break;
}
case PIC_TT_CP: {
@ -439,7 +442,7 @@ gc_mark_phase(pic_state *pic)
struct pic_proc **xhandler;
size_t j;
assert(pic->regs == NULL);
assert(pic->heap->regs == NULL);
/* checkpoint */
if (pic->cp) {
@ -519,7 +522,7 @@ gc_mark_phase(pic_state *pic)
struct pic_reg *reg;
j = 0;
reg = pic->regs;
reg = pic->heap->regs;
while (reg != NULL) {
h = &reg->hash;
@ -664,8 +667,8 @@ gc_sweep_phase(pic_state *pic)
size_t total = 0, inuse = 0;
/* registries */
while (pic->regs != NULL) {
h = &pic->regs->hash;
while (pic->heap->regs != NULL) {
h = &pic->heap->regs->hash;
for (it = kh_begin(h); it != kh_end(h); ++it) {
if (! kh_exist(h, it))
continue;
@ -674,7 +677,7 @@ gc_sweep_phase(pic_state *pic)
kh_del(reg, h, it);
}
}
pic->regs = pic->regs->prev;
pic->heap->regs = pic->heap->regs->prev;
}
/* symbol table */

View File

@ -131,7 +131,6 @@ struct pic_state {
struct pic_heap *heap;
struct pic_object **arena;
size_t arena_size, arena_idx;
struct pic_reg *regs;
pic_value err;

View File

@ -300,9 +300,6 @@ pic_open(pic_allocf allocf, void *userdata)
/* memory heap */
pic->heap = pic_heap_open(pic);
/* registries */
pic->regs = NULL;
/* symbol table */
kh_init(s, &pic->syms);