From 7547b8351534b3f6a8da2bae3f9c33780f529878 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Sun, 2 Feb 2014 12:10:31 +0900 Subject: [PATCH] add pic_values functions --- include/picrin/cont.h | 2 ++ src/cont.c | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/include/picrin/cont.h b/include/picrin/cont.h index 2cb82f16..ddd104af 100644 --- a/include/picrin/cont.h +++ b/include/picrin/cont.h @@ -51,6 +51,8 @@ struct pic_cont { } while (0) pic_value pic_callcc(pic_state *, struct pic_proc *); +pic_value pic_values(pic_state *, size_t, ...); +pic_value pic_values_from_array(pic_state *, size_t, pic_value *); #if defined(__cplusplus) } diff --git a/src/cont.c b/src/cont.c index 34b053c2..f7157fe8 100644 --- a/src/cont.c +++ b/src/cont.c @@ -169,6 +169,45 @@ pic_callcc(pic_state *pic, struct pic_proc *proc) } } +pic_value +pic_values(pic_state *pic, size_t c, ...) +{ + va_list ap; + size_t i; + pic_value head = pic_none_value(); + + va_start(ap, c); + + for (i = 0; i < c; ++i) { + pic->ci->fp[i] = va_arg(ap, pic_value); + if (i == 0) { + head = pic->ci->fp[0]; + } + } + pic->ci->fp[i] = pic_undef_value(); + + va_end(ap); + + return head; +} + +pic_value +pic_values_from_array(pic_state *pic, size_t argc, pic_value *argv) +{ + size_t i; + pic_value head = pic_none_value(); + + for (i = 0; i < argc; ++i) { + pic->ci->fp[i] = argv[i]; + if (i == 0) { + head = pic->ci->fp[0]; + } + } + pic->ci->fp[i] = pic_undef_value(); + + return head; +} + static pic_value pic_cont_callcc(pic_state *pic) {