aboutsummaryrefslogtreecommitdiffstats
path: root/tuplr.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'tuplr.hpp')
-rw-r--r--tuplr.hpp34
1 files changed, 12 insertions, 22 deletions
diff --git a/tuplr.hpp b/tuplr.hpp
index 21ed121..3e051c1 100644
--- a/tuplr.hpp
+++ b/tuplr.hpp
@@ -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);