continuation now can take more than 1 arguments
This commit is contained in:
parent
7547b83515
commit
2373e7a067
|
@ -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 { \
|
||||
|
|
15
src/cont.c
15
src/cont.c
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue