don't setjmp in pic_push_try

This commit is contained in:
Yuichi Nishiwaki 2014-09-24 20:21:28 +09:00
parent eb1e01d000
commit d6c6427ff7
2 changed files with 28 additions and 34 deletions

18
error.c
View File

@ -86,18 +86,9 @@ 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));
pic_save_point(pic, escape);
if (setjmp(escape->jmp)) {
puts("escaping");
return false;
} else {
struct pic_proc *cont, *handler;
size_t xp_len, xp_offset;
@ -116,9 +107,6 @@ pic_push_try(pic_state *pic)
}
*pic->xp++ = handler;
return true;
}
}
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 *

View File

@ -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
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);