aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/constrain.cpp2
-rw-r--r--src/lex.cpp2
-rw-r--r--src/llvm.cpp6
-rw-r--r--src/parse.cpp1
-rw-r--r--src/pprint.cpp2
-rw-r--r--src/repl.cpp6
-rw-r--r--src/tuplr.cpp1
-rw-r--r--src/tuplr.hpp17
-rw-r--r--src/unify.cpp15
-rw-r--r--tuplr.dox6
10 files changed, 33 insertions, 25 deletions
diff --git a/src/constrain.cpp b/src/constrain.cpp
index a1868c4..534c77d 100644
--- a/src/constrain.cpp
+++ b/src/constrain.cpp
@@ -97,7 +97,7 @@ AFn::constrain(TEnv& tenv, Constraints& c) const
at(i)->constrain(tenv, cp);
AType* bodyT = tenv.var(at(e-1));
- Subst tsubst = TEnv::unify(cp);
+ Subst tsubst = unify(cp);
genericType = tup<AType>(loc, tenv.penv.sym("Fn"),
tsubst.apply(protT), tsubst.apply(bodyT), 0);
tenv.genericTypes.insert(make_pair(this, genericType));
diff --git a/src/lex.cpp b/src/lex.cpp
index 81dbe19..dc7bd4a 100644
--- a/src/lex.cpp
+++ b/src/lex.cpp
@@ -16,7 +16,6 @@
*/
/** @file
-
* @brief Lexing (build a SExp from a string)
*/
@@ -36,6 +35,7 @@ readChar(Cursor& cur, istream& in)
return ch;
}
+/// Read an expression from @a in
SExp
readExpression(Cursor& cur, istream& in)
{
diff --git a/src/llvm.cpp b/src/llvm.cpp
index b89973d..54a3c66 100644
--- a/src/llvm.cpp
+++ b/src/llvm.cpp
@@ -193,14 +193,14 @@ llEngine(CEnv& cenv)
return reinterpret_cast<LLVMEngine*>(cenv.engine());
}
-/// Shared library entry point
+/// Create a new Engine (shared library entry point)
Engine*
tuplr_new_engine()
{
return new LLVMEngine();
}
-/// Shared library entry point
+/// Free an Engine (shared library entry point)
void
tuplr_free_engine(Engine* engine)
{
@@ -219,7 +219,7 @@ ALiteral<CT>::constrain(TEnv& tenv, Constraints& c) const { \
c.constrain(tenv, this, tenv.named(NAME)); \
}
-/// Literal template instantiations
+// Literal template instantiations
LITERAL(int32_t, "Int", ConstantInt::get(Type::Int32Ty, val, true))
LITERAL(float, "Float", ConstantFP::get(Type::FloatTy, val))
LITERAL(bool, "Bool", ConstantInt::get(Type::Int1Ty, val, false))
diff --git a/src/parse.cpp b/src/parse.cpp
index ae34778..c557c66 100644
--- a/src/parse.cpp
+++ b/src/parse.cpp
@@ -90,6 +90,7 @@ parseFn(PEnv& penv, const SExp& exp, void* arg)
* Language Definition *
***************************************************************************/
+/// Set up language
void
initLang(PEnv& penv, TEnv& tenv)
{
diff --git a/src/pprint.cpp b/src/pprint.cpp
index f156462..adf4ece 100644
--- a/src/pprint.cpp
+++ b/src/pprint.cpp
@@ -92,10 +92,10 @@ pprint_internal(ostream& out, const AST* ast, unsigned indent)
}
}
+/// Pretty-print @a ast to @a out
void
pprint(ostream& out, const AST* ast)
{
pprint_internal(out, ast, 0);
out << endl;
}
-
diff --git a/src/repl.cpp b/src/repl.cpp
index df85293..1ec1834 100644
--- a/src/repl.cpp
+++ b/src/repl.cpp
@@ -26,6 +26,7 @@
using namespace std;
+/// Compile and evaluate code from @a is
int
eval(CEnv& cenv, const string& name, istream& is)
{
@@ -42,7 +43,7 @@ eval(CEnv& cenv, const string& name, istream& is)
result = cenv.penv.parse(exp); // Parse input
Constraints c;
result->constrain(cenv.tenv, c); // Constrain types
- cenv.tsubst = Subst::compose(cenv.tsubst, TEnv::unify(c)); // Solve type constraints
+ cenv.tsubst = Subst::compose(cenv.tsubst, unify(c)); // Solve type constraints
resultType = cenv.type(result);
result->lift(cenv); // Lift functions
exprs.push_back(make_pair(exp, result));
@@ -91,6 +92,7 @@ eval(CEnv& cenv, const string& name, istream& is)
return 0;
}
+/// Read Eval Print Loop
int
repl(CEnv& cenv)
{
@@ -109,7 +111,7 @@ repl(CEnv& cenv)
body->constrain(cenv.tenv, c); // Constrain types
Subst oldSubst = cenv.tsubst;
- cenv.tsubst = Subst::compose(cenv.tsubst, TEnv::unify(c)); // Solve type constraints
+ cenv.tsubst = Subst::compose(cenv.tsubst, unify(c)); // Solve type constraints
AType* bodyT = cenv.type(body);
THROW_IF(!bodyT, cursor, "call to untyped body")
diff --git a/src/tuplr.cpp b/src/tuplr.cpp
index 3bd90f6..0b9344a 100644
--- a/src/tuplr.cpp
+++ b/src/tuplr.cpp
@@ -135,4 +135,3 @@ main(int argc, char** argv)
return ret;
}
-
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,
diff --git a/src/unify.cpp b/src/unify.cpp
index 0383df0..5d4121e 100644
--- a/src/unify.cpp
+++ b/src/unify.cpp
@@ -40,8 +40,9 @@ substitute(ATuple* tup, const AST* from, AST* to)
substitute(tup->at(i)->to<ATuple*>(), from, to);
}
+/// Compose two substitutions (TAPL 22.1.1)
Subst
-Subst::compose(const Subst& delta, const Subst& gamma) // TAPL 22.1.1
+Subst::compose(const Subst& delta, const Subst& gamma)
{
Subst r;
for (Subst::const_iterator g = gamma.begin(); g != gamma.end(); ++g) {
@@ -55,10 +56,11 @@ Subst::compose(const Subst& delta, const Subst& gamma) // TAPL 22.1.1
return r;
}
+/// Replace all occurrences of @a s with @a t
void
-substConstraints(Constraints& constraints, AType* s, AType* t)
+Constraints::replace(AType* s, AType* t)
{
- for (Constraints::iterator c = constraints.begin(); c != constraints.end();) {
+ for (Constraints::iterator c = begin(); c != end();) {
Constraints::iterator next = c; ++next;
if (*c->first == *s) c->first = t;
if (*c->second == *s) c->second = t;
@@ -68,8 +70,9 @@ substConstraints(Constraints& constraints, AType* s, AType* t)
}
}
+/// Unify a type constraint set (TAPL 22.4)
Subst
-TEnv::unify(const Constraints& constraints) // TAPL 22.4
+unify(const Constraints& constraints)
{
if (constraints.empty()) return Subst();
AType* s = constraints.begin()->first;
@@ -80,10 +83,10 @@ TEnv::unify(const Constraints& constraints) // TAPL 22.4
if (*s == *t) {
return unify(cp);
} else if (s->var() && !t->contains(s)) {
- substConstraints(cp, s, t);
+ cp.replace(s, t);
return Subst::compose(unify(cp), Subst(s, t));
} else if (t->var() && !s->contains(t)) {
- substConstraints(cp, t, s);
+ cp.replace(t, s);
return Subst::compose(unify(cp), Subst(t, s));
} else if (s->kind == AType::EXPR && s->kind == t->kind && s->size() == t->size()) {
for (size_t i = 0; i < s->size(); ++i) {
diff --git a/tuplr.dox b/tuplr.dox
index 9e793a7..c1f9d1e 100644
--- a/tuplr.dox
+++ b/tuplr.dox
@@ -297,7 +297,7 @@ SYMBOL_CACHE_SIZE = 0
# Private class members and static file members will be hidden unless
# the EXTRACT_PRIVATE and EXTRACT_STATIC tags are set to YES
-EXTRACT_ALL = YES
+EXTRACT_ALL = NO
# If the EXTRACT_PRIVATE tag is set to YES all private members of a class
# will be included in the documentation.
@@ -307,7 +307,7 @@ EXTRACT_PRIVATE = NO
# If the EXTRACT_STATIC tag is set to YES all static members of a file
# will be included in the documentation.
-EXTRACT_STATIC = YES
+EXTRACT_STATIC = NO
# If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs)
# defined locally in source files will be included in the documentation.
@@ -1403,7 +1403,7 @@ UML_LOOK = NO
# If set to YES, the inheritance and collaboration graphs will show the
# relations between templates and their instances.
-TEMPLATE_RELATIONS = NO
+TEMPLATE_RELATIONS = YES
# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDE_GRAPH, and HAVE_DOT
# tags are set to YES then doxygen will generate a graph for each documented