From 2373e7a06708058fbbef6654d5c6fcee9ff45ea6 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Sun, 2 Feb 2014 12:11:15 +0900 Subject: [PATCH] continuation now can take more than 1 arguments --- include/picrin/cont.h | 3 ++- src/cont.c | 15 ++++++++++----- src/gc.c | 5 ++++- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/include/picrin/cont.h b/include/picrin/cont.h index ddd104af..25f12f46 100644 --- a/include/picrin/cont.h +++ b/include/picrin/cont.h @@ -30,7 +30,8 @@ struct pic_cont { struct pic_object *arena[PIC_ARENA_SIZE]; int arena_idx; - pic_value result; + size_t argc; + pic_value *argv; }; #define PIC_BLK_INCREF(pic,blk) do { \ diff --git a/src/cont.c b/src/cont.c index f7157fe8..db8bc3e7 100644 --- a/src/cont.c +++ b/src/cont.c @@ -4,6 +4,7 @@ #include #include +#include #include "picrin.h" #include "picrin/proc.h" @@ -60,7 +61,8 @@ save_cont(pic_state *pic, struct pic_cont **c) cont->arena_idx = pic->arena_idx; memcpy(cont->arena, pic->arena, sizeof(struct pic_object *) * PIC_ARENA_SIZE); - cont->result = pic_undef_value(); + cont->argc = 0; + cont->argv = NULL; } static void @@ -132,14 +134,16 @@ NORETURN static pic_value cont_call(pic_state *pic) { struct pic_proc *proc; - pic_value v; + size_t argc; + pic_value *argv; struct pic_cont *cont; proc = pic_get_proc(pic); - pic_get_args(pic, "o", &v); + pic_get_args(pic, "*", &argc, &argv); cont = (struct pic_cont *)pic_ptr(proc->env->values[0]); - cont->result = v; + cont->argc = argc; + cont->argv = argv; /* execute guard handlers */ walk_to_block(pic, pic->blk, cont->blk); @@ -154,7 +158,8 @@ pic_callcc(pic_state *pic, struct pic_proc *proc) save_cont(pic, &cont); if (setjmp(cont->jmp)) { - return cont->result; + printf("%d\n", cont->argc); + return pic_values_from_array(pic, cont->argc, cont->argv); } else { struct pic_proc *c; diff --git a/src/gc.c b/src/gc.c index 1b61d4f1..f37e045b 100644 --- a/src/gc.c +++ b/src/gc.c @@ -385,7 +385,10 @@ gc_mark_object(pic_state *pic, struct pic_object *obj) gc_mark_object(pic, cont->arena[j]); } - gc_mark(pic, cont->result); + /* result values */ + for (i = 0; i < cont->argc; ++i) { + gc_mark(pic, cont->argv[i]); + } break; } case PIC_TT_SYNTAX: {