aboutsummaryrefslogtreecommitdiffstats
path: root/tuplr.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'tuplr.hpp')
-rw-r--r--tuplr.hpp23
1 files changed, 19 insertions, 4 deletions
diff --git a/tuplr.hpp b/tuplr.hpp
index 5e60e75..bcfdc86 100644
--- a/tuplr.hpp
+++ b/tuplr.hpp
@@ -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;
};