diff options
author | David Robillard <d@drobilla.net> | 2009-03-15 04:24:23 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2009-03-15 04:24:23 +0000 |
commit | e4943a76e19b442e4cd7b1cf921127ff633d9c13 (patch) | |
tree | a0260377d6ab834ac1a059937230186adbc8b806 /tuplr.hpp | |
parent | 361cf8ee32179f529555d992ffe17c89ca642ddb (diff) | |
download | resp-e4943a76e19b442e4cd7b1cf921127ff633d9c13.tar.gz resp-e4943a76e19b442e4cd7b1cf921127ff633d9c13.tar.bz2 resp-e4943a76e19b442e4cd7b1cf921127ff633d9c13.zip |
Fix polymorphism.
git-svn-id: http://svn.drobilla.net/resp/tuplr@95 ad02d1e2-f140-0410-9f75-f8b11f17cedd
Diffstat (limited to 'tuplr.hpp')
-rw-r--r-- | tuplr.hpp | 23 |
1 files changed, 19 insertions, 4 deletions
@@ -158,6 +158,9 @@ struct AST { if (!t) throw Error("internal error: bad cast", loc); return t; } + template<typename T> T* copy() { + return new T(static_cast<T*>(this)); + } Cursor loc; private: friend class CEnv; @@ -188,7 +191,6 @@ private: ASymbol(const string& s, Cursor c) : AST(c), cppstr(s) {} friend ostream& operator<<(ostream&, const AST*); const string cppstr; - }; /// Tuple (heterogeneous sequence of fixed length), e.g. "(a b c)" @@ -241,6 +243,20 @@ struct AType : public ATuple { push_back(a); va_end(args); } + AType(const AType& copy) : ATuple(0, copy.loc), kind(copy.kind), addr(copy.addr), id(copy.id) { + for (AType::const_iterator i = copy.begin(); i != copy.end(); ++i) { + AType* typ = dynamic_cast<AType*>(*i); + if (typ) { + push_back(new AType(*typ)); + continue; + } + ATuple* tup = dynamic_cast<ATuple*>(*i); + if (tup) + push_back(new ATuple(*tup)); + else + push_back(*i); + } + } CValue compile(CEnv& cenv) { return NULL; } bool var() const { return kind == VAR; } bool concrete() const { @@ -488,12 +504,11 @@ struct TEnv : public Env< const ASymbol*, pair<AST*, AType*> > { } static Subst unify(const Constraints& c); - typedef map<const AST*, AType*> Vars; - typedef map<const AClosure*, AType*> GenericTypes; + typedef map<const AST*, AType*> Vars; + typedef map<const AClosure*, const AType*> GenericTypes; Vars vars; GenericTypes genericTypes; PEnv& penv; - Constraints constraints; unsigned varID; }; |