From cf1e1a87460f7a68028b548c1ed6b22a69fa9c02 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Fri, 28 Mar 2014 12:34:54 +0900 Subject: [PATCH] add pic_proc_name --- include/picrin/proc.h | 2 ++ src/proc.c | 12 ++++++++++++ src/vm.c | 4 ++-- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/include/picrin/proc.h b/include/picrin/proc.h index 18df1357..86e11121 100644 --- a/include/picrin/proc.h +++ b/include/picrin/proc.h @@ -48,6 +48,8 @@ struct pic_proc { struct pic_proc *pic_proc_new(pic_state *, pic_func_t, const char *); struct pic_proc *pic_proc_new_irep(pic_state *, struct pic_irep *, struct pic_env *); +pic_sym pic_proc_name(struct pic_proc *); + /* closed variables accessor */ void pic_proc_cv_init(pic_state *, struct pic_proc *, size_t); int pic_proc_cv_size(pic_state *, struct pic_proc *); diff --git a/src/proc.c b/src/proc.c index 1dfb259a..d4c73d7a 100644 --- a/src/proc.c +++ b/src/proc.c @@ -34,6 +34,18 @@ pic_proc_new_irep(pic_state *pic, struct pic_irep *irep, struct pic_env *env) return proc; } +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: + return proc->u.irep->name; + } + UNREACHABLE(); +} + void pic_proc_cv_init(pic_state *pic, struct pic_proc *proc, size_t cv_size) { diff --git a/src/vm.c b/src/vm.c index a4aa1551..760a63eb 100644 --- a/src/vm.c +++ b/src/vm.c @@ -687,12 +687,12 @@ pic_apply(pic_state *pic, struct pic_proc *proc, pic_value argv) puts(")"); if (! pic_proc_func_p(proc)) { printf(" irep = %p\n", proc->u.irep); - printf(" name = %s\n", pic_symbol_name(pic, proc->u.irep->name)); + printf(" name = %s\n", pic_symbol_name(pic, pic_proc_name(proc))); pic_dump_irep(proc->u.irep); } else { printf(" cfunc = %p\n", (void *)proc->u.func.f); - printf(" name = %s\n", pic_symbol_name(pic, proc->u.func.name)); + printf(" name = %s\n", pic_symbol_name(pic, pic_proc_name(proc))); } puts("== end\n"); #endif