diff options
author | David Robillard <d@drobilla.net> | 2009-06-18 20:45:40 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2009-06-18 20:45:40 +0000 |
commit | 936f996c4091266e9404f346e2939e613121f74c (patch) | |
tree | 737f02b112cd6d98a0abdc11b2a84591b1493b8e | |
parent | d8c876402bb348abc7d1fb539f245e7ba8c4ce27 (diff) | |
download | resp-936f996c4091266e9404f346e2939e613121f74c.tar.gz resp-936f996c4091266e9404f346e2939e613121f74c.tar.bz2 resp-936f996c4091266e9404f346e2939e613121f74c.zip |
Make source location mandatory parameter for Error.
git-svn-id: http://svn.drobilla.net/resp/tuplr@121 ad02d1e2-f140-0410-9f75-f8b11f17cedd
-rw-r--r-- | llvm.cpp | 18 | ||||
-rw-r--r-- | tuplr.hpp | 4 | ||||
-rw-r--r-- | typing.cpp | 2 |
3 files changed, 12 insertions, 12 deletions
@@ -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 @@ -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)" @@ -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); |