diff options
author | David Robillard <d@drobilla.net> | 2009-10-14 00:43:14 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2009-10-14 00:43:14 +0000 |
commit | 336648e6c68fb0d24d12e67e37c9398c01d09c34 (patch) | |
tree | 291b28073091b65d41a82e36853130ce3b7adfda /src | |
parent | ba3406f78e20f2e6a7fd6dbe28eb8de553cec9ae (diff) | |
download | resp-336648e6c68fb0d24d12e67e37c9398c01d09c34.tar.gz resp-336648e6c68fb0d24d12e67e37c9398c01d09c34.tar.bz2 resp-336648e6c68fb0d24d12e67e37c9398c01d09c34.zip |
Remove cruft.
git-svn-id: http://svn.drobilla.net/resp/tuplr@216 ad02d1e2-f140-0410-9f75-f8b11f17cedd
Diffstat (limited to 'src')
-rw-r--r-- | src/constrain.cpp | 18 | ||||
-rw-r--r-- | src/gc.cpp | 36 | ||||
-rw-r--r-- | src/parse.cpp | 2 | ||||
-rw-r--r-- | src/tuplr.hpp | 11 | ||||
-rw-r--r-- | src/tuplr_gc.cpp | 2 |
5 files changed, 22 insertions, 47 deletions
diff --git a/src/constrain.cpp b/src/constrain.cpp index 7106ec8..e5349d9 100644 --- a/src/constrain.cpp +++ b/src/constrain.cpp @@ -66,17 +66,15 @@ AFn::constrain(TEnv& tenv, Constraints& c) const if (gt != tenv.genericTypes.end()) { genericType = gt->second; } else { - set<const ASymbol*> defined; + set<const ASymbol*> defs; TEnv::Frame frame; // Add parameters to environment frame for (size_t i = 0; i < prot()->size(); ++i) { const ASymbol* sym = prot()->at(i)->to<const ASymbol*>(); - if (!sym) - throw Error(prot()->at(i)->loc, "parameter name is not a symbol"); - if (defined.find(sym) != defined.end()) - throw Error(sym->loc, (format("duplicate parameter `%1%'") % sym->str()).str()); - defined.insert(sym); + THROW_IF(!sym, prot()->at(i)->loc, "parameter name is not a symbol"); + THROW_IF(defs.count(sym) != 0, sym->loc, string("duplicate parameter `") + sym->str() + "'"); + defs.insert(sym); frame.push_back(make_pair(sym, make_pair((AST*)NULL, (AType*)NULL))); } @@ -87,9 +85,8 @@ AFn::constrain(TEnv& tenv, Constraints& c) const const ADef* def = exp->to<const ADef*>(); if (def) { const ASymbol* sym = def->sym(); - if (defined.find(sym) != defined.end()) - throw Error(def->loc, (format("`%1%' defined twice") % sym->str()).str()); - defined.insert(def->sym()); + THROW_IF(defs.count(sym) != 0, def->loc, (format("`%1%' defined twice") % sym->str()).str()); + defs.insert(def->sym()); frame.push_back(make_pair(def->sym(), make_pair(const_cast<AST*>(def->at(2)), (AType*)NULL))); } @@ -138,8 +135,7 @@ ACall::constrain(TEnv& tenv, Constraints& c) const const AST* callee = tenv.resolve(at(0)); const AFn* closure = callee->to<const AFn*>(); if (closure) { - if (size() - 1 != closure->prot()->size()) - throw Error(loc, "incorrect number of arguments"); + THROW_IF(size() - 1 != closure->prot()->size(), loc, "incorrect number of arguments"); TEnv::GenericTypes::iterator gt = tenv.genericTypes.find(closure); if (gt != tenv.genericTypes.end()) { const ATuple* prot = gt->second->at(1)->to<const ATuple*>(); @@ -38,13 +38,12 @@ GC::~GC() } void* -GC::alloc(size_t size, GC::Tag tag) +GC::alloc(size_t size) { size += (4 - (size % 4)); // Align to 32-bits size += sizeof(Object::Header); void* ret = tlsf_malloc((tlsf_t*)_pool, size); ((Object::Header*)ret)->mark = 0; - ((Object::Header*)ret)->tag = tag; ret = (char*)ret + sizeof(Object::Header); _heap.push_back((Object*)ret); return ret; @@ -57,16 +56,10 @@ mark(const Object* obj) return; obj->mark(true); - switch (obj->tag()) { - case GC::TAG_FRAME: - break; - case GC::TAG_AST: - const ATuple* tup = dynamic_cast<const ATuple*>((AST*)obj); - if (tup) - FOREACH(ATuple::const_iterator, i, *tup) - mark(*i); - break; - } + const ATuple* tup = dynamic_cast<const ATuple*>((AST*)obj); + if (tup) + FOREACH(ATuple::const_iterator, i, *tup) + mark(*i); } void @@ -78,26 +71,17 @@ GC::collect(const Roots& roots) mark(*i); for (Heap::iterator i = _heap.begin(); i != _heap.end();) { - assert((*i)->tag() == GC::TAG_AST || (*i)->tag() == GC::TAG_FRAME); Heap::iterator next = i; ++next; if ((*i)->marked()) { (*i)->mark(false); } else { - switch ((*i)->tag()) { - case GC::TAG_FRAME: - tlsf_free((tlsf_t*)_pool, (char*)(*i) - sizeof(Object::Header)); - _heap.erase(i); - break; - case GC::TAG_AST: - AST* ast = (AST*)*i; - if (!ast->to<AType*>()) { // FIXME - (ast)->~AST(); - tlsf_free((tlsf_t*)_pool, ((char*)(*i) - sizeof(Object::Header))); - _heap.erase(i); - } - break; + AST* ast = (AST*)*i; + if (!ast->to<AType*>()) { // FIXME + (ast)->~AST(); + tlsf_free((tlsf_t*)_pool, ((char*)(*i) - sizeof(Object::Header))); + _heap.erase(i); } } i = next; diff --git a/src/parse.cpp b/src/parse.cpp index 9d26652..9cf74e6 100644 --- a/src/parse.cpp +++ b/src/parse.cpp @@ -106,7 +106,7 @@ initLang(PEnv& penv, TEnv& tenv) tenv.def(penv.sym("Bool"), make_pair((AST*)0, new AType(penv.sym("Bool")))); tenv.def(penv.sym("Int"), make_pair((AST*)0, new AType(penv.sym("Int")))); tenv.def(penv.sym("Float"), make_pair((AST*)0, new AType(penv.sym("Float")))); - tenv.def(penv.sym("String"), make_pair((AST*)0, new AType(penv.sym("String")))); + tenv.def(penv.sym("String"), make_pair((AST*)0, new AType(penv.sym("String")))); // Literals static bool trueVal = true; diff --git a/src/tuplr.hpp b/src/tuplr.hpp index ada5412..f51db5e 100644 --- a/src/tuplr.hpp +++ b/src/tuplr.hpp @@ -107,18 +107,15 @@ typedef void* CFunc; ///< Compiled function (opaque) ***************************************************************************/ struct Object; +struct AType; /// Garbage collector struct GC { - enum Tag { - TAG_AST = 1, ///< Abstract syntax tree node - TAG_FRAME = 2 ///< Stack frame - }; typedef std::list<const Object*> Roots; typedef std::list<Object*> Heap; GC(size_t pool_size); ~GC(); - void* alloc(size_t size, Tag tag); + void* alloc(size_t size); void collect(const Roots& roots); void addRoot(const Object* obj) { assert(obj); _roots.push_back(obj); } void lock() { _roots.insert(_roots.end(), _heap.begin(), _heap.end()); } @@ -133,7 +130,6 @@ private: struct Object { struct Header { uint8_t mark; - uint8_t tag; }; /// Always allocated with pool.alloc, so this - sizeof(Header) is a valid Header*. @@ -141,9 +137,8 @@ struct Object { inline bool marked() const { return header()->mark != 0; } inline void mark(bool b) const { header()->mark = 1; } - inline GC::Tag tag() const { return (GC::Tag)header()->tag; } - static void* operator new(size_t size) { return pool.alloc(size, GC::TAG_AST); } + static void* operator new(size_t size) { return pool.alloc(size); } static void operator delete(void* ptr) {} static GC pool; }; diff --git a/src/tuplr_gc.cpp b/src/tuplr_gc.cpp index 8a0dd3e..d999e44 100644 --- a/src/tuplr_gc.cpp +++ b/src/tuplr_gc.cpp @@ -38,7 +38,7 @@ tuplr_gc_allocate(unsigned size, uint8_t tag) allocated = 0; } - return Object::pool.alloc(size, (GC::Tag)tag); + return Object::pool.alloc(size); } } |