This commit is contained in:
Yuichi Nishiwaki 2015-05-31 20:22:46 +09:00
parent 88092044d7
commit ce0c737c95
4 changed files with 20 additions and 23 deletions

View File

@ -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;
}

View File

@ -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))

View File

@ -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();

View File

@ -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;