From 88092044d76aa123b914e4b403728cb10df491be Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Sun, 31 May 2015 20:19:07 +0900 Subject: [PATCH] shrink pic_proc size --- extlib/benz/gc.c | 8 ++++---- extlib/benz/include/picrin/proc.h | 6 ++++-- extlib/benz/proc.c | 7 +++---- extlib/benz/vm.c | 20 ++++++++++++-------- 4 files changed, 23 insertions(+), 18 deletions(-) diff --git a/extlib/benz/gc.c b/extlib/benz/gc.c index c60f377a..f1796ce1 100644 --- a/extlib/benz/gc.c +++ b/extlib/benz/gc.c @@ -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); } diff --git a/extlib/benz/include/picrin/proc.h b/extlib/benz/include/picrin/proc.h index 472dfe8a..17605590 100644 --- a/extlib/benz/include/picrin/proc.h +++ b/extlib/benz/include/picrin/proc.h @@ -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 diff --git a/extlib/benz/proc.c b/extlib/benz/proc.c index 71b3195a..93432759 100644 --- a/extlib/benz/proc.c +++ b/extlib/benz/proc.c @@ -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(); } diff --git a/extlib/benz/vm.c b/extlib/benz/vm.c index 9d26ee6b..95ada7a5 100644 --- a/extlib/benz/vm.c +++ b/extlib/benz/vm.c @@ -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"); }