From acb513aa166bf6bc7f1fd5bb8e31d2094dc3e44e Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Sat, 18 Jan 2014 16:08:07 +0900 Subject: [PATCH] publish pic_callcc --- include/picrin/cont.h | 2 ++ src/cont.c | 19 +++++++++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/include/picrin/cont.h b/include/picrin/cont.h index 27a8df45..7c888bce 100644 --- a/include/picrin/cont.h +++ b/include/picrin/cont.h @@ -50,6 +50,8 @@ struct pic_cont { } \ } while (0) +pic_value pic_callcc(pic_state *, struct pic_proc *); + #if defined(__cplusplus) } #endif diff --git a/src/cont.c b/src/cont.c index a4be2e6c..d42753fb 100644 --- a/src/cont.c +++ b/src/cont.c @@ -150,13 +150,10 @@ cont_call(pic_state *pic) return pic_undef_value(); } -static pic_value -pic_cont_callcc(pic_state *pic) +pic_value +pic_callcc(pic_state *pic, struct pic_proc *proc) { struct pic_cont *cont; - struct pic_proc *cb; - - pic_get_args(pic, "l", &cb); save_cont(pic, &cont); if (setjmp(cont->jmp)) { @@ -171,10 +168,20 @@ pic_cont_callcc(pic_state *pic) pic_proc_cv_init(pic, c, 1); pic_proc_cv_set(pic, c, 0, pic_obj_value(cont)); - return pic_apply_argv(pic, cb, 1, pic_obj_value(c)); + return pic_apply_argv(pic, proc, 1, pic_obj_value(c)); } } +static pic_value +pic_cont_callcc(pic_state *pic) +{ + struct pic_proc *cb; + + pic_get_args(pic, "l", &cb); + + return pic_callcc(pic, cb); +} + static pic_value pic_cont_dynamic_wind(pic_state *pic) {