remove struct pic_picjmp
This commit is contained in:
parent
8932dbddd6
commit
aae1b8792a
|
@ -3,7 +3,7 @@
|
|||
struct pic_fullcont {
|
||||
jmp_buf jmp;
|
||||
|
||||
pic_jmpbuf *prev_jmp;
|
||||
struct pic_cont *prev_jmp;
|
||||
|
||||
pic_checkpoint *cp;
|
||||
|
||||
|
@ -122,7 +122,7 @@ save_cont(pic_state *pic, struct pic_fullcont **c)
|
|||
|
||||
cont = *c = pic_malloc(pic, sizeof(struct pic_fullcont));
|
||||
|
||||
cont->prev_jmp = pic->jmp;
|
||||
cont->prev_jmp = pic->cc;
|
||||
|
||||
cont->cp = pic->cp;
|
||||
|
||||
|
@ -181,8 +181,7 @@ restore_cont(pic_state *pic, struct pic_fullcont *cont)
|
|||
if (&v > cont->stk_pos + cont->stk_len) native_stack_extend(pic, cont);
|
||||
}
|
||||
|
||||
pic->jmp = cont->prev_jmp;
|
||||
|
||||
pic->cc = cont->prev_jmp;
|
||||
pic->cp = cont->cp;
|
||||
|
||||
pic->stbase = pic_realloc(pic, pic->stbase, sizeof(pic_value) * cont->st_len);
|
||||
|
|
|
@ -51,9 +51,6 @@ pic_dynamic_wind(pic_state *pic, struct pic_proc *in, struct pic_proc *thunk, st
|
|||
void
|
||||
pic_save_point(pic_state *pic, struct pic_cont *cont)
|
||||
{
|
||||
cont->jmp.prev = pic->jmp;
|
||||
pic->jmp = &cont->jmp;
|
||||
|
||||
/* save runtime context */
|
||||
cont->cp = pic->cp;
|
||||
cont->sp_offset = pic->sp - pic->stbase;
|
||||
|
@ -62,21 +59,23 @@ pic_save_point(pic_state *pic, struct pic_cont *cont)
|
|||
cont->arena_idx = pic->arena_idx;
|
||||
cont->ip = pic->ip;
|
||||
cont->ptable = pic->ptable;
|
||||
|
||||
cont->prev = pic->cc;
|
||||
cont->results = pic_undef_value();
|
||||
|
||||
pic->cc = cont;
|
||||
}
|
||||
|
||||
void
|
||||
pic_load_point(pic_state *pic, struct pic_cont *cont)
|
||||
{
|
||||
pic_jmpbuf *jmp;
|
||||
struct pic_cont *cc;
|
||||
|
||||
for (jmp = pic->jmp; jmp != NULL; jmp = jmp->prev) {
|
||||
if (jmp == &cont->jmp) {
|
||||
for (cc = pic->cc; cc != NULL; cc = cc->prev) {
|
||||
if (cc == cont) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (jmp == NULL) {
|
||||
if (cc == NULL) {
|
||||
pic_errorf(pic, "calling dead escape continuation");
|
||||
}
|
||||
|
||||
|
@ -106,7 +105,7 @@ cont_call(pic_state *pic)
|
|||
|
||||
pic_load_point(pic, e->data);
|
||||
|
||||
PIC_LONGJMP(pic, ((struct pic_cont *)e->data)->jmp.buf, 1);
|
||||
PIC_LONGJMP(pic, ((struct pic_cont *)e->data)->jmp, 1);
|
||||
|
||||
PIC_UNREACHABLE();
|
||||
}
|
||||
|
@ -114,7 +113,7 @@ cont_call(pic_state *pic)
|
|||
struct pic_proc *
|
||||
pic_make_cont(pic_state *pic, struct pic_cont *cont)
|
||||
{
|
||||
static const pic_data_type cont_type = { "cont", pic_free, NULL };
|
||||
static const pic_data_type cont_type = { "cont", NULL, NULL };
|
||||
struct pic_proc *c;
|
||||
struct pic_data *e;
|
||||
|
||||
|
@ -131,21 +130,21 @@ pic_make_cont(pic_state *pic, struct pic_cont *cont)
|
|||
pic_value
|
||||
pic_callcc(pic_state *pic, struct pic_proc *proc)
|
||||
{
|
||||
struct pic_cont *cont = pic_malloc(pic, sizeof(struct pic_cont));
|
||||
struct pic_cont cont;
|
||||
|
||||
pic_save_point(pic, cont);
|
||||
pic_save_point(pic, &cont);
|
||||
|
||||
if (PIC_SETJMP(pic, cont->jmp.buf)) {
|
||||
pic->jmp = pic->jmp->prev;
|
||||
if (PIC_SETJMP(pic, cont.jmp)) {
|
||||
pic->cc = pic->cc->prev;
|
||||
|
||||
return pic_values_by_list(pic, cont->results);
|
||||
return pic_values_by_list(pic, cont.results);
|
||||
}
|
||||
else {
|
||||
pic_value val;
|
||||
|
||||
val = pic_apply1(pic, proc, pic_obj_value(pic_make_cont(pic, cont)));
|
||||
val = pic_apply1(pic, proc, pic_obj_value(pic_make_cont(pic, &cont)));
|
||||
|
||||
pic->jmp = pic->jmp->prev;
|
||||
pic->cc = pic->cc->prev;
|
||||
|
||||
return val;
|
||||
}
|
||||
|
|
|
@ -702,7 +702,9 @@ gc_finalize_object(pic_state *pic, struct pic_object *obj)
|
|||
}
|
||||
case PIC_TT_DATA: {
|
||||
struct pic_data *data = (struct pic_data *)obj;
|
||||
data->type->dtor(pic, data->data);
|
||||
if (data->type->dtor) {
|
||||
data->type->dtor(pic, data->data);
|
||||
}
|
||||
xh_destroy(&data->storage);
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -47,11 +47,6 @@ typedef struct pic_state pic_state;
|
|||
#include "picrin/read.h"
|
||||
#include "picrin/gc.h"
|
||||
|
||||
typedef struct pic_jmpbuf {
|
||||
PIC_JMPBUF buf;
|
||||
struct pic_jmpbuf *prev;
|
||||
} pic_jmpbuf;
|
||||
|
||||
typedef struct pic_checkpoint {
|
||||
PIC_OBJECT_HEADER
|
||||
struct pic_proc *in;
|
||||
|
@ -78,7 +73,7 @@ struct pic_state {
|
|||
|
||||
pic_allocf allocf;
|
||||
|
||||
pic_jmpbuf *jmp;
|
||||
struct pic_cont *cc;
|
||||
pic_checkpoint *cp;
|
||||
|
||||
pic_value *sp;
|
||||
|
|
|
@ -10,7 +10,7 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
struct pic_cont {
|
||||
pic_jmpbuf jmp;
|
||||
PIC_JMPBUF jmp;
|
||||
|
||||
pic_checkpoint *cp;
|
||||
|
||||
|
@ -18,12 +18,13 @@ struct pic_cont {
|
|||
ptrdiff_t ci_offset;
|
||||
ptrdiff_t xp_offset;
|
||||
size_t arena_idx;
|
||||
pic_value ptable;
|
||||
|
||||
pic_code *ip;
|
||||
|
||||
pic_value ptable;
|
||||
|
||||
pic_value results;
|
||||
|
||||
struct pic_cont *prev;
|
||||
};
|
||||
|
||||
void pic_save_point(pic_state *, struct pic_cont *);
|
||||
|
|
|
@ -30,21 +30,21 @@ struct pic_error *pic_make_error(pic_state *, pic_sym *, const char *, pic_list)
|
|||
pic_catch_(PIC_GENSYM(label))
|
||||
#define pic_try_(cont, handler) \
|
||||
do { \
|
||||
struct pic_cont *cont = pic_malloc(pic, sizeof(struct pic_cont)); \
|
||||
pic_save_point(pic, cont); \
|
||||
if (PIC_SETJMP(pic, cont->jmp.buf) == 0) { \
|
||||
struct pic_cont cont; \
|
||||
pic_save_point(pic, &cont); \
|
||||
if (PIC_SETJMP(pic, cont.jmp) == 0) { \
|
||||
extern pic_value pic_native_exception_handler(pic_state *); \
|
||||
struct pic_proc *handler; \
|
||||
handler = pic_make_proc(pic, pic_native_exception_handler, "(native-exception-handler)"); \
|
||||
pic_proc_env_set(pic, handler, "cont", pic_obj_value(pic_make_cont(pic, cont))); \
|
||||
pic_proc_env_set(pic, handler, "cont", pic_obj_value(pic_make_cont(pic, &cont))); \
|
||||
do { \
|
||||
pic_push_handler(pic, handler);
|
||||
#define pic_catch_(label) \
|
||||
pic_pop_handler(pic); \
|
||||
pic_pop_handler(pic); \
|
||||
} while (0); \
|
||||
pic->jmp = pic->jmp->prev; \
|
||||
pic->cc = pic->cc->prev; \
|
||||
} else { \
|
||||
pic->jmp = pic->jmp->prev; \
|
||||
pic->cc = pic->cc->prev; \
|
||||
goto label; \
|
||||
} \
|
||||
} while (0); \
|
||||
|
|
|
@ -172,8 +172,8 @@ pic_open(int argc, char *argv[], char **envp, pic_allocf allocf)
|
|||
/* turn off GC */
|
||||
pic->gc_enable = false;
|
||||
|
||||
/* jmp */
|
||||
pic->jmp = NULL;
|
||||
/* continuation chain */
|
||||
pic->cc = NULL;
|
||||
|
||||
/* root block */
|
||||
pic->cp = NULL;
|
||||
|
|
Loading…
Reference in New Issue