Garbage-collect dictionaries properly
This commit is contained in:
parent
737dc03054
commit
1f14624664
3 changed files with 15 additions and 2 deletions
|
@ -146,7 +146,7 @@ Result<PodObject*> Arena::gc_pair(PodPair* obj) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Result<PodObject*> Arena::gc_array(PodArray* obj) {
|
Result<PodObject*> Arena::gc_array(PodArray* obj) {
|
||||||
auto nobj = TRY(alloc<PodArray>(obj->size));
|
auto nobj = TRY(alloc<PodArray>(sizeof(OffPtr<PodObject>) * obj->size));
|
||||||
nobj->header.tag = Tag::Array;
|
nobj->header.tag = Tag::Array;
|
||||||
nobj->size = obj->size;
|
nobj->size = obj->size;
|
||||||
for (uint64_t i = 0; i < obj->size; i++) {
|
for (uint64_t i = 0; i < obj->size; i++) {
|
||||||
|
@ -165,5 +165,13 @@ Result<PodObject*> Arena::gc_bytearray(PodByteArray* obj) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Result<PodObject*> Arena::gc_dict(PodDict* obj) {
|
Result<PodObject*> Arena::gc_dict(PodDict* obj) {
|
||||||
return ErrorCode::NotImplemented;
|
auto nobj = TRY(alloc<PodDict>(obj->size * 2 * sizeof(OffPtr<PodObject>)));
|
||||||
|
nobj->header.tag = Tag::Dict;
|
||||||
|
nobj->size = obj->size;
|
||||||
|
for (uint64_t i = 0; i < obj->size * 2; i++) {
|
||||||
|
PodObject* val = obj->data[i].get(obj);
|
||||||
|
nobj->data[i] = OffPtr<PodObject>(nobj, TRY(gc_pod(val)));
|
||||||
|
}
|
||||||
|
return nobj;
|
||||||
|
// return ErrorCode::NotImplemented;
|
||||||
}
|
}
|
||||||
|
|
|
@ -216,6 +216,7 @@ Result<Dict> Dict::insert(Arena& arena, Value& key, Value& value) {
|
||||||
}
|
}
|
||||||
|
|
||||||
auto pod = TRY(arena.alloc<PodDict>(2 * s * sizeof(OffPtr<PodObject>)));
|
auto pod = TRY(arena.alloc<PodDict>(2 * s * sizeof(OffPtr<PodObject>)));
|
||||||
|
pod->header.tag = Tag::Dict;
|
||||||
pod->size = s;
|
pod->size = s;
|
||||||
|
|
||||||
auto vpod = _value.get();
|
auto vpod = _value.get();
|
||||||
|
|
|
@ -15,7 +15,11 @@ TEST_CASE(dict_insert) {
|
||||||
d = DIEX(d.insert(arena, 0, 5));
|
d = DIEX(d.insert(arena, 0, 5));
|
||||||
d = DIEX(d.insert(arena, 2, 6));
|
d = DIEX(d.insert(arena, 2, 6));
|
||||||
|
|
||||||
|
DIEX(arena.gc());
|
||||||
|
|
||||||
auto s = DIEX(write_one(arena, d));
|
auto s = DIEX(write_one(arena, d));
|
||||||
|
|
||||||
|
DIEX(arena.gc());
|
||||||
|
|
||||||
ASSERT_EQUALS(s, "{0 5 1 3 2 6 3 3}");
|
ASSERT_EQUALS(s, "{0 5 1 3 2 6 3 3}");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue