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();
|
UNREACHABLE();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
void
|
||||||
pic_push_try(pic_state *pic)
|
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)) {
|
handler = pic_make_proc(pic, native_exception_handler, "(native-exception-handler)");
|
||||||
puts("escaping");
|
|
||||||
|
|
||||||
return false;
|
pic_attr_set(pic, handler, "@@escape", pic_obj_value(cont));
|
||||||
} else {
|
|
||||||
struct pic_proc *cont, *handler;
|
|
||||||
size_t xp_len, xp_offset;
|
|
||||||
|
|
||||||
cont = pic_make_econt(pic, escape);
|
if (pic->xp >= pic->xpend) {
|
||||||
|
xp_len = (pic->xpend - pic->xpbase) * 2;
|
||||||
handler = pic_make_proc(pic, native_exception_handler, "(native-exception-handler)");
|
xp_offset = pic->xp - pic->xpbase;
|
||||||
|
pic->xpbase = pic_realloc(pic, pic->xpbase, sizeof(struct pic_proc *) * xp_len);
|
||||||
pic_attr_set(pic, handler, "@@escape", pic_obj_value(cont));
|
pic->xp = pic->xpbase + xp_offset;
|
||||||
|
pic->xpend = pic->xpbase + xp_len;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*pic->xp++ = handler;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -137,8 +125,6 @@ pic_pop_try(pic_state *pic)
|
||||||
assert(pic_data_p(escape));
|
assert(pic_data_p(escape));
|
||||||
|
|
||||||
((struct pic_escape *)pic_data_ptr(escape)->data)->valid = false;
|
((struct pic_escape *)pic_data_ptr(escape)->data)->valid = false;
|
||||||
|
|
||||||
puts("pop_try done;");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct pic_error *
|
struct pic_error *
|
||||||
|
|
|
@ -9,6 +9,8 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "picrin/cont.h"
|
||||||
|
|
||||||
struct pic_error {
|
struct pic_error {
|
||||||
PIC_OBJECT_HEADER
|
PIC_OBJECT_HEADER
|
||||||
pic_sym type;
|
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! */
|
/* do not return from try block! */
|
||||||
|
|
||||||
#define pic_try \
|
#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
|
do
|
||||||
#define pic_catch \
|
#define pic_catch \
|
||||||
while (pic_pop_try(pic), 0); \
|
while (0); \
|
||||||
else
|
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 *);
|
void pic_pop_try(pic_state *);
|
||||||
|
|
||||||
pic_value pic_raise_continuable(pic_state *, pic_value);
|
pic_value pic_raise_continuable(pic_state *, pic_value);
|
||||||
|
|
Loading…
Reference in New Issue