add cxt.ai
This commit is contained in:
parent
8c234d7548
commit
ce80a2dfdf
|
@ -65,7 +65,8 @@ pic_enter_try(pic_state *pic)
|
|||
{
|
||||
pic_value cont, handler;
|
||||
pic_value var, env;
|
||||
size_t ai = pic_enter(pic);
|
||||
|
||||
pic->cxt->ai = pic->ai;
|
||||
|
||||
/* call/cc */
|
||||
cont = pic_make_cont(pic, pic->cxt, pic_invalid_value(pic), pic->dyn_env);
|
||||
|
@ -76,7 +77,7 @@ pic_enter_try(pic_state *pic)
|
|||
pic_weak_set(pic, env, var, pic_cons(pic, handler, pic_call(pic, var, 0)));
|
||||
pic->dyn_env = pic_cons(pic, env, pic->dyn_env);
|
||||
|
||||
pic_leave(pic, ai);
|
||||
pic_leave(pic, pic->cxt->ai);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -86,6 +87,7 @@ pic_exit_try(pic_state *pic)
|
|||
pic->dyn_env = pic_cdr(pic, pic->dyn_env);
|
||||
pic->cxt = cxt->prev;
|
||||
pic_free(pic, cxt);
|
||||
/* don't rewind ai here */
|
||||
}
|
||||
|
||||
pic_value
|
||||
|
@ -93,7 +95,7 @@ pic_abort_try(pic_state *pic)
|
|||
{
|
||||
struct context *cxt = pic->cxt;
|
||||
pic_value err = cxt->sp->regs[1];
|
||||
pic->cxt = pic->cxt->prev;
|
||||
pic->cxt = cxt->prev;
|
||||
pic_free(pic, cxt);
|
||||
pic_protect(pic, err);
|
||||
return err;
|
||||
|
|
|
@ -304,18 +304,14 @@ PIC_NORETURN void pic_error(pic_state *, const char *msg, int n, ...);
|
|||
extern void pic_enter_try(pic_state *); \
|
||||
extern void pic_exit_try(pic_state *); \
|
||||
extern pic_value pic_abort_try(pic_state *); \
|
||||
size_t pic_try_ai_ = pic_enter(pic); \
|
||||
PIC_JMPBUF *jmp = pic_prepare_try(pic); \
|
||||
if (PIC_SETJMP(*jmp) == 0) { \
|
||||
pic_enter_try(pic);
|
||||
#define pic_catch(e) pic_catch_(e, PIC_GENSYM(label))
|
||||
#define pic_catch_(e, label) \
|
||||
pic_exit_try(pic); \
|
||||
/* don't rewind ai here */ \
|
||||
} else { \
|
||||
e = pic_abort_try(pic); \
|
||||
pic_leave(pic, pic_try_ai_); \
|
||||
pic_protect(pic, e); \
|
||||
goto label; \
|
||||
} \
|
||||
} while (0); \
|
||||
|
|
|
@ -364,7 +364,6 @@ pic_value
|
|||
pic_apply(pic_state *pic, pic_value proc, int argc, pic_value *argv)
|
||||
{
|
||||
struct context cxt;
|
||||
size_t arena_base = pic->ai;
|
||||
|
||||
#define MKCALL(argc) (cxt.tmpcode[0] = OP_CALL, cxt.tmpcode[1] = (argc), cxt.tmpcode)
|
||||
|
||||
|
@ -383,10 +382,10 @@ pic_apply(pic_state *pic, pic_value proc, int argc, pic_value *argv)
|
|||
cxt.prev = pic->cxt;
|
||||
pic->cxt = &cxt;
|
||||
|
||||
#define SAVE (pic->ai = arena_base)
|
||||
#define SAVE (pic->ai = cxt.ai)
|
||||
|
||||
if (PIC_SETJMP(cxt.jmp) != 0) {
|
||||
SAVE;
|
||||
if (PIC_SETJMP(cxt.jmp) == 0) {
|
||||
cxt.ai = pic->ai;
|
||||
}
|
||||
|
||||
#define A (cxt.pc[1])
|
||||
|
|
|
@ -171,6 +171,7 @@ pic_open(pic_allocf allocf, void *userdata)
|
|||
pic->userdata = userdata;
|
||||
|
||||
/* context */
|
||||
pic->default_cxt.ai = 0;
|
||||
pic->default_cxt.pc = NULL;
|
||||
pic->default_cxt.fp = NULL;
|
||||
pic->default_cxt.sp = NULL;
|
||||
|
@ -256,6 +257,7 @@ pic_close(pic_state *pic)
|
|||
pic->features = pic_invalid_value(pic);
|
||||
pic->dyn_env = pic_invalid_value(pic);
|
||||
|
||||
assert(pic->cxt->ai == 0);
|
||||
assert(pic->cxt->pc == NULL);
|
||||
assert(pic->cxt->fp == NULL);
|
||||
assert(pic->cxt->sp == NULL);
|
||||
|
|
|
@ -16,6 +16,7 @@ KHASH_DECLARE(oblist, struct string *, struct symbol *)
|
|||
|
||||
struct context {
|
||||
PIC_JMPBUF jmp;
|
||||
size_t ai;
|
||||
|
||||
/* vm */
|
||||
const code_t *pc;
|
||||
|
|
Loading…
Reference in New Issue