From 116a65cdee3b5ac3c95e021f8877c044672384c0 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Sun, 2 Feb 2014 12:38:46 +0900 Subject: [PATCH] add pic_receive --- include/picrin/cont.h | 1 + src/cont.c | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/include/picrin/cont.h b/include/picrin/cont.h index c08a2830..e846b7de 100644 --- a/include/picrin/cont.h +++ b/include/picrin/cont.h @@ -54,6 +54,7 @@ pic_value pic_callcc(pic_state *, struct pic_proc *); pic_value pic_values(pic_state *, size_t, ...); pic_value pic_values_by_array(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 *); #if defined(__cplusplus) } diff --git a/src/cont.c b/src/cont.c index 2da3fd3d..a113f01e 100644 --- a/src/cont.c +++ b/src/cont.c @@ -218,6 +218,21 @@ pic_values_by_list(pic_state *pic, pic_value list) return pic_nil_p(list) ? pic_none_value() : pic->ci->fp[0]; } +size_t +pic_receive(pic_state *pic, size_t n, pic_value *argv) +{ + size_t i; + + for (i = 0; ; ++i) { + if (pic_undef_p(pic->ci->fp[i])) + break; + if (i < n) { + argv[i] = pic->ci->fp[i]; + } + } + return i; +} + static pic_value pic_cont_callcc(pic_state *pic) {