diff --git a/src/arena.cpp b/src/arena.cpp index 3838c46..5dc31b8 100644 --- a/src/arena.cpp +++ b/src/arena.cpp @@ -146,7 +146,7 @@ Result Arena::gc_pair(PodPair* obj) { } Result Arena::gc_array(PodArray* obj) { - auto nobj = TRY(alloc(obj->size)); + auto nobj = TRY(alloc(sizeof(OffPtr) * obj->size)); nobj->header.tag = Tag::Array; nobj->size = obj->size; for (uint64_t i = 0; i < obj->size; i++) { @@ -165,5 +165,13 @@ Result Arena::gc_bytearray(PodByteArray* obj) { } Result Arena::gc_dict(PodDict* obj) { - return ErrorCode::NotImplemented; + auto nobj = TRY(alloc(obj->size * 2 * sizeof(OffPtr))); + 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(nobj, TRY(gc_pod(val))); + } + return nobj; + // return ErrorCode::NotImplemented; } diff --git a/src/common.cpp b/src/common.cpp index 287cc90..abc5f74 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -216,6 +216,7 @@ Result Dict::insert(Arena& arena, Value& key, Value& value) { } auto pod = TRY(arena.alloc(2 * s * sizeof(OffPtr))); + pod->header.tag = Tag::Dict; pod->size = s; auto vpod = _value.get(); diff --git a/test/dict.cpp b/test/dict.cpp index 0ed6494..52c4f4c 100644 --- a/test/dict.cpp +++ b/test/dict.cpp @@ -15,7 +15,11 @@ TEST_CASE(dict_insert) { d = DIEX(d.insert(arena, 0, 5)); d = DIEX(d.insert(arena, 2, 6)); + DIEX(arena.gc()); + auto s = DIEX(write_one(arena, d)); + DIEX(arena.gc()); + ASSERT_EQUALS(s, "{0 5 1 3 2 6 3 3}"); }