From cabae2767bfb3366eb6222137617ad147016b947 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Sun, 18 Jan 2015 21:58:40 +0900 Subject: [PATCH] use dictionary for senv->map --- extlib/benz/gc.c | 3 +-- extlib/benz/include/picrin/macro.h | 2 +- extlib/benz/macro.c | 17 +++++++---------- 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/extlib/benz/gc.c b/extlib/benz/gc.c index 678b1964..9c005479 100644 --- a/extlib/benz/gc.c +++ b/extlib/benz/gc.c @@ -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(pic, senv->defer); + gc_mark_object(pic, (struct pic_object *)senv->map); break; } case PIC_TT_LIB: { @@ -633,8 +634,6 @@ gc_finalize_object(pic_state *pic, struct pic_object *obj) break; } case PIC_TT_SENV: { - struct pic_senv *senv = (struct pic_senv *)obj; - xh_destroy(&senv->map); break; } case PIC_TT_LIB: { diff --git a/extlib/benz/include/picrin/macro.h b/extlib/benz/include/picrin/macro.h index fe4074f5..e79c4251 100644 --- a/extlib/benz/include/picrin/macro.h +++ b/extlib/benz/include/picrin/macro.h @@ -11,7 +11,7 @@ extern "C" { struct pic_senv { PIC_OBJECT_HEADER - xhash map; + struct pic_dict *map; pic_value defer; struct pic_senv *up; }; diff --git a/extlib/benz/macro.c b/extlib/benz/macro.c index 7e1c7b36..87dea7c1 100644 --- a/extlib/benz/macro.c +++ b/extlib/benz/macro.c @@ -25,23 +25,17 @@ pic_add_rename(pic_state *pic, struct pic_senv *senv, pic_sym sym) void pic_put_rename(pic_state *pic, struct pic_senv *senv, pic_sym sym, pic_sym rename) { - PIC_UNUSED(pic); - - xh_put_int(&senv->map, sym, &rename); + pic_dict_set(pic, senv->map, sym, pic_sym_value(rename)); } bool pic_find_rename(pic_state *pic, struct pic_senv *senv, pic_sym sym, pic_sym *rename) { - xh_entry *e; - - PIC_UNUSED(pic); - - if ((e = xh_get_int(&senv->map, sym)) == NULL) { + if (! pic_dict_has(pic, senv->map, sym)) { return false; } if (rename != NULL) { - *rename = xh_val(e, pic_sym); + *rename = pic_sym(pic_dict_ref(pic, senv->map, sym)); } return true; } @@ -383,11 +377,14 @@ struct pic_senv * pic_make_senv(pic_state *pic, struct pic_senv *up) { 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->up = up; senv->defer = pic_nil_value(); - xh_init_int(&senv->map, sizeof(pic_sym)); + senv->map = map; return senv; }