aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm.cpp18
-rw-r--r--tuplr.hpp4
-rw-r--r--typing.cpp2
3 files changed, 12 insertions, 12 deletions
diff --git a/llvm.cpp b/llvm.cpp
index dcf8365..d04bd1b 100644
--- a/llvm.cpp
+++ b/llvm.cpp
@@ -56,7 +56,7 @@ lltype(const AType* t)
if (t->at(0)->str() == "Bool") return Type::Int1Ty;
if (t->at(0)->str() == "Int") return Type::Int32Ty;
if (t->at(0)->str() == "Float") return Type::FloatTy;
- throw Error(string("Unknown primitive type `") + t->str() + "'");
+ throw Error(string("Unknown primitive type `") + t->str() + "'", t->loc);
case AType::EXPR:
if (t->at(0)->str() == "Pair") {
vector<const Type*> types;
@@ -148,24 +148,24 @@ LITERAL(bool, "Bool", ConstantInt::get(Type::Int1Ty, val, false))
static Function*
compileFunction(CEnv& cenv, const std::string& name, const Type* retT, const ATuple& protT,
- const vector<string> argNames=vector<string>())
+ Cursor loc, const vector<string> argNames=vector<string>())
{
Function::LinkageTypes linkage = Function::ExternalLinkage;
vector<const Type*> cprot;
for (size_t i = 0; i < protT.size(); ++i) {
AType* at = protT.at(i)->as<AType*>();
- THROW_IF(!lltype(at), "function parameter is untyped")
+ THROW_IF(!lltype(at), "function parameter is untyped", protT.at(i)->loc)
cprot.push_back(lltype(at));
}
- THROW_IF(!retT, "function return is untyped")
+ THROW_IF(!retT, "function return is untyped", loc);
FunctionType* fT = FunctionType::get(static_cast<const Type*>(retT), cprot, false);
Function* f = Function::Create(fT, linkage, name, llengine(cenv)->module);
if (f->getName() != name) {
f->eraseFromParent();
- throw Error("function redefined");
+ throw Error("function redefined", loc);
}
// Set argument names in generated code
@@ -237,7 +237,7 @@ AClosure::liftCall(CEnv& cenv, const vector<AType*>& argsT)
string name = this->name == "" ? cenv.gensym("_fn") : this->name;
Function* f = compileFunction(cenv, name,
lltype(thisType->at(thisType->size()-1)->to<AType*>()),
- *protT);
+ *protT, loc);
cenv.push();
Subst oldSubst = cenv.tsubst;
@@ -467,7 +467,7 @@ AConsCall::lift(CEnv& cenv)
vector<string> argNames;
argNames.push_back("car");
argNames.push_back("cdr");
- Function* func = compileFunction(cenv, cenv.gensym("cons"), pT, *protT, argNames);
+ Function* func = compileFunction(cenv, cenv.gensym("cons"), pT, *protT, loc, argNames);
Value* mem = builder.CreateCall(LLVal(cenv.alloc), ConstantInt::get(Type::Int32Ty, sz), "mem");
Value* cell = builder.CreateBitCast(mem, pT, "cell");
@@ -563,7 +563,7 @@ eval(CEnv& cenv, const string& name, istream& is)
THROW_IF(!ctype, "body has non-compilable type", cursor)
// Create function for top-level of program
- Function* f = compileFunction(cenv, "main", ctype, ATuple(cursor));
+ Function* f = compileFunction(cenv, "main", ctype, ATuple(cursor), cursor);
// Compile all expressions into it
Value* val = NULL;
@@ -610,7 +610,7 @@ repl(CEnv& cenv)
if (lltype(bodyT)) {
// Create anonymous function to insert code into
- Function* f = compileFunction(cenv, cenv.gensym("_repl"), lltype(bodyT), ATuple(cursor));
+ Function* f = compileFunction(cenv, cenv.gensym("_repl"), lltype(bodyT), ATuple(cursor), cursor);
try {
Value* retVal = LLVal(cenv.compile(body));
llengine(cenv)->builder.CreateRet(retVal); // Finish function
diff --git a/tuplr.hpp b/tuplr.hpp
index efcba1f..2f66d9f 100644
--- a/tuplr.hpp
+++ b/tuplr.hpp
@@ -50,7 +50,7 @@ struct Cursor {
/// Compiler error
struct Error {
- Error(const string& m, Cursor c=Cursor()) : msg(m), loc(c) {}
+ Error(const string& m, Cursor c) : msg(m), loc(c) {}
const string what() const { return (loc ? loc.str() + ": " : "") + "error: " + msg; }
string msg;
Cursor loc;
@@ -220,7 +220,7 @@ struct ATuple : public AST, public vector<AST*> {
return false;
}
void constrain(TEnv& tenv, Constraints& c) const;
- CValue compile(CEnv& cenv) { throw Error("tuple compiled"); }
+ CValue compile(CEnv& cenv) { throw Error("tuple compiled", loc); }
};
/// Type Expression, e.g. "Int", "(Fn (Int Int) Float)"
diff --git a/typing.cpp b/typing.cpp
index 3f2f8e0..699589b 100644
--- a/typing.cpp
+++ b/typing.cpp
@@ -162,7 +162,7 @@ ADefinition::constrain(TEnv& tenv, Constraints& c) const
void
AIf::constrain(TEnv& tenv, Constraints& c) const
{
- THROW_IF(size() < 4, "`if' requires at least 3 argumentsz", loc);
+ THROW_IF(size() < 4, "`if' requires at least 3 arguments", loc);
THROW_IF(size() % 2 != 0, "`if' missing final else clause", loc)
for (size_t i = 1; i < size(); ++i)
at(i)->constrain(tenv, c);