From 63e5a3cfb10e238eaab2a77bcc83acd0d41e60fa Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Thu, 25 Jul 2013 14:54:17 +0900 Subject: refactor out longjmp() to a function --- src/codegen.c | 12 +++++++----- src/error.c | 3 +-- src/error.h | 1 + src/vm.c | 10 ++++++++-- 4 files changed, 17 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/codegen.c b/src/codegen.c index 37176653b..5681ce03a 100644 --- a/src/codegen.c +++ b/src/codegen.c @@ -2842,13 +2842,15 @@ codegen_start(mrb_state *mrb, parser_state *p) if (p->filename) { scope->filename = p->filename; } - if (setjmp(scope->jmp) != 0) { + if (setjmp(scope->jmp) == 0) { + // prepare irep + codegen(scope, p->tree, NOVAL); + mrb_pool_close(scope->mpool); + return 0; + } + else { return -1; } - // prepare irep - codegen(scope, p->tree, NOVAL); - mrb_pool_close(scope->mpool); - return 0; } int diff --git a/src/error.c b/src/error.c index 9f3a86cc8..df4bbc866 100644 --- a/src/error.c +++ b/src/error.c @@ -5,7 +5,6 @@ */ #include -#include #include #include #include @@ -219,7 +218,7 @@ mrb_exc_raise(mrb_state *mrb, mrb_value exc) mrb_p(mrb, exc); abort(); } - longjmp(*(jmp_buf*)mrb->jmp, 1); + mrb_longjmp(mrb); } void diff --git a/src/error.h b/src/error.h index 3726cb4c4..5aa4ca374 100644 --- a/src/error.h +++ b/src/error.h @@ -14,5 +14,6 @@ mrb_value make_exception(mrb_state *mrb, int argc, mrb_value *argv, int isstr); mrb_value mrb_make_exception(mrb_state *mrb, int argc, mrb_value *argv); mrb_value mrb_format(mrb_state *mrb, const char *format, ...); void mrb_exc_print(mrb_state *mrb, struct RObject *exc); +void mrb_longjmp(mrb_state *mrb); #endif /* MRUBY_ERROR_H */ diff --git a/src/vm.c b/src/vm.c index c9e80e0ed..d4ab1af46 100644 --- a/src/vm.c +++ b/src/vm.c @@ -1,4 +1,4 @@ -/* + /* ** vm.c - virtual machine for mruby ** ** See Copyright Notice in mruby.h @@ -1261,7 +1261,7 @@ mrb_run(mrb_state *mrb, struct RProc *proc, mrb_value self) mrb->c->stack = mrb->c->stbase + ci[1].stackidx; if (ci[1].acc < 0 && prev_jmp) { mrb->jmp = prev_jmp; - longjmp(*(jmp_buf*)mrb->jmp, 1); + mrb_longjmp(mrb); } while (eidx > ci->eidx) { ecall(mrb, --eidx); @@ -2127,3 +2127,9 @@ mrb_run(mrb_state *mrb, struct RProc *proc, mrb_value self) } END_DISPATCH; } + +void +mrb_longjmp(mrb_state *mrb) +{ + longjmp(*(jmp_buf*)mrb->jmp, 1); +} -- cgit v1.2.3