diff options
author | David Robillard <d@drobilla.net> | 2009-03-15 15:16:09 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2009-03-15 15:16:09 +0000 |
commit | 52ae7f1842e0f079152902ee73008a2a00aaeb3f (patch) | |
tree | 6e511b17cd3f6a06936ea53fa52110706e52ae61 /tuplr.hpp | |
parent | 0bd85b083b35ec9287462ca42fba45dc7af48797 (diff) | |
download | resp-52ae7f1842e0f079152902ee73008a2a00aaeb3f.tar.gz resp-52ae7f1842e0f079152902ee73008a2a00aaeb3f.tar.bz2 resp-52ae7f1842e0f079152902ee73008a2a00aaeb3f.zip |
Set name of closures so defined functions are emitted with meaningful names.
git-svn-id: http://svn.drobilla.net/resp/tuplr@103 ad02d1e2-f140-0410-9f75-f8b11f17cedd
Diffstat (limited to 'tuplr.hpp')
-rw-r--r-- | tuplr.hpp | 34 |
1 files changed, 12 insertions, 22 deletions
@@ -146,10 +146,11 @@ extern ostream& operator<<(ostream& out, const AST* ast); struct AST { AST(Cursor c=Cursor()) : loc(c) {} virtual ~AST() {} - virtual bool operator==(const AST& o) const = 0; - virtual bool contains(const AST* child) const { return false; } - virtual void constrain(TEnv& tenv, Constraints& c) const {} - virtual void lift(CEnv& cenv) {} + virtual bool operator==(const AST& o) const = 0; + virtual bool contains(const AST* child) const { return false; } + virtual void constrain(TEnv& tenv, Constraints& c) const {} + virtual void lift(CEnv& cenv) {} + virtual CValue compile(CEnv& cenv) = 0; string str() const { ostringstream ss; ss << this; return ss.str(); } template<typename T> T as() { T t = dynamic_cast<T>(this); @@ -157,9 +158,6 @@ struct AST { return t; } Cursor loc; -private: - friend class CEnv; - virtual CValue compile(CEnv& cenv) = 0; }; /// Literal value @@ -180,12 +178,11 @@ struct ASymbol : public AST { bool operator==(const AST& rhs) const { return this == &rhs; } void constrain(TEnv& tenv, Constraints& c) const; CValue compile(CEnv& cenv); - mutable LAddr addr; + mutable LAddr addr; + const string cppstr; private: friend class PEnv; 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)" @@ -208,10 +205,7 @@ struct ATuple : public AST, public vector<AST*> { return false; return true; } - void lift(CEnv& cenv) { - FOREACH(iterator, t, *this) - (*t)->lift(cenv); - } + void lift(CEnv& cenv) { FOREACH(iterator, t, *this) (*t)->lift(cenv); } bool contains(AST* child) const { if (*this == *child) return true; FOREACH(const_iterator, p, *this) @@ -300,10 +294,9 @@ struct AClosure : public ATuple { void liftCall(CEnv& cenv, const vector<AType*>& argsT); CValue compile(CEnv& cenv); ATuple* prot() const { return dynamic_cast<ATuple*>(at(1)); } - Funcs funcs; - mutable Subst* subst; -private: - string name; + Funcs funcs; + mutable Subst* subst; + string name; }; /// Function call/application, e.g. "(func arg1 arg2)" @@ -488,10 +481,7 @@ struct TEnv : public Env< const ASymbol*, pair<AST*, AType*> > { } AST* resolve(AST* ast) { ASymbol* sym = dynamic_cast<ASymbol*>(ast); - if (sym) - return ref(sym)->first; - else - return ast; + return sym ? ref(sym)->first : ast; } static Subst unify(const Constraints& c); |