From 6de5bc75503b8ce23e7c2d0ede877cc1285a8d8b Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Thu, 14 Nov 2013 19:25:03 +0900 Subject: [PATCH] propagate jmp_bufs (useful when C stack and scheme stack interleave) --- src/codegen.c | 23 ++++++++++++----------- src/vm.c | 4 ++-- 2 files changed, 14 insertions(+), 13 deletions(-) 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(); }