From 03fed95b320068f0df5bab43097f9b6f5c12da98 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Fri, 19 Feb 2016 17:58:42 +0900 Subject: [PATCH] don't allocate on continuation call --- extlib/benz/cont.c | 20 +++++++++++--------- extlib/benz/include/picrin.h | 4 ---- extlib/benz/include/picrin/cont.h | 3 ++- extlib/benz/include/picrin/object.h | 4 ++++ 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/extlib/benz/cont.c b/extlib/benz/cont.c index 9eeb20bf..f47347b6 100644 --- a/extlib/benz/cont.c +++ b/extlib/benz/cont.c @@ -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 diff --git a/extlib/benz/include/picrin.h b/extlib/benz/include/picrin.h index 907bd3dc..94600879 100644 --- a/extlib/benz/include/picrin.h +++ b/extlib/benz/include/picrin.h @@ -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 *); diff --git a/extlib/benz/include/picrin/cont.h b/extlib/benz/include/picrin/cont.h index 6b6edcf0..4e6649bf 100644 --- a/extlib/benz/include/picrin/cont.h +++ b/extlib/benz/include/picrin/cont.h @@ -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; }; diff --git a/extlib/benz/include/picrin/object.h b/extlib/benz/include/picrin/object.h index 0a3310bd..2335cd59 100644 --- a/extlib/benz/include/picrin/object.h +++ b/extlib/benz/include/picrin/object.h @@ -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 *);