use dictionary for senv->map

This commit is contained in:
Yuichi Nishiwaki 2015-01-18 21:58:40 +09:00
parent c1bba1ec83
commit cabae2767b
3 changed files with 9 additions and 13 deletions

View File

@ -422,6 +422,7 @@ gc_mark_object(pic_state *pic, struct pic_object *obj)
gc_mark_object(pic, (struct pic_object *)senv->up); gc_mark_object(pic, (struct pic_object *)senv->up);
} }
gc_mark(pic, senv->defer); gc_mark(pic, senv->defer);
gc_mark_object(pic, (struct pic_object *)senv->map);
break; break;
} }
case PIC_TT_LIB: { case PIC_TT_LIB: {
@ -633,8 +634,6 @@ gc_finalize_object(pic_state *pic, struct pic_object *obj)
break; break;
} }
case PIC_TT_SENV: { case PIC_TT_SENV: {
struct pic_senv *senv = (struct pic_senv *)obj;
xh_destroy(&senv->map);
break; break;
} }
case PIC_TT_LIB: { case PIC_TT_LIB: {

View File

@ -11,7 +11,7 @@ extern "C" {
struct pic_senv { struct pic_senv {
PIC_OBJECT_HEADER PIC_OBJECT_HEADER
xhash map; struct pic_dict *map;
pic_value defer; pic_value defer;
struct pic_senv *up; struct pic_senv *up;
}; };

View File

@ -25,23 +25,17 @@ pic_add_rename(pic_state *pic, struct pic_senv *senv, pic_sym sym)
void void
pic_put_rename(pic_state *pic, struct pic_senv *senv, pic_sym sym, pic_sym rename) pic_put_rename(pic_state *pic, struct pic_senv *senv, pic_sym sym, pic_sym rename)
{ {
PIC_UNUSED(pic); pic_dict_set(pic, senv->map, sym, pic_sym_value(rename));
xh_put_int(&senv->map, sym, &rename);
} }
bool bool
pic_find_rename(pic_state *pic, struct pic_senv *senv, pic_sym sym, pic_sym *rename) pic_find_rename(pic_state *pic, struct pic_senv *senv, pic_sym sym, pic_sym *rename)
{ {
xh_entry *e; if (! pic_dict_has(pic, senv->map, sym)) {
PIC_UNUSED(pic);
if ((e = xh_get_int(&senv->map, sym)) == NULL) {
return false; return false;
} }
if (rename != NULL) { if (rename != NULL) {
*rename = xh_val(e, pic_sym); *rename = pic_sym(pic_dict_ref(pic, senv->map, sym));
} }
return true; return true;
} }
@ -383,11 +377,14 @@ struct pic_senv *
pic_make_senv(pic_state *pic, struct pic_senv *up) pic_make_senv(pic_state *pic, struct pic_senv *up)
{ {
struct pic_senv *senv; struct pic_senv *senv;
struct pic_dict *map;
map = pic_make_dict(pic);
senv = (struct pic_senv *)pic_obj_alloc(pic, sizeof(struct pic_senv), PIC_TT_SENV); senv = (struct pic_senv *)pic_obj_alloc(pic, sizeof(struct pic_senv), PIC_TT_SENV);
senv->up = up; senv->up = up;
senv->defer = pic_nil_value(); senv->defer = pic_nil_value();
xh_init_int(&senv->map, sizeof(pic_sym)); senv->map = map;
return senv; return senv;
} }