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