pic_env -> pic_context

This commit is contained in:
Yuichi Nishiwaki 2015-05-30 22:34:51 +09:00
parent bebda9407f
commit d0e10b49a7
7 changed files with 60 additions and 60 deletions

View File

@ -66,8 +66,8 @@ cont_mark(pic_state *pic, void *data, void (*mark)(pic_state *, pic_value))
/* callinfo */
for (ci = cont->ci_ptr + cont->ci_offset; ci != cont->ci_ptr; --ci) {
if (ci->env) {
mark(pic, pic_obj_value(ci->env));
if (ci->cxt) {
mark(pic, pic_obj_value(ci->cxt));
}
}

View File

@ -354,22 +354,22 @@ gc_mark_object(pic_state *pic, struct pic_object *obj)
gc_mark(pic, ((struct pic_pair *)obj)->cdr);
break;
}
case PIC_TT_ENV: {
struct pic_env *env = (struct pic_env *)obj;
case PIC_TT_CXT: {
struct pic_context *cxt = (struct pic_context *)obj;
int i;
for (i = 0; i < env->regc; ++i) {
gc_mark(pic, env->regs[i]);
for (i = 0; i < cxt->regc; ++i) {
gc_mark(pic, cxt->regs[i]);
}
if (env->up) {
gc_mark_object(pic, (struct pic_object *)env->up);
if (cxt->up) {
gc_mark_object(pic, (struct pic_object *)cxt->up);
}
break;
}
case PIC_TT_PROC: {
struct pic_proc *proc = (struct pic_proc *)obj;
if (proc->env) {
gc_mark_object(pic, (struct pic_object *)proc->env);
if (proc->cxt) {
gc_mark_object(pic, (struct pic_object *)proc->cxt);
}
if (pic_proc_irep_p(proc)) {
gc_mark_object(pic, (struct pic_object *)proc->u.irep);
@ -542,8 +542,8 @@ gc_mark_phase(pic_state *pic)
/* callinfo */
for (ci = pic->ci; ci != pic->cibase; --ci) {
if (ci->env) {
gc_mark_object(pic, (struct pic_object *)ci->env);
if (ci->cxt) {
gc_mark_object(pic, (struct pic_object *)ci->cxt);
}
}
@ -619,7 +619,7 @@ gc_finalize_object(pic_state *pic, struct pic_object *obj)
case PIC_TT_PAIR: {
break;
}
case PIC_TT_ENV: {
case PIC_TT_CXT: {
break;
}
case PIC_TT_PROC: {

View File

@ -59,10 +59,10 @@ typedef struct {
int argc, retc;
pic_code *ip;
pic_value *fp;
struct pic_env *env;
struct pic_context *cxt;
int regc;
pic_value *regs;
struct pic_env *up;
struct pic_context *up;
} pic_callinfo;
typedef void *(*pic_allocf)(void *, size_t);

View File

@ -15,11 +15,11 @@ struct pic_func {
pic_sym *name;
};
struct pic_env {
struct pic_context {
PIC_OBJECT_HEADER
pic_value *regs;
int regc;
struct pic_env *up;
struct pic_context *up;
pic_value storage[1];
};
@ -30,7 +30,7 @@ struct pic_proc {
struct pic_func func;
struct pic_irep *irep;
} u;
struct pic_env *env;
struct pic_context *cxt;
};
#define PIC_PROC_KIND_FUNC 1
@ -42,11 +42,11 @@ struct pic_proc {
#define pic_proc_p(o) (pic_type(o) == PIC_TT_PROC)
#define pic_proc_ptr(o) ((struct pic_proc *)pic_ptr(o))
#define pic_env_p(o) (pic_type(o) == PIC_TT_ENV)
#define pic_env_ptr(o) ((struct pic_env *)pic_ptr(o))
#define pic_context_p(o) (pic_type(o) == PIC_TT_CXT)
#define pic_context_ptr(o) ((struct pic_context *)pic_ptr(o))
struct pic_proc *pic_make_proc(pic_state *, pic_func_t, const char *);
struct pic_proc *pic_make_proc_irep(pic_state *, struct pic_irep *, struct pic_env *);
struct pic_proc *pic_make_proc_irep(pic_state *, struct pic_irep *, struct pic_context *);
pic_sym *pic_proc_name(struct pic_proc *);

View File

@ -155,7 +155,7 @@ enum pic_tt {
PIC_TT_PROC,
PIC_TT_PORT,
PIC_TT_ERROR,
PIC_TT_ENV,
PIC_TT_CXT,
PIC_TT_SENV,
PIC_TT_LIB,
PIC_TT_IREP,
@ -306,8 +306,8 @@ pic_type_repr(enum pic_tt tt)
return "port";
case PIC_TT_ERROR:
return "error";
case PIC_TT_ENV:
return "env";
case PIC_TT_CXT:
return "cxt";
case PIC_TT_PROC:
return "proc";
case PIC_TT_SENV:

View File

@ -18,19 +18,19 @@ pic_make_proc(pic_state *pic, pic_func_t func, const char *name)
proc->kind = PIC_PROC_KIND_FUNC;
proc->u.func.f = func;
proc->u.func.name = sym;
proc->env = NULL;
proc->cxt = NULL;
return proc;
}
struct pic_proc *
pic_make_proc_irep(pic_state *pic, struct pic_irep *irep, struct pic_env *env)
pic_make_proc_irep(pic_state *pic, struct pic_irep *irep, struct pic_context *cxt)
{
struct pic_proc *proc;
proc = (struct pic_proc *)pic_obj_alloc(pic, sizeof(struct pic_proc), PIC_TT_PROC);
proc->kind = PIC_PROC_KIND_IREP;
proc->u.irep = irep;
proc->env = env;
proc->cxt = cxt;
return proc;
}

View File

@ -473,33 +473,33 @@ pic_defvar(pic_state *pic, const char *name, pic_value init, struct pic_proc *co
}
static void
vm_push_env(pic_state *pic)
vm_push_cxt(pic_state *pic)
{
pic_callinfo *ci = pic->ci;
ci->env = (struct pic_env *)pic_obj_alloc(pic, sizeof(struct pic_env) + sizeof(pic_value) * (size_t)(ci->regc), PIC_TT_ENV);
ci->env->up = ci->up;
ci->env->regc = ci->regc;
ci->env->regs = ci->regs;
ci->cxt = (struct pic_context *)pic_obj_alloc(pic, sizeof(struct pic_context) + sizeof(pic_value) * (size_t)(ci->regc), PIC_TT_CXT);
ci->cxt->up = ci->up;
ci->cxt->regc = ci->regc;
ci->cxt->regs = ci->regs;
}
static void
vm_tear_off(pic_callinfo *ci)
{
struct pic_env *env;
struct pic_context *cxt;
int i;
assert(ci->env != NULL);
assert(ci->cxt != NULL);
env = ci->env;
cxt = ci->cxt;
if (env->regs == env->storage) {
if (cxt->regs == cxt->storage) {
return; /* is torn off */
}
for (i = 0; i < env->regc; ++i) {
env->storage[i] = env->regs[i];
for (i = 0; i < cxt->regc; ++i) {
cxt->storage[i] = cxt->regs[i];
}
env->regs = env->storage;
cxt->regs = cxt->storage;
}
void
@ -508,7 +508,7 @@ pic_vm_tear_off(pic_state *pic)
pic_callinfo *ci;
for (ci = pic->ci; ci > pic->cibase; ci--) {
if (ci->env != NULL) {
if (ci->cxt != NULL) {
vm_tear_off(ci);
}
}
@ -764,10 +764,10 @@ pic_apply(pic_state *pic, struct pic_proc *proc, pic_value args)
pic_callinfo *ci = pic->ci;
struct pic_irep *irep;
if (ci->env != NULL && ci->env->regs == ci->env->storage) {
if (ci->cxt != NULL && ci->cxt->regs == ci->cxt->storage) {
irep = pic_get_proc(pic)->u.irep;
if (c.u.i >= irep->argc + irep->localc) {
PUSH(ci->env->regs[c.u.i - (ci->regs - ci->fp)]);
PUSH(ci->cxt->regs[c.u.i - (ci->regs - ci->fp)]);
NEXT;
}
}
@ -778,10 +778,10 @@ pic_apply(pic_state *pic, struct pic_proc *proc, pic_value args)
pic_callinfo *ci = pic->ci;
struct pic_irep *irep;
if (ci->env != NULL && ci->env->regs == ci->env->storage) {
if (ci->cxt != NULL && ci->cxt->regs == ci->cxt->storage) {
irep = pic_get_proc(pic)->u.irep;
if (c.u.i >= irep->argc + irep->localc) {
ci->env->regs[c.u.i - (ci->regs - ci->fp)] = POP();
ci->cxt->regs[c.u.i - (ci->regs - ci->fp)] = POP();
NEXT;
}
}
@ -790,24 +790,24 @@ pic_apply(pic_state *pic, struct pic_proc *proc, pic_value args)
}
CASE(OP_CREF) {
int depth = c.u.r.depth;
struct pic_env *env;
struct pic_context *cxt;
env = pic->ci->up;
cxt = pic->ci->up;
while (--depth) {
env = env->up;
cxt = cxt->up;
}
PUSH(env->regs[c.u.r.idx]);
PUSH(cxt->regs[c.u.r.idx]);
NEXT;
}
CASE(OP_CSET) {
int depth = c.u.r.depth;
struct pic_env *env;
struct pic_context *cxt;
env = pic->ci->up;
cxt = pic->ci->up;
while (--depth) {
env = env->up;
cxt = cxt->up;
}
env->regs[c.u.r.idx] = POP();
cxt->regs[c.u.r.idx] = POP();
NEXT;
}
CASE(OP_JMP) {
@ -858,7 +858,7 @@ pic_apply(pic_state *pic, struct pic_proc *proc, pic_value args)
ci->retc = 1;
ci->ip = pic->ip;
ci->fp = pic->sp - c.u.i;
ci->env = NULL;
ci->cxt = NULL;
if (pic_proc_func_p(pic_proc_ptr(x))) {
/* invoke! */
@ -899,8 +899,8 @@ pic_apply(pic_state *pic, struct pic_proc *proc, pic_value args)
}
}
/* prepare env */
ci->up = proc->env;
/* prepare cxt */
ci->up = proc->cxt;
ci->regc = irep->capturec;
ci->regs = ci->fp + irep->argc + irep->localc;
@ -914,7 +914,7 @@ pic_apply(pic_state *pic, struct pic_proc *proc, pic_value args)
pic_value *argv;
pic_callinfo *ci;
if (pic->ci->env != NULL) {
if (pic->ci->cxt != NULL) {
vm_tear_off(pic->ci);
}
@ -940,7 +940,7 @@ pic_apply(pic_state *pic, struct pic_proc *proc, pic_value args)
pic_value *retv;
pic_callinfo *ci;
if (pic->ci->env != NULL) {
if (pic->ci->cxt != NULL) {
vm_tear_off(pic->ci);
}
@ -974,11 +974,11 @@ pic_apply(pic_state *pic, struct pic_proc *proc, pic_value args)
pic_errorf(pic, "logic flaw");
}
if (pic->ci->env == NULL) {
vm_push_env(pic);
if (pic->ci->cxt == NULL) {
vm_push_cxt(pic);
}
proc = pic_make_proc_irep(pic, irep->irep[c.u.i], pic->ci->env);
proc = pic_make_proc_irep(pic, irep->irep[c.u.i], pic->ci->cxt);
PUSH(pic_obj_value(proc));
pic_gc_arena_restore(pic, ai);
NEXT;