diff options
Diffstat (limited to 'src/gc.cpp')
-rw-r--r-- | src/gc.cpp | 19 |
1 files changed, 11 insertions, 8 deletions
@@ -44,6 +44,7 @@ GC::alloc(size_t size) size += sizeof(Object::Header); void* ret = tlsf_malloc((tlsf_t*)_pool, size); ((Object::Header*)ret)->mark = 0; + ((Object::Header*)ret)->tag = Object::AST; ret = (char*)ret + sizeof(Object::Header); _heap.push_back((Object*)ret); return ret; @@ -56,10 +57,12 @@ mark(const Object* obj) return; obj->mark(true); - const ATuple* tup = dynamic_cast<const ATuple*>((AST*)obj); - if (tup) - FOREACHP(ATuple::const_iterator, i, tup) - mark(*i); + if (obj->tag() == Object::AST) { + const ATuple* tup = ((const AST*)obj)->to<const ATuple*>(); + if (tup) + FOREACHP(ATuple::const_iterator, i, tup) + mark(*i); + } } void @@ -77,14 +80,14 @@ GC::collect(const Roots& roots) if ((*i)->marked()) { (*i)->mark(false); } else { - AST* ast = (AST*)*i; - if (!ast->to<AType*>()) { // FIXME - (ast)->~AST(); + if ((*i)->tag() == Object::AST) + ((AST*)*i)->~AST(); + tlsf_free((tlsf_t*)_pool, ((char*)(*i) - sizeof(Object::Header))); _heap.erase(i); - } } i = next; } + //std::cerr << "[GC] Collect " << oldSize << " => " << _heap.size() << endl; } |