tear off on longjmp

This commit is contained in:
Yuichi Nishiwaki 2014-07-04 13:21:45 +09:00
parent a75a48fc8f
commit f176fadb89
3 changed files with 24 additions and 0 deletions

View File

@ -164,9 +164,12 @@ native_stack_extend(pic_state *pic, struct pic_cont *cont)
noreturn static void
restore_cont(pic_state *pic, struct pic_cont *cont)
{
void pic_vm_tear_off(pic_state *);
char v;
struct pic_cont *tmp = cont;
pic_vm_tear_off(pic); /* tear off */
if (&v < pic->native_stack_start) {
if (&v > cont->stk_pos) native_stack_extend(pic, cont);
}

View File

@ -91,11 +91,16 @@ error_new(pic_state *pic, short type, pic_str *msg, pic_value irrs)
noreturn void
pic_throw_error(pic_state *pic, struct pic_error *e)
{
void pic_vm_tear_off(pic_state *);
pic_vm_tear_off(pic); /* tear off */
pic->err = e;
if (! pic->jmp) {
puts(pic_errmsg(pic));
abort();
}
longjmp(*pic->jmp, 1);
}

View File

@ -503,12 +503,28 @@ vm_tear_off(pic_state *pic)
assert(pic->ci->env != NULL);
env = pic->ci->env;
if (env->regs == env->storage) {
return; /* is torn off */
}
for (i = 0; i < env->regc; ++i) {
env->storage[i] = env->regs[i];
}
env->regs = env->storage;
}
void
pic_vm_tear_off(pic_state *pic)
{
pic_callinfo *ci;
for (ci = pic->ci; ci > pic->cibase; ci--) {
if (pic->ci->env != NULL) {
vm_tear_off(pic);
}
}
}
pic_value
pic_apply0(pic_state *pic, struct pic_proc *proc)
{