From 11a8a861a1f026a9c1869fc1a164dfb62fbcb956 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Fri, 6 Mar 2009 01:23:48 +0000 Subject: Tidy. git-svn-id: http://svn.drobilla.net/resp/tuplr@53 ad02d1e2-f140-0410-9f75-f8b11f17cedd --- tuplr.hpp | 51 ++++++++++++++++++++++++++------------------------- 1 file changed, 26 insertions(+), 25 deletions(-) (limited to 'tuplr.hpp') diff --git a/tuplr.hpp b/tuplr.hpp index 37d8ad8..d253a49 100644 --- a/tuplr.hpp +++ b/tuplr.hpp @@ -88,11 +88,11 @@ struct CEnv; ///< Compile-Time Environment /// Base class for all AST nodes struct AST { virtual ~AST() {} - virtual string str() const = 0; - virtual bool operator==(const AST& o) const = 0; - virtual bool contains(AST* child) const { return false; } - virtual void constrain(TEnv& tenv) const {} - virtual void lift(CEnv& cenv) {} + virtual string str() const = 0; + virtual bool operator==(const AST& o) const = 0; + virtual bool contains(AST* child) const { return false; } + virtual void constrain(TEnv& tenv) const {} + virtual void lift(CEnv& cenv) {} virtual CValue compile(CEnv& cenv) = 0; }; @@ -104,8 +104,8 @@ struct ASTLiteral : public AST { const ASTLiteral* r = dynamic_cast*>(&rhs); return (r && (val == r->val)); } - string str() const { return (format("%1%") % val).str(); } - void constrain(TEnv& tenv) const; + string str() const { return (format("%1%") % val).str(); } + void constrain(TEnv& tenv) const; CValue compile(CEnv& cenv); const VT val; }; @@ -113,8 +113,8 @@ struct ASTLiteral : public AST { /// Symbol, e.g. "a" struct ASTSymbol : public AST { ASTSymbol(const string& s, Cursor c=Cursor()) : loc(c), cppstr(s) {} - bool operator==(const AST& rhs) const { return this == &rhs; } - string str() const { return cppstr; } + bool operator==(const AST& rhs) const { return this == &rhs; } + string str() const { return cppstr; } CValue compile(CEnv& cenv); private: Cursor loc; @@ -156,8 +156,8 @@ struct ASTTuple : public AST, public vector { FOREACH(iterator, t, *this) (*t)->lift(cenv); } - bool contains(AST* child) const; - void constrain(TEnv& tenv) const; + bool contains(AST* child) const; + void constrain(TEnv& tenv) const; CValue compile(CEnv& cenv) { throw Error("tuple compiled"); } }; @@ -174,9 +174,9 @@ struct AType : public ASTTuple { } return ""; // never reached } - void constrain(TEnv& tenv) const {} + void constrain(TEnv& tenv) const {} CValue compile(CEnv& cenv) { return NULL; } - bool var() const { return kind == VAR; } + bool var() const { return kind == VAR; } bool concrete() const { switch (kind) { case VAR: return false; @@ -233,7 +233,7 @@ struct ASTClosure : public ASTTuple { string str() const { return (format("%1%") % this).str(); } void constrain(TEnv& tenv) const; void lift(CEnv& cenv); - CValue compile(CEnv& cenv); + CValue compile(CEnv& cenv); ASTTuple* prot() const { return dynamic_cast(at(1)); } private: Funcs funcs; @@ -243,8 +243,8 @@ private: /// Function call/application, e.g. "(func arg1 arg2)" struct ASTCall : public ASTTuple { ASTCall(const SExp& e, const ASTTuple& t) : ASTTuple(t), exp(e) {} - void constrain(TEnv& tenv) const; - void lift(CEnv& cenv); + void constrain(TEnv& tenv) const; + void lift(CEnv& cenv); CValue compile(CEnv& cenv); const SExp& exp; }; @@ -252,22 +252,22 @@ struct ASTCall : public ASTTuple { /// Definition special form, e.g. "(def x 2)" struct ASTDefinition : public ASTCall { ASTDefinition(const SExp& e, const ASTTuple& t, CArg ca=CArg()) : ASTCall(e, t) {} - void constrain(TEnv& tenv) const; - void lift(CEnv& cenv); + void constrain(TEnv& tenv) const; + void lift(CEnv& cenv); CValue compile(CEnv& cenv); }; /// Conditional special form, e.g. "(if cond thenexp elseexp)" struct ASTIf : public ASTCall { ASTIf(const SExp& e, const ASTTuple& t, CArg ca=CArg()) : ASTCall(e, t) {} - void constrain(TEnv& tenv) const; + void constrain(TEnv& tenv) const; CValue compile(CEnv& cenv); }; /// Primitive (builtin arithmetic function), e.g. "(+ 2 3)" struct ASTPrimitive : public ASTCall { ASTPrimitive(const SExp& e, const ASTTuple& t, CArg ca=CArg()) : ASTCall(e, t), arg(ca) {} - void constrain(TEnv& tenv) const; + void constrain(TEnv& tenv) const; CValue compile(CEnv& cenv); CArg arg; }; @@ -275,9 +275,9 @@ struct ASTPrimitive : public ASTCall { /// Cons special form, e.g. "(cons 1 2)" struct ASTConsCall : public ASTCall { ASTConsCall(const SExp& e, const ASTTuple& t, CArg ca=CArg()) : ASTCall(e, t) {} - AType* functionType(CEnv& cenv); - void constrain(TEnv& tenv) const; - void lift(CEnv& cenv); + AType* functionType(CEnv& cenv); + void constrain(TEnv& tenv) const; + void lift(CEnv& cenv); CValue compile(CEnv& cenv); static Funcs funcs; }; @@ -285,14 +285,14 @@ struct ASTConsCall : public ASTCall { /// Car special form, e.g. "(car p)" struct ASTCarCall : public ASTCall { ASTCarCall(const SExp& e, const ASTTuple& t, CArg ca=CArg()) : ASTCall(e, t) {} - void constrain(TEnv& tenv) const; + void constrain(TEnv& tenv) const; CValue compile(CEnv& cenv); }; /// Cdr special form, e.g. "(cdr p)" struct ASTCdrCall : public ASTCall { ASTCdrCall(const SExp& e, const ASTTuple& t, CArg ca=CArg()) : ASTCall(e, t) {} - void constrain(TEnv& tenv) const; + void constrain(TEnv& tenv) const; CValue compile(CEnv& cenv); }; @@ -428,6 +428,7 @@ struct TEnv : public Env { void solve() { apply(unify(constraints)); } void apply(const TSubst& substs); static TSubst unify(const Constraints& c); + PEnv& penv; Constraints constraints; unsigned varID; -- cgit v1.2.1