diff options
Diffstat (limited to 'src/tuplr.hpp')
-rw-r--r-- | src/tuplr.hpp | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/src/tuplr.hpp b/src/tuplr.hpp index 4948b82..3579cca 100644 --- a/src/tuplr.hpp +++ b/src/tuplr.hpp @@ -185,7 +185,6 @@ struct Object { * Abstract Syntax Tree * ***************************************************************************/ -struct Constraint; ///< Type Constraint struct TEnv; ///< Type-Time Environment struct Constraints; ///< Type Constraints struct Subst; ///< Type substitutions @@ -227,16 +226,16 @@ static T* tup(Cursor c, AST* ast, ...) } /// Literal value -template<typename VT> +template<typename T> struct ALiteral : public AST { - ALiteral(VT v, Cursor c) : AST(c), val(v) {} + ALiteral(T v, Cursor c) : AST(c), val(v) {} bool operator==(const AST& rhs) const { - const ALiteral<VT>* r = rhs.to<const ALiteral<VT>*>(); + const ALiteral<T>* r = rhs.to<const ALiteral<T>*>(); return (r && (val == r->val)); } void constrain(TEnv& tenv, Constraints& c) const; CValue compile(CEnv& cenv); - const VT val; + const T val; }; /// Symbol, e.g. "a" @@ -524,13 +523,16 @@ struct PEnv : private map<const string, ASymbol*> { * Typing * ***************************************************************************/ +/// Type constraint struct Constraint : public pair<AType*,AType*> { Constraint(AType* a, AType* b, Cursor c) : pair<AType*,AType*>(a, b), loc(c) {} Cursor loc; }; +/// Type constraint set struct Constraints : public list<Constraint> { void constrain(TEnv& tenv, const AST* o, AType* t); + void replace(AType* s, AType* t); }; inline ostream& operator<<(ostream& out, const Constraints& c) { @@ -571,8 +573,6 @@ struct TEnv : public Env< const ASymbol*, pair<AST*, AType*> > { return (sym && sym->addr) ? ref(sym)->first : ast; } - static Subst unify(const Constraints& c); - typedef map<const AST*, AType*> Vars; typedef map<const AFn*, const AType*> GenericTypes; Vars vars; @@ -581,11 +581,14 @@ struct TEnv : public Env< const ASymbol*, pair<AST*, AType*> > { unsigned varID; }; +Subst unify(const Constraints& c); + /*************************************************************************** * Code Generation * ***************************************************************************/ +/// Compiler back-end struct Engine { virtual CFunction startFunction(CEnv& cenv, const std::string& name, const AType* retT, const ATuple& argsT, |