This commit is contained in:
Yuichi Nishiwaki 2015-06-24 01:13:18 +09:00
parent f0434a8b37
commit 07fc2bb98e
5 changed files with 19 additions and 18 deletions

View File

@ -4,11 +4,12 @@ struct pic_data *
pic_data_alloc(pic_state *pic, const pic_data_type *type, void *userdata)
{
struct pic_data *data;
struct pic_dict *storage = pic_make_dict(pic);
data = (struct pic_data *)pic_obj_alloc(pic, sizeof(struct pic_data), PIC_TT_DATA);
data->type = type;
data->data = userdata;
xh_init_str(&data->storage, sizeof(pic_value));
data->storage = storage;
return data;
}

View File

@ -238,12 +238,13 @@ pic_dict_dictionary_to_alist(pic_state *pic)
{
struct pic_dict *dict;
pic_value item, alist = pic_nil_value();
pic_sym *sym;
xh_entry *it;
pic_get_args(pic, "d", &dict);
for (it = xh_begin(&dict->hash); it != NULL; it = xh_next(it)) {
item = pic_cons(pic, pic_obj_value(xh_key(it, pic_sym *)), xh_val(it, pic_value));
pic_dict_for_each (sym, dict, it) {
item = pic_cons(pic, pic_obj_value(sym), pic_dict_ref(pic, dict, sym));
pic_push(pic, item, alist);
}
@ -273,13 +274,14 @@ pic_dict_dictionary_to_plist(pic_state *pic)
{
struct pic_dict *dict;
pic_value plist = pic_nil_value();
pic_sym *sym;
xh_entry *it;
pic_get_args(pic, "d", &dict);
for (it = xh_begin(&dict->hash); it != NULL; it = xh_next(it)) {
pic_push(pic, pic_obj_value(xh_key(it, pic_sym *)), plist);
pic_push(pic, xh_val(it, pic_value), plist);
pic_dict_for_each (sym, dict, it) {
pic_push(pic, pic_obj_value(sym), plist);
pic_push(pic, pic_dict_ref(pic, dict, sym), plist);
}
return pic_reverse(pic, plist);

View File

@ -442,11 +442,8 @@ gc_mark_object(pic_state *pic, struct pic_object *obj)
}
case PIC_TT_DATA: {
struct pic_data *data = (struct pic_data *)obj;
xh_entry *it;
for (it = xh_begin(&data->storage); it != NULL; it = xh_next(it)) {
gc_mark(pic, xh_val(it, pic_value));
}
gc_mark_object(pic, (struct pic_object *)data->storage);
if (data->type->mark) {
data->type->mark(pic, data->data, gc_mark);
}
@ -454,11 +451,12 @@ gc_mark_object(pic_state *pic, struct pic_object *obj)
}
case PIC_TT_DICT: {
struct pic_dict *dict = (struct pic_dict *)obj;
pic_sym *sym;
xh_entry *it;
for (it = xh_begin(&dict->hash); it != NULL; it = xh_next(it)) {
gc_mark_object(pic, (struct pic_object *)xh_key(it, pic_sym *));
gc_mark(pic, xh_val(it, pic_value));
pic_dict_for_each (sym, dict, it) {
gc_mark_object(pic, (struct pic_object *)sym);
gc_mark(pic, pic_dict_ref(pic, dict, sym));
}
break;
}
@ -705,7 +703,6 @@ gc_finalize_object(pic_state *pic, struct pic_object *obj)
if (data->type->dtor) {
data->type->dtor(pic, data->data);
}
xh_destroy(&data->storage);
break;
}
case PIC_TT_DICT: {

View File

@ -18,7 +18,7 @@ typedef struct {
struct pic_data {
PIC_OBJECT_HEADER
const pic_data_type *type;
xhash storage; /* const char * to pic_value table */
struct pic_dict *storage;
void *data;
};

View File

@ -169,6 +169,7 @@ write_core(struct writer_control *p, pic_value obj)
pic_state *pic = p->pic;
xFILE *file = p->file;
size_t i;
pic_sym *sym;
xh_entry *e, *it;
int c;
#if PIC_ENABLE_FLOAT
@ -297,9 +298,9 @@ write_core(struct writer_control *p, pic_value obj)
break;
case PIC_TT_DICT:
xfprintf(pic, file, "#.(dictionary");
for (it = xh_begin(&pic_dict_ptr(obj)->hash); it != NULL; it = xh_next(it)) {
xfprintf(pic, file, " '%s ", pic_symbol_name(pic, xh_key(it, pic_sym *)));
write_core(p, xh_val(it, pic_value));
pic_dict_for_each (sym, pic_dict_ptr(obj), it) {
xfprintf(pic, file, " '%s ", pic_symbol_name(pic, sym));
write_core(p, pic_dict_ref(pic, pic_dict_ptr(obj), sym));
}
xfprintf(pic, file, ")");
break;