From 6d2966e9463cc020de7ff586588249b02f24af4b Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Mon, 29 Jun 2015 04:25:47 +0900 Subject: [PATCH] don't cons in pic_valuesN --- extlib/benz/cont.c | 34 +++++++++++++++++++++++-------- extlib/benz/include/picrin/cont.h | 2 +- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/extlib/benz/cont.c b/extlib/benz/cont.c index fe9947a3..85394f7d 100644 --- a/extlib/benz/cont.c +++ b/extlib/benz/cont.c @@ -155,44 +155,62 @@ pic_callcc(pic_state *pic, struct pic_proc *proc) } } +static pic_value +pic_va_values(pic_state *pic, size_t n, ...) +{ + pic_value args[n]; + va_list ap; + size_t i = 0; + + va_start(ap, n); + + while (i < n) { + args[i++] = va_arg(ap, pic_value); + } + + va_end(ap); + + return pic_values(pic, n, args); +} + pic_value pic_values0(pic_state *pic) { - return pic_values_by_list(pic, pic_nil_value()); + return pic_va_values(pic, 0); } pic_value pic_values1(pic_state *pic, pic_value arg1) { - return pic_values_by_list(pic, pic_list1(pic, arg1)); + return pic_va_values(pic, 1, arg1); } pic_value pic_values2(pic_state *pic, pic_value arg1, pic_value arg2) { - return pic_values_by_list(pic, pic_list2(pic, arg1, arg2)); + return pic_va_values(pic, 2, arg1, arg2); } pic_value pic_values3(pic_state *pic, pic_value arg1, pic_value arg2, pic_value arg3) { - return pic_values_by_list(pic, pic_list3(pic, arg1, arg2, arg3)); + return pic_va_values(pic, 3, arg1, arg2, arg3); } pic_value pic_values4(pic_state *pic, pic_value arg1, pic_value arg2, pic_value arg3, pic_value arg4) { - return pic_values_by_list(pic, pic_list4(pic, arg1, arg2, arg3, arg4)); + return pic_va_values(pic, 4, arg1, arg2, arg3, arg4); } pic_value pic_values5(pic_state *pic, pic_value arg1, pic_value arg2, pic_value arg3, pic_value arg4, pic_value arg5) { - return pic_values_by_list(pic, pic_list5(pic, arg1, arg2, arg3, arg4, arg5)); + return pic_va_values(pic, 5, arg1, arg2, arg3, arg4, arg5); } pic_value -pic_values_by_array(pic_state *pic, size_t argc, pic_value *argv) +pic_values(pic_state *pic, size_t argc, pic_value *argv) { size_t i; @@ -264,7 +282,7 @@ pic_cont_values(pic_state *pic) pic_get_args(pic, "*", &argc, &argv); - return pic_values_by_array(pic, argc, argv); + return pic_values(pic, argc, argv); } static pic_value diff --git a/extlib/benz/include/picrin/cont.h b/extlib/benz/include/picrin/cont.h index 439f6aeb..c701ec55 100644 --- a/extlib/benz/include/picrin/cont.h +++ b/extlib/benz/include/picrin/cont.h @@ -41,7 +41,7 @@ pic_value pic_values2(pic_state *, pic_value, pic_value); pic_value pic_values3(pic_state *, pic_value, pic_value, pic_value); pic_value pic_values4(pic_state *, pic_value, pic_value, pic_value, pic_value); pic_value pic_values5(pic_state *, pic_value, pic_value, pic_value, pic_value, pic_value); -pic_value pic_values_by_array(pic_state *, size_t, pic_value *); +pic_value pic_values(pic_state *, size_t, pic_value *); pic_value pic_values_by_list(pic_state *, pic_value); size_t pic_receive(pic_state *, size_t, pic_value *);