aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm.cpp3
-rw-r--r--tuplr.cpp2
-rw-r--r--tuplr.hpp34
3 files changed, 16 insertions, 23 deletions
diff --git a/llvm.cpp b/llvm.cpp
index 0cd5199..64fc6a6 100644
--- a/llvm.cpp
+++ b/llvm.cpp
@@ -341,6 +341,9 @@ ADefinition::lift(CEnv& cenv)
{
// Define first for recursion
cenv.def(at(1)->as<ASymbol*>(), at(2), cenv.type(at(2)), NULL);
+ AClosure* c = dynamic_cast<AClosure*>(at(2));
+ if (c)
+ c->name = at(1)->str();
at(2)->lift(cenv);
}
diff --git a/tuplr.cpp b/tuplr.cpp
index 5124528..3b7cb81 100644
--- a/tuplr.cpp
+++ b/tuplr.cpp
@@ -188,7 +188,7 @@ print_usage(char* name, bool error)
{
ostream& os = error ? cerr : cout;
os << "Usage: " << name << " [OPTION]... [FILE]..." << endl;
- os << "Evaluate and/or compile Tuplr code" << endl;
+ os << "Evaluate and/or compile Tuplr code" << endl;
os << endl;
os << " -h Display this help and exit" << endl;
os << " -r Enter REPL after evaluating files" << endl;
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);