change pic_find_rename interface

This commit is contained in:
Yuichi Nishiwaki 2015-06-09 22:26:21 +09:00
parent 6af9a3ee7d
commit 98857c0726
4 changed files with 14 additions and 17 deletions

View File

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

View File

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

View File

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

View File

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