shrink pic_proc size

This commit is contained in:
Yuichi Nishiwaki 2015-05-31 20:19:07 +09:00
parent 65dc4020f4
commit 88092044d7
4 changed files with 23 additions and 18 deletions

View File

@ -368,11 +368,11 @@ gc_mark_object(pic_state *pic, struct pic_object *obj)
}
case PIC_TT_PROC: {
struct pic_proc *proc = (struct pic_proc *)obj;
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);
gc_mark_object(pic, (struct pic_object *)proc->u.i.irep);
if (proc->u.i.cxt) {
gc_mark_object(pic, (struct pic_object *)proc->u.i.cxt);
}
} else {
gc_mark_object(pic, (struct pic_object *)proc->u.func.name);
}

View File

@ -28,9 +28,11 @@ struct pic_proc {
char kind;
union {
struct pic_func func;
struct pic_irep *irep;
struct {
struct pic_irep *irep;
struct pic_context *cxt;
} i;
} u;
struct pic_context *cxt;
};
#define PIC_PROC_KIND_FUNC 1

View File

@ -18,7 +18,6 @@ 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->cxt = NULL;
return proc;
}
@ -29,8 +28,8 @@ pic_make_proc_irep(pic_state *pic, struct pic_irep *irep, struct pic_context *cx
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->cxt = cxt;
proc->u.i.irep = irep;
proc->u.i.cxt = cxt;
return proc;
}
@ -41,7 +40,7 @@ pic_proc_name(struct pic_proc *proc)
case PIC_PROC_KIND_FUNC:
return proc->u.func.name;
case PIC_PROC_KIND_IREP:
return proc->u.irep->name;
return proc->u.i.irep->name;
}
PIC_UNREACHABLE();
}

View File

@ -524,7 +524,7 @@ vm_get_irep(pic_state *pic)
if (! pic_proc_p(self)) {
pic_errorf(pic, "logic flaw");
}
irep = pic_proc_ptr(self)->u.irep;
irep = pic_proc_ptr(self)->u.i.irep;
if (! pic_proc_irep_p(pic_proc_ptr(self))) {
pic_errorf(pic, "logic flaw");
}
@ -642,9 +642,9 @@ pic_apply5(pic_state *pic, struct pic_proc *proc, pic_value arg1, pic_value arg2
} \
puts(")"); \
if (! pic_proc_func_p(proc)) { \
printf(" irep = %p\n", proc->u.irep); \
printf(" irep = %p\n", proc->u.i.irep); \
printf(" name = %s\n", pic_symbol_name(pic, pic_proc_name(proc))); \
pic_dump_irep(proc->u.irep); \
pic_dump_irep(proc->u.i.irep); \
} \
else { \
printf(" cfunc = %p\n", (void *)proc->u.func.f); \
@ -765,7 +765,7 @@ pic_apply(pic_state *pic, struct pic_proc *proc, pic_value args)
struct pic_irep *irep;
if (ci->cxt != NULL && ci->cxt->regs == ci->cxt->storage) {
irep = pic_get_proc(pic)->u.irep;
irep = pic_get_proc(pic)->u.i.irep;
if (c.u.i >= irep->argc + irep->localc) {
PUSH(ci->cxt->regs[c.u.i - (ci->regs - ci->fp)]);
NEXT;
@ -779,7 +779,7 @@ pic_apply(pic_state *pic, struct pic_proc *proc, pic_value args)
struct pic_irep *irep;
if (ci->cxt != NULL && ci->cxt->regs == ci->cxt->storage) {
irep = pic_get_proc(pic)->u.irep;
irep = pic_get_proc(pic)->u.i.irep;
if (c.u.i >= irep->argc + irep->localc) {
ci->cxt->regs[c.u.i - (ci->regs - ci->fp)] = POP();
NEXT;
@ -870,7 +870,7 @@ pic_apply(pic_state *pic, struct pic_proc *proc, pic_value args)
goto L_RET;
}
else {
struct pic_irep *irep = proc->u.irep;
struct pic_irep *irep = proc->u.i.irep;
int i;
pic_value rest;
@ -900,7 +900,11 @@ pic_apply(pic_state *pic, struct pic_proc *proc, pic_value args)
}
/* prepare cxt */
ci->up = proc->cxt;
if (pic_proc_irep_p(proc)) {
ci->up = proc->u.i.cxt;
} else {
ci->up = NULL;
}
ci->regc = irep->capturec;
ci->regs = ci->fp + irep->argc + irep->localc;
@ -969,7 +973,7 @@ pic_apply(pic_state *pic, struct pic_proc *proc, pic_value args)
if (! pic_proc_p(self)) {
pic_errorf(pic, "logic flaw");
}
irep = pic_proc_ptr(self)->u.irep;
irep = pic_proc_ptr(self)->u.i.irep;
if (! pic_proc_irep_p(pic_proc_ptr(self))) {
pic_errorf(pic, "logic flaw");
}