rename functions related to continuation
This commit is contained in:
parent
02f0d00578
commit
5df4e4f64e
|
@ -1,6 +1,6 @@
|
|||
#include "picrin.h"
|
||||
|
||||
struct pic_cont {
|
||||
struct pic_fullcont {
|
||||
jmp_buf jmp;
|
||||
|
||||
pic_jmpbuf *prev_jmp;
|
||||
|
@ -31,7 +31,7 @@ struct pic_cont {
|
|||
static void
|
||||
cont_dtor(pic_state *pic, void *data)
|
||||
{
|
||||
struct pic_cont *cont = data;
|
||||
struct pic_fullcont *cont = data;
|
||||
|
||||
pic_free(pic, cont->stk_ptr);
|
||||
pic_free(pic, cont->st_ptr);
|
||||
|
@ -44,7 +44,7 @@ cont_dtor(pic_state *pic, void *data)
|
|||
static void
|
||||
cont_mark(pic_state *pic, void *data, void (*mark)(pic_state *, pic_value))
|
||||
{
|
||||
struct pic_cont *cont = data;
|
||||
struct pic_fullcont *cont = data;
|
||||
struct pic_winder *wind;
|
||||
pic_value *stack;
|
||||
pic_callinfo *ci;
|
||||
|
@ -89,8 +89,8 @@ cont_mark(pic_state *pic, void *data, void (*mark)(pic_state *, pic_value))
|
|||
|
||||
static const pic_data_type cont_type = { "continuation", cont_dtor, cont_mark };
|
||||
|
||||
static void save_cont(pic_state *, struct pic_cont **);
|
||||
static void restore_cont(pic_state *, struct pic_cont *);
|
||||
static void save_cont(pic_state *, struct pic_fullcont **);
|
||||
static void restore_cont(pic_state *, struct pic_fullcont *);
|
||||
|
||||
static ptrdiff_t
|
||||
native_stack_length(pic_state *pic, char **pos)
|
||||
|
@ -107,15 +107,15 @@ native_stack_length(pic_state *pic, char **pos)
|
|||
}
|
||||
|
||||
static void
|
||||
save_cont(pic_state *pic, struct pic_cont **c)
|
||||
save_cont(pic_state *pic, struct pic_fullcont **c)
|
||||
{
|
||||
void pic_vm_tear_off(pic_state *);
|
||||
struct pic_cont *cont;
|
||||
struct pic_fullcont *cont;
|
||||
char *pos;
|
||||
|
||||
pic_vm_tear_off(pic); /* tear off */
|
||||
|
||||
cont = *c = pic_malloc(pic, sizeof(struct pic_cont));
|
||||
cont = *c = pic_malloc(pic, sizeof(struct pic_fullcont));
|
||||
|
||||
cont->prev_jmp = pic->jmp;
|
||||
|
||||
|
@ -153,7 +153,7 @@ save_cont(pic_state *pic, struct pic_cont **c)
|
|||
}
|
||||
|
||||
static void
|
||||
native_stack_extend(pic_state *pic, struct pic_cont *cont)
|
||||
native_stack_extend(pic_state *pic, struct pic_fullcont *cont)
|
||||
{
|
||||
volatile pic_value v[1024];
|
||||
|
||||
|
@ -162,10 +162,10 @@ native_stack_extend(pic_state *pic, struct pic_cont *cont)
|
|||
}
|
||||
|
||||
PIC_NORETURN static void
|
||||
restore_cont(pic_state *pic, struct pic_cont *cont)
|
||||
restore_cont(pic_state *pic, struct pic_fullcont *cont)
|
||||
{
|
||||
char v;
|
||||
struct pic_cont *tmp = cont;
|
||||
struct pic_fullcont *tmp = cont;
|
||||
|
||||
if (&v < pic->native_stack_start) {
|
||||
if (&v > cont->stk_pos) native_stack_extend(pic, cont);
|
||||
|
@ -211,7 +211,7 @@ cont_call(pic_state *pic)
|
|||
struct pic_proc *proc;
|
||||
size_t argc;
|
||||
pic_value *argv;
|
||||
struct pic_cont *cont;
|
||||
struct pic_fullcont *cont;
|
||||
|
||||
proc = pic_get_proc(pic);
|
||||
pic_get_args(pic, "*", &argc, &argv);
|
||||
|
@ -226,9 +226,9 @@ cont_call(pic_state *pic)
|
|||
}
|
||||
|
||||
pic_value
|
||||
pic_callcc(pic_state *pic, struct pic_proc *proc)
|
||||
pic_callcc_full(pic_state *pic, struct pic_proc *proc)
|
||||
{
|
||||
struct pic_cont *cont;
|
||||
struct pic_fullcont *cont;
|
||||
|
||||
save_cont(pic, &cont);
|
||||
if (setjmp(cont->jmp)) {
|
||||
|
@ -250,9 +250,9 @@ pic_callcc(pic_state *pic, struct pic_proc *proc)
|
|||
}
|
||||
|
||||
static pic_value
|
||||
pic_callcc_trampoline(pic_state *pic, struct pic_proc *proc)
|
||||
pic_callcc_full_trampoline(pic_state *pic, struct pic_proc *proc)
|
||||
{
|
||||
struct pic_cont *cont;
|
||||
struct pic_fullcont *cont;
|
||||
|
||||
save_cont(pic, &cont);
|
||||
if (setjmp(cont->jmp)) {
|
||||
|
@ -280,7 +280,7 @@ pic_callcc_callcc(pic_state *pic)
|
|||
|
||||
pic_get_args(pic, "l", &cb);
|
||||
|
||||
return pic_callcc_trampoline(pic, cb);
|
||||
return pic_callcc_full_trampoline(pic, cb);
|
||||
}
|
||||
|
||||
#define pic_redefun(pic, lib, name, func) \
|
||||
|
|
|
@ -49,7 +49,7 @@ pic_dynamic_wind(pic_state *pic, struct pic_proc *in, struct pic_proc *thunk, st
|
|||
}
|
||||
|
||||
void
|
||||
pic_save_point(pic_state *pic, struct pic_escape *escape)
|
||||
pic_save_point(pic_state *pic, struct pic_cont *escape)
|
||||
{
|
||||
escape->jmp.prev = pic->jmp;
|
||||
pic->jmp = &escape->jmp;
|
||||
|
@ -66,7 +66,7 @@ pic_save_point(pic_state *pic, struct pic_escape *escape)
|
|||
}
|
||||
|
||||
void
|
||||
pic_load_point(pic_state *pic, struct pic_escape *escape)
|
||||
pic_load_point(pic_state *pic, struct pic_cont *escape)
|
||||
{
|
||||
pic_jmpbuf *jmp;
|
||||
|
||||
|
@ -100,17 +100,17 @@ escape_call(pic_state *pic)
|
|||
pic_get_args(pic, "*", &argc, &argv);
|
||||
|
||||
e = pic_data_ptr(pic_attr_ref(pic, pic_obj_value(pic_get_proc(pic)), "@@escape"));
|
||||
((struct pic_escape *)e->data)->results = pic_list_by_array(pic, argc, argv);
|
||||
((struct pic_cont *)e->data)->results = pic_list_by_array(pic, argc, argv);
|
||||
|
||||
pic_load_point(pic, e->data);
|
||||
|
||||
PIC_LONGJMP(pic, (void *)((struct pic_escape *)e->data)->jmp.buf, 1);
|
||||
PIC_LONGJMP(pic, ((struct pic_cont *)e->data)->jmp.buf, 1);
|
||||
|
||||
PIC_UNREACHABLE();
|
||||
}
|
||||
|
||||
struct pic_proc *
|
||||
pic_make_econt(pic_state *pic, struct pic_escape *escape)
|
||||
pic_make_cont(pic_state *pic, struct pic_cont *escape)
|
||||
{
|
||||
static const pic_data_type escape_type = { "escape", pic_free, NULL };
|
||||
struct pic_proc *cont;
|
||||
|
@ -127,13 +127,13 @@ pic_make_econt(pic_state *pic, struct pic_escape *escape)
|
|||
}
|
||||
|
||||
pic_value
|
||||
pic_escape(pic_state *pic, struct pic_proc *proc)
|
||||
pic_callcc(pic_state *pic, struct pic_proc *proc)
|
||||
{
|
||||
struct pic_escape *escape = pic_malloc(pic, sizeof(struct pic_escape));
|
||||
struct pic_cont *escape = pic_malloc(pic, sizeof(struct pic_cont));
|
||||
|
||||
pic_save_point(pic, escape);
|
||||
|
||||
if (PIC_SETJMP(pic, (void *)escape->jmp.buf)) {
|
||||
if (PIC_SETJMP(pic, escape->jmp.buf)) {
|
||||
pic->jmp = pic->jmp->prev;
|
||||
|
||||
return pic_values_by_list(pic, escape->results);
|
||||
|
@ -141,7 +141,7 @@ pic_escape(pic_state *pic, struct pic_proc *proc)
|
|||
else {
|
||||
pic_value val;
|
||||
|
||||
val = pic_apply1(pic, proc, pic_obj_value(pic_make_econt(pic, escape)));
|
||||
val = pic_apply1(pic, proc, pic_obj_value(pic_make_cont(pic, escape)));
|
||||
|
||||
pic->jmp = pic->jmp->prev;
|
||||
|
||||
|
@ -237,7 +237,7 @@ pic_cont_callcc(pic_state *pic)
|
|||
|
||||
pic_get_args(pic, "l", &cb);
|
||||
|
||||
return pic_escape(pic, cb);
|
||||
return pic_callcc(pic, cb);
|
||||
}
|
||||
|
||||
static pic_value
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct pic_escape {
|
||||
struct pic_cont {
|
||||
pic_jmpbuf jmp;
|
||||
|
||||
struct pic_winder *wind;
|
||||
|
@ -24,10 +24,10 @@ struct pic_escape {
|
|||
pic_value results;
|
||||
};
|
||||
|
||||
void pic_save_point(pic_state *, struct pic_escape *);
|
||||
void pic_load_point(pic_state *, struct pic_escape *);
|
||||
void pic_save_point(pic_state *, struct pic_cont *);
|
||||
void pic_load_point(pic_state *, struct pic_cont *);
|
||||
|
||||
struct pic_proc *pic_make_econt(pic_state *, struct pic_escape *);
|
||||
struct pic_proc *pic_make_cont(pic_state *, struct pic_cont *);
|
||||
|
||||
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 *);
|
||||
|
@ -42,7 +42,7 @@ pic_value pic_values_by_array(pic_state *, size_t, pic_value *);
|
|||
pic_value pic_values_by_list(pic_state *, pic_value);
|
||||
size_t pic_receive(pic_state *, size_t, pic_value *);
|
||||
|
||||
pic_value pic_escape(pic_state *, struct pic_proc *);
|
||||
pic_value pic_callcc(pic_state *, struct pic_proc *);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
|
|
|
@ -28,13 +28,13 @@ struct pic_error *pic_make_error(pic_state *, pic_sym *, const char *, pic_list)
|
|||
pic_try_(PIC_GENSYM(escape))
|
||||
#define pic_catch \
|
||||
pic_catch_(PIC_GENSYM(label))
|
||||
#define pic_try_(escape) \
|
||||
#define pic_try_(cont) \
|
||||
do { \
|
||||
struct pic_escape *escape = pic_malloc(pic, sizeof(struct pic_escape)); \
|
||||
pic_save_point(pic, escape); \
|
||||
if (PIC_SETJMP(pic, (void *)escape->jmp.buf) == 0) { \
|
||||
struct pic_cont *cont = pic_malloc(pic, sizeof(struct pic_cont)); \
|
||||
pic_save_point(pic, cont); \
|
||||
if (PIC_SETJMP(pic, cont->jmp.buf) == 0) { \
|
||||
do { \
|
||||
pic_push_try(pic, pic_make_econt(pic, escape));
|
||||
pic_push_try(pic, pic_make_cont(pic, cont));
|
||||
#define pic_catch_(label) \
|
||||
pic_pop_try(pic); \
|
||||
} while (0); \
|
||||
|
|
Loading…
Reference in New Issue