pic_block -> pic_winder
This commit is contained in:
parent
06971a1144
commit
b4c3f4fb73
26
cont.c
26
cont.c
|
@ -121,7 +121,7 @@ save_cont(pic_state *pic, struct pic_cont **c)
|
||||||
|
|
||||||
cont = *c = (struct pic_cont *)pic_obj_alloc(pic, sizeof(struct pic_cont), PIC_TT_CONT);
|
cont = *c = (struct pic_cont *)pic_obj_alloc(pic, sizeof(struct pic_cont), PIC_TT_CONT);
|
||||||
|
|
||||||
cont->blk = pic->blk;
|
cont->wind = pic->wind;
|
||||||
|
|
||||||
cont->stk_len = native_stack_length(pic, &pos);
|
cont->stk_len = native_stack_length(pic, &pos);
|
||||||
cont->stk_pos = pos;
|
cont->stk_pos = pos;
|
||||||
|
@ -168,7 +168,6 @@ restore_cont(pic_state *pic, struct pic_cont *cont)
|
||||||
{
|
{
|
||||||
char v;
|
char v;
|
||||||
struct pic_cont *tmp = cont;
|
struct pic_cont *tmp = cont;
|
||||||
struct pic_block *blk;
|
|
||||||
|
|
||||||
if (&v < pic->native_stack_start) {
|
if (&v < pic->native_stack_start) {
|
||||||
if (&v > cont->stk_pos) native_stack_extend(pic, cont);
|
if (&v > cont->stk_pos) native_stack_extend(pic, cont);
|
||||||
|
@ -177,8 +176,7 @@ restore_cont(pic_state *pic, struct pic_cont *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);
|
||||||
}
|
}
|
||||||
|
|
||||||
blk = pic->blk;
|
pic->wind = cont->wind;
|
||||||
pic->blk = cont->blk;
|
|
||||||
|
|
||||||
pic->stbase = (pic_value *)pic_realloc(pic, pic->stbase, sizeof(pic_value) * cont->st_len);
|
pic->stbase = (pic_value *)pic_realloc(pic, pic->stbase, sizeof(pic_value) * cont->st_len);
|
||||||
memcpy(pic->stbase, cont->st_ptr, sizeof(pic_value) * cont->st_len);
|
memcpy(pic->stbase, cont->st_ptr, sizeof(pic_value) * cont->st_len);
|
||||||
|
@ -208,7 +206,7 @@ restore_cont(pic_state *pic, struct pic_cont *cont)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
walk_to_block(pic_state *pic, struct pic_block *here, struct pic_block *there)
|
walk_to_block(pic_state *pic, struct pic_winder *here, struct pic_winder *there)
|
||||||
{
|
{
|
||||||
if (here == there)
|
if (here == there)
|
||||||
return;
|
return;
|
||||||
|
@ -226,23 +224,23 @@ walk_to_block(pic_state *pic, struct pic_block *here, struct pic_block *there)
|
||||||
static pic_value
|
static pic_value
|
||||||
pic_dynamic_wind(pic_state *pic, struct pic_proc *in, struct pic_proc *thunk, struct pic_proc *out)
|
pic_dynamic_wind(pic_state *pic, struct pic_proc *in, struct pic_proc *thunk, struct pic_proc *out)
|
||||||
{
|
{
|
||||||
struct pic_block *here;
|
struct pic_winder *here;
|
||||||
pic_value val;
|
pic_value val;
|
||||||
|
|
||||||
if (in != NULL) {
|
if (in != NULL) {
|
||||||
pic_apply0(pic, in); /* enter */
|
pic_apply0(pic, in); /* enter */
|
||||||
}
|
}
|
||||||
|
|
||||||
here = pic->blk;
|
here = pic->wind;
|
||||||
pic->blk = (struct pic_block *)pic_obj_alloc(pic, sizeof(struct pic_block), PIC_TT_BLK);
|
pic->wind = pic_alloc(pic, sizeof(struct pic_winder));
|
||||||
pic->blk->prev = here;
|
pic->wind->prev = here;
|
||||||
pic->blk->depth = here->depth + 1;
|
pic->wind->depth = here->depth + 1;
|
||||||
pic->blk->in = in;
|
pic->wind->in = in;
|
||||||
pic->blk->out = out;
|
pic->wind->out = out;
|
||||||
|
|
||||||
val = pic_apply0(pic, thunk);
|
val = pic_apply0(pic, thunk);
|
||||||
|
|
||||||
pic->blk = here;
|
pic->wind = here;
|
||||||
|
|
||||||
if (out != NULL) {
|
if (out != NULL) {
|
||||||
pic_apply0(pic, out); /* exit */
|
pic_apply0(pic, out); /* exit */
|
||||||
|
@ -266,7 +264,7 @@ cont_call(pic_state *pic)
|
||||||
cont->results = pic_list_by_array(pic, argc, argv);
|
cont->results = pic_list_by_array(pic, argc, argv);
|
||||||
|
|
||||||
/* execute guard handlers */
|
/* execute guard handlers */
|
||||||
walk_to_block(pic, pic->blk, cont->blk);
|
walk_to_block(pic, pic->wind, cont->wind);
|
||||||
|
|
||||||
restore_cont(pic, cont);
|
restore_cont(pic, cont);
|
||||||
}
|
}
|
||||||
|
|
41
gc.c
41
gc.c
|
@ -333,6 +333,20 @@ gc_unmark(union header *p)
|
||||||
p->s.mark = PIC_GC_UNMARK;
|
p->s.mark = PIC_GC_UNMARK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gc_mark_winder(pic_state *pic, struct pic_winder *wind)
|
||||||
|
{
|
||||||
|
if (wind->prev) {
|
||||||
|
gc_mark_object(pic, (struct pic_object *)wind->prev);
|
||||||
|
}
|
||||||
|
if (wind->in) {
|
||||||
|
gc_mark_object(pic, (struct pic_object *)wind->in);
|
||||||
|
}
|
||||||
|
if (wind->out) {
|
||||||
|
gc_mark_object(pic, (struct pic_object *)wind->out);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gc_mark_object(pic_state *pic, struct pic_object *obj)
|
gc_mark_object(pic_state *pic, struct pic_object *obj)
|
||||||
{
|
{
|
||||||
|
@ -404,8 +418,8 @@ gc_mark_object(pic_state *pic, struct pic_object *obj)
|
||||||
pic_callinfo *ci;
|
pic_callinfo *ci;
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
/* block */
|
/* winder */
|
||||||
gc_mark_object(pic, (struct pic_object *)cont->blk);
|
gc_mark_winder(pic, cont->wind);
|
||||||
|
|
||||||
/* stack */
|
/* stack */
|
||||||
for (stack = cont->st_ptr; stack != cont->st_ptr + cont->sp_offset; ++stack) {
|
for (stack = cont->st_ptr; stack != cont->st_ptr + cont->sp_offset; ++stack) {
|
||||||
|
@ -504,20 +518,6 @@ gc_mark_object(pic_state *pic, struct pic_object *obj)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case PIC_TT_BLK: {
|
|
||||||
struct pic_block *blk = (struct pic_block *)obj;
|
|
||||||
|
|
||||||
if (blk->prev) {
|
|
||||||
gc_mark_object(pic, (struct pic_object *)blk->prev);
|
|
||||||
}
|
|
||||||
if (blk->in) {
|
|
||||||
gc_mark_object(pic, (struct pic_object *)blk->in);
|
|
||||||
}
|
|
||||||
if (blk->out) {
|
|
||||||
gc_mark_object(pic, (struct pic_object *)blk->out);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case PIC_TT_NIL:
|
case PIC_TT_NIL:
|
||||||
case PIC_TT_BOOL:
|
case PIC_TT_BOOL:
|
||||||
case PIC_TT_FLOAT:
|
case PIC_TT_FLOAT:
|
||||||
|
@ -565,9 +565,9 @@ gc_mark_phase(pic_state *pic)
|
||||||
size_t i, j;
|
size_t i, j;
|
||||||
xh_entry *it;
|
xh_entry *it;
|
||||||
|
|
||||||
/* block */
|
/* winder */
|
||||||
if (pic->blk) {
|
if (pic->wind) {
|
||||||
gc_mark_object(pic, (struct pic_object *)pic->blk);
|
gc_mark_winder(pic, pic->wind);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* stack */
|
/* stack */
|
||||||
|
@ -709,9 +709,6 @@ gc_finalize_object(pic_state *pic, struct pic_object *obj)
|
||||||
xh_destroy(&rec->hash);
|
xh_destroy(&rec->hash);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case PIC_TT_BLK: {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case PIC_TT_NIL:
|
case PIC_TT_NIL:
|
||||||
case PIC_TT_BOOL:
|
case PIC_TT_BOOL:
|
||||||
case PIC_TT_FLOAT:
|
case PIC_TT_FLOAT:
|
||||||
|
|
|
@ -46,6 +46,13 @@ extern "C" {
|
||||||
|
|
||||||
typedef struct pic_code pic_code;
|
typedef struct pic_code pic_code;
|
||||||
|
|
||||||
|
struct pic_winder {
|
||||||
|
struct pic_proc *in;
|
||||||
|
struct pic_proc *out;
|
||||||
|
int depth;
|
||||||
|
struct pic_winder *prev;
|
||||||
|
};
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int argc, retc;
|
int argc, retc;
|
||||||
pic_code *ip;
|
pic_code *ip;
|
||||||
|
@ -60,7 +67,7 @@ typedef struct {
|
||||||
int argc;
|
int argc;
|
||||||
char **argv, **envp;
|
char **argv, **envp;
|
||||||
|
|
||||||
struct pic_block *blk;
|
struct pic_winder *wind;
|
||||||
|
|
||||||
pic_value *sp;
|
pic_value *sp;
|
||||||
pic_value *stbase, *stend;
|
pic_value *stbase, *stend;
|
||||||
|
|
|
@ -9,18 +9,11 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct pic_block {
|
|
||||||
PIC_OBJECT_HEADER
|
|
||||||
struct pic_block *prev;
|
|
||||||
int depth;
|
|
||||||
struct pic_proc *in, *out;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct pic_cont {
|
struct pic_cont {
|
||||||
PIC_OBJECT_HEADER
|
PIC_OBJECT_HEADER
|
||||||
jmp_buf jmp;
|
jmp_buf jmp;
|
||||||
|
|
||||||
struct pic_block *blk;
|
struct pic_winder *wind;
|
||||||
|
|
||||||
char *stk_pos, *stk_ptr;
|
char *stk_pos, *stk_ptr;
|
||||||
ptrdiff_t stk_len;
|
ptrdiff_t stk_len;
|
||||||
|
|
|
@ -125,7 +125,6 @@ enum pic_tt {
|
||||||
PIC_TT_DATA,
|
PIC_TT_DATA,
|
||||||
PIC_TT_DICT,
|
PIC_TT_DICT,
|
||||||
PIC_TT_RECORD,
|
PIC_TT_RECORD,
|
||||||
PIC_TT_BLK,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#define PIC_OBJECT_HEADER \
|
#define PIC_OBJECT_HEADER \
|
||||||
|
@ -274,8 +273,6 @@ pic_type_repr(enum pic_tt tt)
|
||||||
return "dict";
|
return "dict";
|
||||||
case PIC_TT_RECORD:
|
case PIC_TT_RECORD:
|
||||||
return "record";
|
return "record";
|
||||||
case PIC_TT_BLK:
|
|
||||||
return "block";
|
|
||||||
}
|
}
|
||||||
UNREACHABLE();
|
UNREACHABLE();
|
||||||
}
|
}
|
||||||
|
|
18
state.c
18
state.c
|
@ -27,7 +27,7 @@ pic_open(int argc, char *argv[], char **envp)
|
||||||
pic = malloc(sizeof(pic_state));
|
pic = malloc(sizeof(pic_state));
|
||||||
|
|
||||||
/* root block */
|
/* root block */
|
||||||
pic->blk = NULL;
|
pic->wind = NULL;
|
||||||
|
|
||||||
/* command line */
|
/* command line */
|
||||||
pic->argc = argc;
|
pic->argc = argc;
|
||||||
|
@ -153,10 +153,10 @@ pic_open(int argc, char *argv[], char **envp)
|
||||||
pic_gc_arena_restore(pic, ai);
|
pic_gc_arena_restore(pic, ai);
|
||||||
|
|
||||||
/* root block */
|
/* root block */
|
||||||
pic->blk = (struct pic_block *)pic_obj_alloc(pic, sizeof(struct pic_block), PIC_TT_BLK);
|
pic->wind = pic_alloc(pic, sizeof(struct pic_winder));
|
||||||
pic->blk->prev = NULL;
|
pic->wind->prev = NULL;
|
||||||
pic->blk->depth = 0;
|
pic->wind->depth = 0;
|
||||||
pic->blk->in = pic->blk->out = NULL;
|
pic->wind->in = pic->wind->out = NULL;
|
||||||
|
|
||||||
/* init readers */
|
/* init readers */
|
||||||
pic_init_reader(pic);
|
pic_init_reader(pic);
|
||||||
|
@ -182,11 +182,11 @@ pic_close(pic_state *pic)
|
||||||
xh_entry *it;
|
xh_entry *it;
|
||||||
|
|
||||||
/* invoke exit handlers */
|
/* invoke exit handlers */
|
||||||
while (pic->blk) {
|
while (pic->wind) {
|
||||||
if (pic->blk->out) {
|
if (pic->wind->out) {
|
||||||
pic_apply0(pic, pic->blk->out);
|
pic_apply0(pic, pic->wind->out);
|
||||||
}
|
}
|
||||||
pic->blk = pic->blk->prev;
|
pic->wind = pic->wind->prev;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* clear out root objects */
|
/* clear out root objects */
|
||||||
|
|
Loading…
Reference in New Issue