From e38732995e14bd7e89f12a8a3a830213934f06e1 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Wed, 24 Sep 2014 15:34:46 +0900 Subject: [PATCH] publish continuation internal APIs --- cont.c | 18 +++++++++--------- include/picrin/cont.h | 5 +++++ 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/cont.c b/cont.c index bc1a6c17..2c109c67 100644 --- a/cont.c +++ b/cont.c @@ -57,8 +57,8 @@ pic_dynamic_wind(pic_state *pic, struct pic_proc *in, struct pic_proc *thunk, st return val; } -static int -save_point(pic_state *pic, struct pic_escape *escape) +int +pic_save_point(pic_state *pic, struct pic_escape *escape) { escape->valid = true; @@ -75,8 +75,8 @@ save_point(pic_state *pic, struct pic_escape *escape) return setjmp(escape->jmp); } -noreturn static void -load_point(pic_state *pic, struct pic_escape *escape) +noreturn void +pic_load_point(pic_state *pic, struct pic_escape *escape) { if (! escape->valid) { pic_errorf(pic, "calling dead escape continuation"); @@ -108,11 +108,11 @@ escape_call(pic_state *pic) e = pic_data_ptr(pic_attr_ref(pic, pic_get_proc(pic), "@@escape")); - load_point(pic, e->data); + pic_load_point(pic, e->data); } -static struct pic_proc * -make_escape(pic_state *pic, struct pic_escape *escape) +struct pic_proc * +pic_make_cont(pic_state *pic, struct pic_escape *escape) { static const pic_data_type escape_type = { "escape", pic_free, NULL }; struct pic_proc *cont; @@ -135,13 +135,13 @@ pic_escape(pic_state *pic, struct pic_proc *proc) escape = pic_alloc(pic, sizeof(struct pic_escape)); - if (save_point(pic, escape)) { + if (pic_save_point(pic, escape)) { return pic_values_by_list(pic, escape->results); } else { pic_value val; - val = pic_apply1(pic, proc, pic_obj_value(make_escape(pic, escape))); + val = pic_apply1(pic, proc, pic_obj_value(pic_make_cont(pic, escape))); escape->valid = false; diff --git a/include/picrin/cont.h b/include/picrin/cont.h index f49d6595..6fd6fda8 100644 --- a/include/picrin/cont.h +++ b/include/picrin/cont.h @@ -26,6 +26,11 @@ struct pic_escape { pic_value results; }; +int pic_save_point(pic_state *, struct pic_escape *); +noreturn void pic_load_point(pic_state *, struct pic_escape *); + +struct pic_proc *pic_make_cont(pic_state *, struct pic_escape *); + void pic_wind(pic_state *, struct pic_winder *, struct pic_winder *); pic_value pic_dynamic_wind(pic_state *, struct pic_proc *, struct pic_proc *, struct pic_proc *);