diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2013-07-25 14:54:17 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2013-07-25 14:54:17 +0900 |
| commit | 63e5a3cfb10e238eaab2a77bcc83acd0d41e60fa (patch) | |
| tree | cd38afab99c11dbfc2114306c6b779c114a1ac39 | |
| parent | 8a298605e6667bfc15a1bef49b481f35829c0717 (diff) | |
| download | mruby-63e5a3cfb10e238eaab2a77bcc83acd0d41e60fa.tar.gz mruby-63e5a3cfb10e238eaab2a77bcc83acd0d41e60fa.zip | |
refactor out longjmp() to a function
| -rw-r--r-- | src/codegen.c | 12 | ||||
| -rw-r--r-- | src/error.c | 3 | ||||
| -rw-r--r-- | src/error.h | 1 | ||||
| -rw-r--r-- | src/vm.c | 10 |
4 files changed, 17 insertions, 9 deletions
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 <errno.h> -#include <setjmp.h> #include <stdarg.h> #include <stdlib.h> #include <string.h> @@ -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 */ @@ -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); +} |
