don't allocate on continuation call

This commit is contained in:
Yuichi Nishiwaki 2016-02-19 17:58:42 +09:00
parent b070d9c1dc
commit 03fed95b32
4 changed files with 17 additions and 14 deletions

View File

@ -17,7 +17,8 @@ pic_save_point(pic_state *pic, struct pic_cont *cont)
cont->ip = pic->ip;
cont->ptable = pic->ptable;
cont->prev = pic->cc;
cont->results = pic_make_vec(pic, 0, NULL);
cont->retc = 0;
cont->retv = NULL;
cont->id = pic->ccnt++;
pic->cc = cont;
@ -109,7 +110,8 @@ cont_call(pic_state *pic)
}
cont = pic_data_ptr(pic_closure_ref(pic, CV_ESCAPE))->data;
cont->results = pic_make_vec(pic, argc, argv);
cont->retc = argc;
cont->retv = argv;
pic_load_point(pic, cont);
@ -138,7 +140,7 @@ pic_callcc(pic_state *pic, struct pic_proc *proc)
pic_save_point(pic, &cont);
if (PIC_SETJMP(pic, cont.jmp)) {
return pic_valuesk(pic, cont.results->len, cont.results->data);
return pic_valuesk(pic, cont.retc, cont.retv);
}
else {
pic_value val;
@ -239,19 +241,19 @@ static pic_value
pic_cont_call_with_values(pic_state *pic)
{
struct pic_proc *producer, *consumer;
int argc;
pic_vec *args;
int retc;
pic_value *retv;
pic_get_args(pic, "ll", &producer, &consumer);
pic_call(pic, producer, 0);
argc = pic_receive(pic, 0, NULL);
args = pic_make_vec(pic, argc, NULL);
retc = pic_receive(pic, 0, NULL);
retv = pic_alloca(pic, sizeof(pic_value) * retc);
pic_receive(pic, argc, args->data);
pic_receive(pic, retc, retv);
return pic_applyk(pic, consumer, argc, args->data);
return pic_applyk(pic, consumer, retc, retv);
}
void

View File

@ -297,10 +297,6 @@ void pic_close_port(pic_state *, struct pic_port *port);
pic_leave(pic, ai); \
} while (0)
pic_sym *pic_add_identifier(pic_state *, pic_id *, struct pic_env *);
pic_sym *pic_put_identifier(pic_state *, pic_id *, pic_sym *, struct pic_env *);
pic_sym *pic_find_identifier(pic_state *, pic_id *, struct pic_env *);
pic_value pic_read(pic_state *, struct pic_port *);
pic_value pic_read_cstr(pic_state *, const char *);

View File

@ -22,7 +22,8 @@ struct pic_cont {
pic_value ptable;
pic_code *ip;
pic_vec *results;
int retc;
pic_value *retv;
struct pic_cont *prev;
};

View File

@ -36,6 +36,10 @@ struct pic_id {
pic_id *pic_make_identifier(pic_state *, pic_id *, struct pic_env *);
pic_sym *pic_add_identifier(pic_state *, pic_id *, struct pic_env *);
pic_sym *pic_put_identifier(pic_state *, pic_id *, pic_sym *, struct pic_env *);
pic_sym *pic_find_identifier(pic_state *, pic_id *, struct pic_env *);
struct pic_string *pic_id_name(pic_state *, pic_id *);