aboutsummaryrefslogtreecommitdiffstats
path: root/llvm.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm.cpp')
-rw-r--r--llvm.cpp25
1 files changed, 15 insertions, 10 deletions
diff --git a/llvm.cpp b/llvm.cpp
index 2493056..5d929a2 100644
--- a/llvm.cpp
+++ b/llvm.cpp
@@ -240,7 +240,7 @@ AClosure::liftCall(CEnv& cenv, const vector<AType*>& argsT)
{
TEnv::GenericTypes::const_iterator gt = cenv.tenv.genericTypes.find(this);
assert(gt != cenv.tenv.genericTypes.end());
- AType* genericType = gt->second;
+ AType* genericType = new AType(*gt->second, gt->second->loc);
// Find type and build substitution
assert(argsT.size() == prot()->size());
@@ -250,7 +250,7 @@ AClosure::liftCall(CEnv& cenv, const vector<AType*>& argsT)
for (size_t i = 0; i < argsT.size(); ++i)
argsSubst[dynamic_cast<AType*>(genericProtT->at(i))] = dynamic_cast<AType*>(argsT.at(i));
- AType* thisType = new AType(*dynamic_cast<ATuple*>(argsSubst.apply(genericType)), loc);
+ AType* thisType = argsSubst.apply(genericType)->as<AType*>();
if (!thisType->concrete())
throw Error("unable to resolve concrete type for function", loc);
@@ -333,13 +333,13 @@ ACall::lift(CEnv& cenv)
throw Error((format("too few arguments to function `%1%'") % at(0)->str()).str(), loc);
// Extend environment with bound and typed parameters
- cenv.push();
+ /*cenv.push();
for (size_t i = 1; i < size(); ++i)
- cenv.def(c->prot()->at(i-1)->as<ASymbol*>(), at(i), cenv.type(at(i)), NULL);
+ cenv.def(c->prot()->at(i-1)->as<ASymbol*>(), at(i), cenv.type(at(i)), NULL);*/
c->liftCall(cenv, argsT); // Lift called closure
- cenv.pop(); // Restore environment
+ //cenv.pop(); // Restore environment
}
CValue
@@ -355,8 +355,8 @@ ACall::compile(CEnv& cenv)
TEnv::GenericTypes::const_iterator gt = cenv.tenv.genericTypes.find(c);
assert(gt != cenv.tenv.genericTypes.end());
- AType* polyT = gt->second;
- AType* fnT = new AType(loc, cenv.penv.sym("Fn"), protT, polyT->at(2), 0);
+ const AType* polyT = gt->second;
+ AType* fnT = new AType(loc, cenv.penv.sym("Fn"), protT, polyT->at(2), 0);
Function* f = (Function*)c->funcs.find(fnT);
if (!f) throw Error("callee failed to compile", loc);
@@ -634,19 +634,23 @@ repl(CEnv& cenv)
cenv.out << "() ";
cenv.out.flush();
Cursor cursor("(stdin)");
- Constraints c;
+
try {
SExp exp = readExpression(cursor, std::cin);
if (exp.type == SExp::LIST && exp.list.empty())
break;
AST* body = cenv.penv.parse(exp); // Parse input
+ Constraints c;
body->constrain(cenv.tenv, c); // Constrain types
for (TEnv::GenericTypes::const_iterator i = cenv.tenv.genericTypes.begin();
- i != cenv.tenv.genericTypes.end(); ++i)
- c.push_back(Constraint(cenv.tenv.var(i->first), i->second, i->first->loc));
+ i != cenv.tenv.genericTypes.end(); ++i) {
+ c.push_back(Constraint(cenv.tenv.var(i->first),
+ new AType(*i->second), i->first->loc));
+ }
+ Subst oldSubst = cenv.tsubst;
cenv.tsubst = Subst::compose(cenv.tsubst, TEnv::unify(c)); // Solve type constraints
AType* bodyT = cenv.type(body);
@@ -670,6 +674,7 @@ repl(CEnv& cenv)
cenv.out << "; " << cenv.compile(body);
}
cenv.out << " : " << cenv.type(body) << endl;
+ cenv.tsubst = oldSubst;
} catch (Error& e) {
cenv.err << e.what() << endl;
}