diff --git a/extlib/benz/gc.c b/extlib/benz/gc.c index f1796ce1..5d3c5f9d 100644 --- a/extlib/benz/gc.c +++ b/extlib/benz/gc.c @@ -374,7 +374,7 @@ gc_mark_object(pic_state *pic, struct pic_object *obj) gc_mark_object(pic, (struct pic_object *)proc->u.i.cxt); } } else { - gc_mark_object(pic, (struct pic_object *)proc->u.func.name); + gc_mark_object(pic, (struct pic_object *)proc->u.f.name); } break; } diff --git a/extlib/benz/include/picrin/proc.h b/extlib/benz/include/picrin/proc.h index 17605590..eaac2ef7 100644 --- a/extlib/benz/include/picrin/proc.h +++ b/extlib/benz/include/picrin/proc.h @@ -9,12 +9,6 @@ extern "C" { #endif -/* native C function */ -struct pic_func { - pic_func_t f; - pic_sym *name; -}; - struct pic_context { PIC_OBJECT_HEADER pic_value *regs; @@ -25,9 +19,15 @@ struct pic_context { struct pic_proc { PIC_OBJECT_HEADER - char kind; + enum { + PIC_PROC_TAG_IREP, + PIC_PROC_TAG_FUNC + } tag; union { - struct pic_func func; + struct { + pic_func_t func; + pic_sym *name; + } f; struct { struct pic_irep *irep; struct pic_context *cxt; @@ -35,11 +35,8 @@ struct pic_proc { } u; }; -#define PIC_PROC_KIND_FUNC 1 -#define PIC_PROC_KIND_IREP 2 - -#define pic_proc_func_p(proc) ((proc)->kind == PIC_PROC_KIND_FUNC) -#define pic_proc_irep_p(proc) ((proc)->kind == PIC_PROC_KIND_IREP) +#define pic_proc_func_p(proc) ((proc)->tag == PIC_PROC_TAG_FUNC) +#define pic_proc_irep_p(proc) ((proc)->tag == PIC_PROC_TAG_IREP) #define pic_proc_p(o) (pic_type(o) == PIC_TT_PROC) #define pic_proc_ptr(o) ((struct pic_proc *)pic_ptr(o)) diff --git a/extlib/benz/proc.c b/extlib/benz/proc.c index 93432759..e8c80f7a 100644 --- a/extlib/benz/proc.c +++ b/extlib/benz/proc.c @@ -15,9 +15,9 @@ pic_make_proc(pic_state *pic, pic_func_t func, const char *name) sym = pic_intern_cstr(pic, name); proc = (struct pic_proc *)pic_obj_alloc(pic, sizeof(struct pic_proc), PIC_TT_PROC); - proc->kind = PIC_PROC_KIND_FUNC; - proc->u.func.f = func; - proc->u.func.name = sym; + proc->tag = PIC_PROC_TAG_FUNC; + proc->u.f.func = func; + proc->u.f.name = sym; return proc; } @@ -27,7 +27,7 @@ pic_make_proc_irep(pic_state *pic, struct pic_irep *irep, struct pic_context *cx 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->tag = PIC_PROC_TAG_IREP; proc->u.i.irep = irep; proc->u.i.cxt = cxt; return proc; @@ -36,10 +36,10 @@ pic_make_proc_irep(pic_state *pic, struct pic_irep *irep, struct pic_context *cx pic_sym * pic_proc_name(struct pic_proc *proc) { - switch (proc->kind) { - case PIC_PROC_KIND_FUNC: - return proc->u.func.name; - case PIC_PROC_KIND_IREP: + switch (proc->tag) { + case PIC_PROC_TAG_FUNC: + return proc->u.f.name; + case PIC_PROC_TAG_IREP: return proc->u.i.irep->name; } PIC_UNREACHABLE(); diff --git a/extlib/benz/vm.c b/extlib/benz/vm.c index 95ada7a5..baea1bfe 100644 --- a/extlib/benz/vm.c +++ b/extlib/benz/vm.c @@ -862,7 +862,7 @@ pic_apply(pic_state *pic, struct pic_proc *proc, pic_value args) if (pic_proc_func_p(pic_proc_ptr(x))) { /* invoke! */ - v = proc->u.func.f(pic); + v = proc->u.f.func(pic); pic->sp[0] = v; pic->sp += pic->ci->retc;