Skip to content

Commit

Permalink
Dicts are now garbage collected
Browse files Browse the repository at this point in the history
  • Loading branch information
gvx committed Feb 10, 2012
1 parent 82f41d1 commit 02b637e
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions vm/gc.c
Expand Up @@ -47,6 +47,7 @@ void free_value(V t)
Bucket* b;
Bucket* bb;
File* f;
HashMap* hm;
int n;
switch (getType(t))
{
Expand All @@ -61,6 +62,24 @@ void free_value(V t)
while (pop(s));
free(s);
break;
case T_DICT:
hm = toHashMap(t);
if (hm->map != NULL)
{
for (n = 0; n < hm->size; n++)
{
b = hm->map[n];
while(b != NULL)
{
bb = b;
b = b->next;
free(bb);
}
}
free(hm->map);
}
free(hm);
break;
case T_SCOPE:
sc = toScope(t);
if (sc->hm.map != NULL)
Expand Down Expand Up @@ -99,6 +118,7 @@ void iter_children(V t, void (*iter)(V))
Scope* sc;
Bucket* b;
File* f;
HashMap* hm;
V child;
int i;
switch (getType(t))
Expand All @@ -120,6 +140,20 @@ void iter_children(V t, void (*iter)(V))
iter(child);
}
break;
case T_DICT:
hm = toHashMap(t);
if (hm->map != NULL)
{
for (i = 0; i < hm->size; i++)
{
b = hm->map[i];
while(b != NULL)
{
iter(b->value);
b = b->next;
}
}
}
case T_SCOPE:
sc = toScope(t);
if (sc->parent && toScope(sc->parent)->parent)
Expand Down

0 comments on commit 02b637e

Please sign in to comment.