add pic_ungensym

This commit is contained in:
Yuichi Nishiwaki 2014-07-26 14:04:34 +09:00
parent 6966cdfa31
commit 5ba0c56308
2 changed files with 17 additions and 0 deletions

View File

@ -153,6 +153,7 @@ pic_sym pic_intern(pic_state *, const char *, size_t);
pic_sym pic_intern_cstr(pic_state *, const char *);
const char *pic_symbol_name(pic_state *, pic_sym);
pic_sym pic_gensym(pic_state *, pic_sym);
pic_sym pic_ungensym(pic_state *, pic_sym);
bool pic_interned_p(pic_state *, pic_sym);
char *pic_strdup(pic_state *, const char *);

View File

@ -61,6 +61,22 @@ pic_gensym(pic_state *pic, pic_sym base)
return uniq;
}
pic_sym
pic_ungensym(pic_state *pic, pic_sym base)
{
const char *name, *occr;
if (pic_interned_p(pic, base)) {
return base;
}
name = pic_symbol_name(pic, base);
if ((occr = strrchr(name, '@')) == NULL) {
pic_abort(pic, "logic flaw");
}
return pic_intern(pic, name, occr - name);
}
bool
pic_interned_p(pic_state *pic, pic_sym sym)
{