execute procedure by trampoline in call/cc

This commit is contained in:
Yuichi Nishiwaki 2014-02-07 09:56:57 +09:00
parent 67a856b1db
commit 1208fc9f0e
1 changed files with 23 additions and 1 deletions

View File

@ -237,6 +237,28 @@ pic_receive(pic_state *pic, size_t n, pic_value *argv)
return i; return i;
} }
static pic_value
pic_callcc_trampoline(pic_state *pic, struct pic_proc *proc)
{
struct pic_cont *cont;
save_cont(pic, &cont);
if (setjmp(cont->jmp)) {
return pic_values_by_list(pic, cont->results);
}
else {
struct pic_proc *c;
c = pic_proc_new(pic, cont_call);
/* save the continuation object in proc */
pic_proc_cv_init(pic, c, 1);
pic_proc_cv_set(pic, c, 0, pic_obj_value(cont));
return pic_trampoline(pic, proc, pic_list(pic, 1, pic_obj_value(c)));
}
}
static pic_value static pic_value
pic_cont_callcc(pic_state *pic) pic_cont_callcc(pic_state *pic)
{ {
@ -244,7 +266,7 @@ pic_cont_callcc(pic_state *pic)
pic_get_args(pic, "l", &cb); pic_get_args(pic, "l", &cb);
return pic_callcc(pic, cb); return pic_callcc_trampoline(pic, cb);
} }
static pic_value static pic_value