continuation now can take more than 1 arguments

This commit is contained in:
Yuichi Nishiwaki 2014-02-02 12:11:15 +09:00
parent 7547b83515
commit 2373e7a067
3 changed files with 16 additions and 7 deletions

View File

@ -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 { \

View File

@ -4,6 +4,7 @@
#include <setjmp.h>
#include <string.h>
#include <stdarg.h>
#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;

View File

@ -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: {