add pic_throw function
This commit is contained in:
parent
2246213a74
commit
daa7513be5
|
@ -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 {
|
||||
|
|
24
src/error.c
24
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];
|
||||
|
|
|
@ -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();
|
||||
|
|
3
src/vm.c
3
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
|
||||
|
|
Loading…
Reference in New Issue