From 07f24db66f02c3e7e138dc323111fc5bde985567 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Wed, 24 Sep 2014 14:57:49 +0900 Subject: [PATCH] add make_escape --- cont.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/cont.c b/cont.c index 496503cc..1066dd89 100644 --- a/cont.c +++ b/cont.c @@ -109,10 +109,26 @@ escape_call(pic_state *pic) load_point(pic, e->data); } +static struct pic_proc * +make_escape(pic_state *pic, struct pic_escape *escape) +{ + static const pic_data_type escape_type = { "escape", pic_free, NULL }; + struct pic_proc *cont; + struct pic_data *e; + + cont = pic_make_proc(pic, escape_call, ""); + + e = pic_data_alloc(pic, &escape_type, escape); + + /* save the escape continuation in proc */ + pic_attr_set(pic, cont, "@@escape", pic_obj_value(e)); + + return cont; +} + pic_value pic_escape(pic_state *pic, struct pic_proc *proc) { - static const pic_data_type escape_type = { "escape", pic_free, NULL }; struct pic_escape *escape; escape = pic_alloc(pic, sizeof(struct pic_escape)); @@ -121,18 +137,9 @@ pic_escape(pic_state *pic, struct pic_proc *proc) return pic_values_by_list(pic, escape->results); } else { - struct pic_proc *c; pic_value val; - struct pic_data *e; - c = pic_make_proc(pic, escape_call, ""); - - e = pic_data_alloc(pic, &escape_type, escape); - - /* save the escape continuation in proc */ - pic_attr_set(pic, c, "@@escape", pic_obj_value(e)); - - val = pic_apply1(pic, proc, pic_obj_value(c)); + val = pic_apply1(pic, proc, pic_obj_value(make_escape(pic, escape))); escape->valid = false;