From 98857c07265c1878d6717c1c97ddda8c98f97925 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Tue, 9 Jun 2015 22:26:21 +0900 Subject: [PATCH] change pic_find_rename interface --- extlib/benz/include/picrin/macro.h | 2 +- extlib/benz/lib.c | 2 +- extlib/benz/macro.c | 21 +++++++++------------ extlib/benz/vm.c | 6 +++--- 4 files changed, 14 insertions(+), 17 deletions(-) diff --git a/extlib/benz/include/picrin/macro.h b/extlib/benz/include/picrin/macro.h index c0f6fef3..7d150777 100644 --- a/extlib/benz/include/picrin/macro.h +++ b/extlib/benz/include/picrin/macro.h @@ -25,7 +25,7 @@ bool pic_identifier_eq_p(pic_state *, struct pic_env *, pic_sym *, struct pic_en struct pic_env *pic_make_env(pic_state *, struct pic_env *); pic_sym *pic_add_rename(pic_state *, struct pic_env *, pic_sym *); -bool pic_find_rename(pic_state *, struct pic_env *, pic_sym *, pic_sym ** /* = NULL */); +pic_sym *pic_find_rename(pic_state *, struct pic_env *, pic_sym *); void pic_put_rename(pic_state *, struct pic_env *, pic_sym *, pic_sym *); #if defined(__cplusplus) diff --git a/extlib/benz/lib.c b/extlib/benz/lib.c index e39e0f48..9c5468bf 100644 --- a/extlib/benz/lib.c +++ b/extlib/benz/lib.c @@ -165,7 +165,7 @@ export(pic_state *pic, pic_value spec) goto fail; } - if (! pic_find_rename(pic, pic->lib->env, pic_sym_ptr(a), &rename)) { + if ((rename = pic_find_rename(pic, pic->lib->env, pic_sym_ptr(a))) == NULL) { pic_errorf(pic, "export: symbol not defined %s", pic_symbol_name(pic, pic_sym_ptr(a))); } diff --git a/extlib/benz/macro.c b/extlib/benz/macro.c index b12c6bc6..a36a8c8c 100644 --- a/extlib/benz/macro.c +++ b/extlib/benz/macro.c @@ -7,10 +7,10 @@ pic_sym * pic_add_rename(pic_state *pic, struct pic_env *env, pic_sym *sym) { - pic_sym *rename; + pic_sym *rename = pic_gensym(pic, sym); - rename = pic_gensym(pic, sym); pic_put_rename(pic, env, sym, rename); + return rename; } @@ -20,16 +20,13 @@ pic_put_rename(pic_state *pic, struct pic_env *env, pic_sym *sym, pic_sym *renam pic_dict_set(pic, env->map, sym, pic_obj_value(rename)); } -bool -pic_find_rename(pic_state *pic, struct pic_env *env, pic_sym *sym, pic_sym **rename) +pic_sym * +pic_find_rename(pic_state *pic, struct pic_env *env, pic_sym *sym) { if (! pic_dict_has(pic, env->map, sym)) { - return false; + return NULL; } - if (rename != NULL) { - *rename = pic_sym_ptr(pic_dict_ref(pic, env->map, sym)); - } - return true; + return pic_sym_ptr(pic_dict_ref(pic, env->map, sym)); } static void @@ -53,7 +50,7 @@ make_identifier(pic_state *pic, pic_sym *sym, struct pic_env *env) pic_sym *rename; while (true) { - if (pic_find_rename(pic, env, sym, &rename)) { + if ((rename = pic_find_rename(pic, env, sym)) != NULL) { return rename; } if (! env->up) @@ -189,7 +186,7 @@ macroexpand_define(pic_state *pic, pic_value expr, struct pic_env *env) pic_errorf(pic, "binding to non-symbol object"); } sym = pic_sym_ptr(var); - if (! pic_find_rename(pic, env, sym, &rename)) { + if ((rename = pic_find_rename(pic, env, sym)) == NULL) { rename = pic_add_rename(pic, env, sym); } val = macroexpand(pic, pic_list_ref(pic, expr, 2), env); @@ -212,7 +209,7 @@ macroexpand_defsyntax(pic_state *pic, pic_value expr, struct pic_env *env) pic_errorf(pic, "binding to non-symbol object"); } sym = pic_sym_ptr(var); - if (! pic_find_rename(pic, env, sym, &rename)) { + if ((rename = pic_find_rename(pic, env, sym)) == NULL) { rename = pic_add_rename(pic, env, sym); } else { pic_warnf(pic, "redefining syntax variable: ~s", pic_obj_value(sym)); diff --git a/extlib/benz/vm.c b/extlib/benz/vm.c index ab9916fb..7a062019 100644 --- a/extlib/benz/vm.c +++ b/extlib/benz/vm.c @@ -410,7 +410,7 @@ pic_define_noexport(pic_state *pic, const char *name, pic_value val) sym = pic_intern_cstr(pic, name); - if (! pic_find_rename(pic, pic->lib->env, sym, &rename)) { + if ((rename = pic_find_rename(pic, pic->lib->env, sym)) == NULL) { rename = pic_add_rename(pic, pic->lib->env, sym); } else { pic_warnf(pic, "redefining global"); @@ -434,7 +434,7 @@ pic_ref(pic_state *pic, struct pic_lib *lib, const char *name) sym = pic_intern_cstr(pic, name); - if (! pic_find_rename(pic, lib->env, sym, &rename)) { + if ((rename = pic_find_rename(pic, lib->env, sym)) == NULL) { pic_errorf(pic, "symbol \"%s\" not defined in library ~s", name, lib->name); } @@ -448,7 +448,7 @@ pic_set(pic_state *pic, struct pic_lib *lib, const char *name, pic_value val) sym = pic_intern_cstr(pic, name); - if (! pic_find_rename(pic, lib->env, sym, &rename)) { + if ((rename = pic_find_rename(pic, lib->env, sym)) == NULL) { pic_errorf(pic, "symbol \"%s\" not defined in library ~s", name, lib->name); }