diff --git a/src/codegen.c b/src/codegen.c index 7459e54e..29c08a4e 100644 --- a/src/codegen.c +++ b/src/codegen.c @@ -851,21 +851,19 @@ pic_codegen(pic_state *pic, pic_value obj) { struct pic_proc *proc; codegen_state *state; + jmp_buf jmp, *prev_jmp = pic->jmp; state = new_codegen_state(pic); - if (! pic->jmp) { - jmp_buf jmp; - - if (setjmp(jmp) == 0) { - pic->jmp = &jmp; - } - else { - /* error occured */ - pic->jmp = NULL; - return NULL; - } + if (setjmp(jmp) == 0) { + pic->jmp = &jmp; } + else { + /* error occured */ + proc = NULL; + goto exit; + } + state->irep = new_irep(pic); state->irep->argc = 1; state->irep->localc = 0; @@ -883,6 +881,9 @@ pic_codegen(pic_state *pic, pic_value obj) print_irep(pic, proc->u.irep); #endif + exit: + pic->jmp = prev_jmp; + return proc; } diff --git a/src/vm.c b/src/vm.c index ce026cb6..84b9fa7e 100644 --- a/src/vm.c +++ b/src/vm.c @@ -278,7 +278,7 @@ pic_apply(pic_state *pic, struct pic_proc *proc, pic_value argv) { struct pic_code *pc, c; int ai = pic_gc_arena_preserve(pic); - jmp_buf jmp; + jmp_buf jmp, *prev_jmp = pic->jmp; size_t argc, i; struct pic_code boot[2]; @@ -653,7 +653,7 @@ pic_apply(pic_state *pic, struct pic_proc *proc, pic_value argv) L_STOP: val = POP(); - pic->jmp = NULL; + pic->jmp = prev_jmp; if (pic->errmsg) { return pic_undef_value(); }