change pic_intern interface
This commit is contained in:
parent
09cb576a3b
commit
4be979b1df
|
@ -175,8 +175,7 @@ bool pic_eq_p(pic_value, pic_value);
|
||||||
bool pic_eqv_p(pic_value, pic_value);
|
bool pic_eqv_p(pic_value, pic_value);
|
||||||
bool pic_equal_p(pic_state *, pic_value, pic_value);
|
bool pic_equal_p(pic_state *, pic_value, pic_value);
|
||||||
|
|
||||||
pic_sym pic_intern(pic_state *, const char *, size_t);
|
pic_sym pic_intern(pic_state *, pic_str *);
|
||||||
pic_sym pic_intern_str(pic_state *, pic_str *);
|
|
||||||
pic_sym pic_intern_cstr(pic_state *, const char *);
|
pic_sym pic_intern_cstr(pic_state *, const char *);
|
||||||
const char *pic_symbol_name(pic_state *, pic_sym);
|
const char *pic_symbol_name(pic_state *, pic_sym);
|
||||||
pic_sym pic_gensym(pic_state *, pic_sym);
|
pic_sym pic_gensym(pic_state *, pic_sym);
|
||||||
|
|
|
@ -104,7 +104,7 @@ import_table(pic_state *pic, pic_value spec, struct pic_dict *imports)
|
||||||
|
|
||||||
prefix = pic_list_ref(pic, spec, 2);
|
prefix = pic_list_ref(pic, spec, 2);
|
||||||
pic_dict_for_each (sym, table) {
|
pic_dict_for_each (sym, table) {
|
||||||
id = pic_intern_str(pic, pic_format(pic, "~s~s", prefix, pic_sym_value(sym)));
|
id = pic_intern(pic, pic_format(pic, "~s~s", prefix, pic_sym_value(sym)));
|
||||||
pic_dict_set(pic, imports, id, pic_dict_ref(pic, table, sym));
|
pic_dict_set(pic, imports, id, pic_dict_ref(pic, table, sym));
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -222,7 +222,8 @@ read_symbol(pic_state *pic, struct pic_port *port, const char *str)
|
||||||
buf[len - 1] = (char)c;
|
buf[len - 1] = (char)c;
|
||||||
}
|
}
|
||||||
|
|
||||||
sym = pic_intern(pic, buf, len);
|
buf[len] = 0;
|
||||||
|
sym = pic_intern_cstr(pic, buf);
|
||||||
pic_free(pic, buf);
|
pic_free(pic, buf);
|
||||||
|
|
||||||
return pic_sym_value(sym);
|
return pic_sym_value(sym);
|
||||||
|
|
|
@ -6,21 +6,20 @@
|
||||||
#include "picrin/string.h"
|
#include "picrin/string.h"
|
||||||
|
|
||||||
pic_sym
|
pic_sym
|
||||||
pic_intern(pic_state *pic, const char *str, size_t len)
|
pic_intern(pic_state *pic, pic_str *str)
|
||||||
{
|
{
|
||||||
char *cstr;
|
char *cstr;
|
||||||
xh_entry *e;
|
xh_entry *e;
|
||||||
pic_sym id;
|
pic_sym id;
|
||||||
|
|
||||||
cstr = (char *)pic_malloc(pic, len + 1);
|
e = xh_get_str(&pic->syms, pic_str_cstr(str));
|
||||||
cstr[len] = '\0';
|
|
||||||
memcpy(cstr, str, len);
|
|
||||||
|
|
||||||
e = xh_get_str(&pic->syms, cstr);
|
|
||||||
if (e) {
|
if (e) {
|
||||||
return xh_val(e, pic_sym);
|
return xh_val(e, pic_sym);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cstr = (char *)pic_malloc(pic, pic_strlen(str) + 1);
|
||||||
|
strcpy(cstr, pic_str_cstr(str));
|
||||||
|
|
||||||
id = pic->sym_cnt++;
|
id = pic->sym_cnt++;
|
||||||
xh_put_str(&pic->syms, cstr, &id);
|
xh_put_str(&pic->syms, cstr, &id);
|
||||||
xh_put_int(&pic->sym_names, id, &cstr);
|
xh_put_int(&pic->sym_names, id, &cstr);
|
||||||
|
@ -30,13 +29,7 @@ pic_intern(pic_state *pic, const char *str, size_t len)
|
||||||
pic_sym
|
pic_sym
|
||||||
pic_intern_cstr(pic_state *pic, const char *str)
|
pic_intern_cstr(pic_state *pic, const char *str)
|
||||||
{
|
{
|
||||||
return pic_intern(pic, str, strlen(str));
|
return pic_intern(pic, pic_make_str(pic, str, strlen(str)));
|
||||||
}
|
|
||||||
|
|
||||||
pic_sym
|
|
||||||
pic_intern_str(pic_state *pic, pic_str *str)
|
|
||||||
{
|
|
||||||
return pic_intern_cstr(pic, pic_str_cstr(str));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pic_sym
|
pic_sym
|
||||||
|
|
Loading…
Reference in New Issue