when restoring continuation sp and ci must be re-allocated

This commit is contained in:
Yuichi Nishiwaki 2013-11-17 15:58:53 +09:00
parent d470997f03
commit c79e08632c
3 changed files with 14 additions and 10 deletions

View File

@ -10,11 +10,11 @@ struct pic_cont {
size_t stk_len; size_t stk_len;
pic_value *stk_pos, *stk_ptr; pic_value *stk_pos, *stk_ptr;
pic_value *sp, *st_ptr; pic_value *st_ptr;
size_t st_len; size_t sp_offset, st_len;
pic_callinfo *ci, *ci_ptr; pic_callinfo *ci_ptr;
size_t ci_len; size_t ci_offset, ci_len;
struct pic_object *arena[PIC_ARENA_SIZE]; struct pic_object *arena[PIC_ARENA_SIZE];
int arena_idx; int arena_idx;

View File

@ -38,12 +38,12 @@ save_cont(pic_state *pic)
cont->stk_ptr = pic_alloc(pic, sizeof(pic_value) * cont->stk_len); cont->stk_ptr = pic_alloc(pic, sizeof(pic_value) * cont->stk_len);
memcpy(cont->stk_ptr, cont->stk_pos, sizeof(pic_value) * cont->stk_len); memcpy(cont->stk_ptr, cont->stk_pos, sizeof(pic_value) * cont->stk_len);
cont->sp = pic->sp; cont->sp_offset = pic->sp - pic->stbase;
cont->st_len = pic->stend - pic->stbase; cont->st_len = pic->stend - pic->stbase;
cont->st_ptr = (pic_value *)pic_alloc(pic, sizeof(pic_value) * cont->st_len); cont->st_ptr = (pic_value *)pic_alloc(pic, sizeof(pic_value) * cont->st_len);
memcpy(cont->st_ptr, pic->stbase, sizeof(pic_value) * cont->st_len); memcpy(cont->st_ptr, pic->stbase, sizeof(pic_value) * cont->st_len);
cont->ci = pic->ci; cont->ci_offset = pic->ci - pic->cibase;
cont->ci_len = pic->ciend - pic->cibase; cont->ci_len = pic->ciend - pic->cibase;
cont->ci_ptr = (pic_callinfo *)pic_alloc(pic, sizeof(pic_callinfo) * cont->ci_len); cont->ci_ptr = (pic_callinfo *)pic_alloc(pic, sizeof(pic_callinfo) * cont->ci_len);
memcpy(cont->ci_ptr, pic->cibase, sizeof(pic_callinfo) * cont->ci_len); memcpy(cont->ci_ptr, pic->cibase, sizeof(pic_callinfo) * cont->ci_len);
@ -82,11 +82,15 @@ restore_cont(pic_state *pic, struct pic_cont *cont)
PIC_BLK_INCREF(pic, cont->blk); PIC_BLK_INCREF(pic, cont->blk);
pic->blk = cont->blk; pic->blk = cont->blk;
pic->sp = cont->sp; pic->stbase = (pic_value *)pic_realloc(pic, pic->stbase, sizeof(pic_value) * cont->st_len);
memcpy(pic->stbase, cont->st_ptr, sizeof(pic_value) * 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->ci = cont->ci; pic->cibase = (pic_callinfo *)pic_realloc(pic, pic->cibase, sizeof(pic_callinfo) * cont->ci_len);
memcpy(pic->cibase, cont->ci_ptr, sizeof(pic_callinfo) * 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;
memcpy(pic->arena, cont->arena, sizeof(struct pic_object *) * PIC_ARENA_SIZE); memcpy(pic->arena, cont->arena, sizeof(struct pic_object *) * PIC_ARENA_SIZE);
pic->arena_idx = cont->arena_idx; pic->arena_idx = cont->arena_idx;

View File

@ -230,12 +230,12 @@ gc_mark_object(pic_state *pic, struct pic_object *obj)
gc_mark_block(pic, cont->blk); gc_mark_block(pic, cont->blk);
/* stack */ /* stack */
for (stack = cont->st_ptr; stack != cont->sp; ++stack) { for (stack = cont->st_ptr; stack != cont->st_ptr + cont->sp_offset; ++stack) {
gc_mark(pic, *stack); gc_mark(pic, *stack);
} }
/* callinfo */ /* callinfo */
for (ci = cont->ci; ci != cont->ci_ptr; --ci) { for (ci = cont->ci_ptr + cont->ci_offset; ci != cont->ci_ptr; --ci) {
if (ci->env) { if (ci->env) {
gc_mark_object(pic, (struct pic_object *)ci->env); gc_mark_object(pic, (struct pic_object *)ci->env);
} }