diff --git a/include/picrin/error.h b/include/picrin/error.h index a4caf63a..5aff2916 100644 --- a/include/picrin/error.h +++ b/include/picrin/error.h @@ -27,6 +27,8 @@ struct pic_jmpbuf { void pic_push_try(pic_state *); void pic_pop_try(pic_state *); +noreturn void pic_throw(pic_state *, struct pic_error *); + struct pic_error { PIC_OBJECT_HEADER enum pic_error_kind { diff --git a/src/error.c b/src/error.c index d3798f21..10097548 100644 --- a/src/error.c +++ b/src/error.c @@ -39,16 +39,8 @@ pic_pop_try(pic_state *pic) pic->try_jmps = prev; } -const char * -pic_errmsg(pic_state *pic) -{ - assert(pic->err != NULL); - - return pic_str_cstr(pic->err->msg); -} - -noreturn static void -raise(pic_state *pic, struct pic_error *e) +noreturn void +pic_throw(pic_state *pic, struct pic_error *e) { pic->err = e; if (! pic->jmp) { @@ -58,6 +50,14 @@ raise(pic_state *pic, struct pic_error *e) longjmp(*pic->jmp, 1); } +const char * +pic_errmsg(pic_state *pic) +{ + assert(pic->err != NULL); + + return pic_str_cstr(pic->err->msg); +} + noreturn static void error(pic_state *pic, pic_str *msg, pic_value irrs) { @@ -68,7 +68,7 @@ error(pic_state *pic, pic_str *msg, pic_value irrs) e->msg = msg; e->irrs = irrs; - raise(pic, e); + pic_throw(pic, e); } void @@ -115,7 +115,7 @@ pic_raise(pic_state *pic, struct pic_error *e) struct pic_proc *handler; if (pic->ridx == 0) { - raise(pic, e); + pic_throw(pic, e); } handler = pic->rescue[--pic->ridx]; diff --git a/src/macro.c b/src/macro.c index 4af43ae6..89a2a3d3 100644 --- a/src/macro.c +++ b/src/macro.c @@ -243,7 +243,7 @@ macroexpand(pic_state *pic, pic_value expr, struct pic_senv *senv) pic_catch { /* restores pic->lib even if an error occurs */ pic_in_library(pic, prev->name); - longjmp(*pic->jmp, 1); + pic_throw(pic, pic->err); } return pic_none_value(); diff --git a/src/vm.c b/src/vm.c index 51e1787a..047406e2 100644 --- a/src/vm.c +++ b/src/vm.c @@ -18,6 +18,7 @@ #include "picrin/var.h" #include "picrin/lib.h" #include "picrin/macro.h" +#include "picrin/error.h" #define GET_OPERAND(pic,n) ((pic)->ci->fp[(n)]) @@ -935,7 +936,7 @@ pic_apply(pic_state *pic, struct pic_proc *proc, pic_value argv) pic->jmp = prev_jmp; if (pic->err) { - longjmp(*pic->jmp, 1); + pic_throw(pic, pic->err); } #if VM_DEBUG