don't setjmp in pic_push_try
This commit is contained in:
parent
eb1e01d000
commit
d6c6427ff7
44
error.c
44
error.c
|
@ -86,39 +86,27 @@ native_exception_handler(pic_state *pic)
|
|||
UNREACHABLE();
|
||||
}
|
||||
|
||||
bool
|
||||
pic_push_try(pic_state *pic)
|
||||
void
|
||||
pic_push_try(pic_state *pic, struct pic_escape *escape)
|
||||
{
|
||||
struct pic_escape *escape = pic_alloc(pic, sizeof(struct pic_escape));
|
||||
struct pic_proc *cont, *handler;
|
||||
size_t xp_len, xp_offset;
|
||||
|
||||
pic_save_point(pic, escape);
|
||||
cont = pic_make_econt(pic, escape);
|
||||
|
||||
if (setjmp(escape->jmp)) {
|
||||
puts("escaping");
|
||||
handler = pic_make_proc(pic, native_exception_handler, "(native-exception-handler)");
|
||||
|
||||
return false;
|
||||
} else {
|
||||
struct pic_proc *cont, *handler;
|
||||
size_t xp_len, xp_offset;
|
||||
pic_attr_set(pic, handler, "@@escape", pic_obj_value(cont));
|
||||
|
||||
cont = pic_make_econt(pic, escape);
|
||||
|
||||
handler = pic_make_proc(pic, native_exception_handler, "(native-exception-handler)");
|
||||
|
||||
pic_attr_set(pic, handler, "@@escape", pic_obj_value(cont));
|
||||
|
||||
if (pic->xp >= pic->xpend) {
|
||||
xp_len = (pic->xpend - pic->xpbase) * 2;
|
||||
xp_offset = pic->xp - pic->xpbase;
|
||||
pic->xpbase = pic_realloc(pic, pic->xpbase, sizeof(struct pic_proc *) * xp_len);
|
||||
pic->xp = pic->xpbase + xp_offset;
|
||||
pic->xpend = pic->xpbase + xp_len;
|
||||
}
|
||||
|
||||
*pic->xp++ = handler;
|
||||
|
||||
return true;
|
||||
if (pic->xp >= pic->xpend) {
|
||||
xp_len = (pic->xpend - pic->xpbase) * 2;
|
||||
xp_offset = pic->xp - pic->xpbase;
|
||||
pic->xpbase = pic_realloc(pic, pic->xpbase, sizeof(struct pic_proc *) * xp_len);
|
||||
pic->xp = pic->xpbase + xp_offset;
|
||||
pic->xpend = pic->xpbase + xp_len;
|
||||
}
|
||||
|
||||
*pic->xp++ = handler;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -137,8 +125,6 @@ pic_pop_try(pic_state *pic)
|
|||
assert(pic_data_p(escape));
|
||||
|
||||
((struct pic_escape *)pic_data_ptr(escape)->data)->valid = false;
|
||||
|
||||
puts("pop_try done;");
|
||||
}
|
||||
|
||||
struct pic_error *
|
||||
|
|
|
@ -9,6 +9,8 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "picrin/cont.h"
|
||||
|
||||
struct pic_error {
|
||||
PIC_OBJECT_HEADER
|
||||
pic_sym type;
|
||||
|
@ -25,13 +27,19 @@ struct pic_error *pic_make_error(pic_state *, pic_sym, const char *, pic_list);
|
|||
/* do not return from try block! */
|
||||
|
||||
#define pic_try \
|
||||
if (pic_push_try(pic)) \
|
||||
pic_try_(GENSYM(escape))
|
||||
#define pic_try_(escape) \
|
||||
struct pic_escape *escape = pic_alloc(pic, sizeof(struct pic_escape)); \
|
||||
pic_save_point(pic, escape); \
|
||||
if (setjmp(escape->jmp) == 0) { \
|
||||
pic_push_try(pic, escape); \
|
||||
do
|
||||
#define pic_catch \
|
||||
while (pic_pop_try(pic), 0); \
|
||||
else
|
||||
#define pic_catch \
|
||||
while (0); \
|
||||
pic_pop_try(pic); \
|
||||
} else
|
||||
|
||||
bool pic_push_try(pic_state *);
|
||||
void pic_push_try(pic_state *, struct pic_escape *);
|
||||
void pic_pop_try(pic_state *);
|
||||
|
||||
pic_value pic_raise_continuable(pic_state *, pic_value);
|
||||
|
|
Loading…
Reference in New Issue