From ee4cb870837adfe9774d8f4643151b48c920ae98 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Sat, 18 Jan 2014 12:58:00 +0900 Subject: [PATCH] impl pic_unwrap_var --- src/var.c | 50 ++++++++++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/src/var.c b/src/var.c index 5cb0fa6c..92afb717 100644 --- a/src/var.c +++ b/src/var.c @@ -45,6 +45,28 @@ pic_var_set_force(pic_state *pic, struct pic_var *var, pic_value value) var->value = value; } +static struct pic_var * +get_var_from_proc(pic_state *pic, struct pic_proc *proc) +{ + pic_value v; + + if (! proc->cfunc_p) { + goto typeerror; + } + if (pic_proc_cv_size(pic, proc) != 1) { + goto typeerror; + } + v = pic_proc_cv_ref(pic, proc, 0); + if (! pic_var_p(v)) { + goto typeerror; + } + return pic_var_ptr(v); + + typeerror: + pic_error(pic, "expected parameter"); + UNREACHABLE; +} + static pic_value var_call(pic_state *pic) { @@ -83,6 +105,12 @@ pic_wrap_var(pic_state *pic, struct pic_var *var) return proc; } +struct pic_var * +pic_unwrap_var(pic_state *pic, struct pic_proc *proc) +{ + return get_var_from_proc(pic, proc); +} + static pic_value pic_var_make_parameter(pic_state *pic) { @@ -96,28 +124,6 @@ pic_var_make_parameter(pic_state *pic) return pic_obj_value(pic_wrap_var(pic, var)); } -static struct pic_var * -get_var_from_proc(pic_state *pic, struct pic_proc *proc) -{ - pic_value v; - - if (! proc->cfunc_p) { - goto typeerror; - } - if (pic_proc_cv_size(pic, proc) != 1) { - goto typeerror; - } - v = pic_proc_cv_ref(pic, proc, 0); - if (! pic_var_p(v)) { - goto typeerror; - } - return pic_var_ptr(v); - - typeerror: - pic_error(pic, "expected parameter"); - UNREACHABLE; -} - static pic_value pic_var_parameter_ref(pic_state *pic) {