cleanup
This commit is contained in:
parent
f0434a8b37
commit
07fc2bb98e
|
@ -4,11 +4,12 @@ struct pic_data *
|
||||||
pic_data_alloc(pic_state *pic, const pic_data_type *type, void *userdata)
|
pic_data_alloc(pic_state *pic, const pic_data_type *type, void *userdata)
|
||||||
{
|
{
|
||||||
struct pic_data *data;
|
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 = (struct pic_data *)pic_obj_alloc(pic, sizeof(struct pic_data), PIC_TT_DATA);
|
||||||
data->type = type;
|
data->type = type;
|
||||||
data->data = userdata;
|
data->data = userdata;
|
||||||
xh_init_str(&data->storage, sizeof(pic_value));
|
data->storage = storage;
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
|
@ -238,12 +238,13 @@ pic_dict_dictionary_to_alist(pic_state *pic)
|
||||||
{
|
{
|
||||||
struct pic_dict *dict;
|
struct pic_dict *dict;
|
||||||
pic_value item, alist = pic_nil_value();
|
pic_value item, alist = pic_nil_value();
|
||||||
|
pic_sym *sym;
|
||||||
xh_entry *it;
|
xh_entry *it;
|
||||||
|
|
||||||
pic_get_args(pic, "d", &dict);
|
pic_get_args(pic, "d", &dict);
|
||||||
|
|
||||||
for (it = xh_begin(&dict->hash); it != NULL; it = xh_next(it)) {
|
pic_dict_for_each (sym, dict, it) {
|
||||||
item = pic_cons(pic, pic_obj_value(xh_key(it, pic_sym *)), xh_val(it, pic_value));
|
item = pic_cons(pic, pic_obj_value(sym), pic_dict_ref(pic, dict, sym));
|
||||||
pic_push(pic, item, alist);
|
pic_push(pic, item, alist);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -273,13 +274,14 @@ pic_dict_dictionary_to_plist(pic_state *pic)
|
||||||
{
|
{
|
||||||
struct pic_dict *dict;
|
struct pic_dict *dict;
|
||||||
pic_value plist = pic_nil_value();
|
pic_value plist = pic_nil_value();
|
||||||
|
pic_sym *sym;
|
||||||
xh_entry *it;
|
xh_entry *it;
|
||||||
|
|
||||||
pic_get_args(pic, "d", &dict);
|
pic_get_args(pic, "d", &dict);
|
||||||
|
|
||||||
for (it = xh_begin(&dict->hash); it != NULL; it = xh_next(it)) {
|
pic_dict_for_each (sym, dict, it) {
|
||||||
pic_push(pic, pic_obj_value(xh_key(it, pic_sym *)), plist);
|
pic_push(pic, pic_obj_value(sym), plist);
|
||||||
pic_push(pic, xh_val(it, pic_value), plist);
|
pic_push(pic, pic_dict_ref(pic, dict, sym), plist);
|
||||||
}
|
}
|
||||||
|
|
||||||
return pic_reverse(pic, plist);
|
return pic_reverse(pic, plist);
|
||||||
|
|
|
@ -442,11 +442,8 @@ gc_mark_object(pic_state *pic, struct pic_object *obj)
|
||||||
}
|
}
|
||||||
case PIC_TT_DATA: {
|
case PIC_TT_DATA: {
|
||||||
struct pic_data *data = (struct pic_data *)obj;
|
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_object(pic, (struct pic_object *)data->storage);
|
||||||
gc_mark(pic, xh_val(it, pic_value));
|
|
||||||
}
|
|
||||||
if (data->type->mark) {
|
if (data->type->mark) {
|
||||||
data->type->mark(pic, data->data, gc_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: {
|
case PIC_TT_DICT: {
|
||||||
struct pic_dict *dict = (struct pic_dict *)obj;
|
struct pic_dict *dict = (struct pic_dict *)obj;
|
||||||
|
pic_sym *sym;
|
||||||
xh_entry *it;
|
xh_entry *it;
|
||||||
|
|
||||||
for (it = xh_begin(&dict->hash); it != NULL; it = xh_next(it)) {
|
pic_dict_for_each (sym, dict, it) {
|
||||||
gc_mark_object(pic, (struct pic_object *)xh_key(it, pic_sym *));
|
gc_mark_object(pic, (struct pic_object *)sym);
|
||||||
gc_mark(pic, xh_val(it, pic_value));
|
gc_mark(pic, pic_dict_ref(pic, dict, sym));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -705,7 +703,6 @@ gc_finalize_object(pic_state *pic, struct pic_object *obj)
|
||||||
if (data->type->dtor) {
|
if (data->type->dtor) {
|
||||||
data->type->dtor(pic, data->data);
|
data->type->dtor(pic, data->data);
|
||||||
}
|
}
|
||||||
xh_destroy(&data->storage);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case PIC_TT_DICT: {
|
case PIC_TT_DICT: {
|
||||||
|
|
|
@ -18,7 +18,7 @@ typedef struct {
|
||||||
struct pic_data {
|
struct pic_data {
|
||||||
PIC_OBJECT_HEADER
|
PIC_OBJECT_HEADER
|
||||||
const pic_data_type *type;
|
const pic_data_type *type;
|
||||||
xhash storage; /* const char * to pic_value table */
|
struct pic_dict *storage;
|
||||||
void *data;
|
void *data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -169,6 +169,7 @@ write_core(struct writer_control *p, pic_value obj)
|
||||||
pic_state *pic = p->pic;
|
pic_state *pic = p->pic;
|
||||||
xFILE *file = p->file;
|
xFILE *file = p->file;
|
||||||
size_t i;
|
size_t i;
|
||||||
|
pic_sym *sym;
|
||||||
xh_entry *e, *it;
|
xh_entry *e, *it;
|
||||||
int c;
|
int c;
|
||||||
#if PIC_ENABLE_FLOAT
|
#if PIC_ENABLE_FLOAT
|
||||||
|
@ -297,9 +298,9 @@ write_core(struct writer_control *p, pic_value obj)
|
||||||
break;
|
break;
|
||||||
case PIC_TT_DICT:
|
case PIC_TT_DICT:
|
||||||
xfprintf(pic, file, "#.(dictionary");
|
xfprintf(pic, file, "#.(dictionary");
|
||||||
for (it = xh_begin(&pic_dict_ptr(obj)->hash); it != NULL; it = xh_next(it)) {
|
pic_dict_for_each (sym, pic_dict_ptr(obj), it) {
|
||||||
xfprintf(pic, file, " '%s ", pic_symbol_name(pic, xh_key(it, pic_sym *)));
|
xfprintf(pic, file, " '%s ", pic_symbol_name(pic, sym));
|
||||||
write_core(p, xh_val(it, pic_value));
|
write_core(p, pic_dict_ref(pic, pic_dict_ptr(obj), sym));
|
||||||
}
|
}
|
||||||
xfprintf(pic, file, ")");
|
xfprintf(pic, file, ")");
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in New Issue