aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm.cpp24
-rw-r--r--tuplr.cpp12
-rw-r--r--tuplr.hpp10
-rw-r--r--typing.cpp40
4 files changed, 43 insertions, 43 deletions
diff --git a/llvm.cpp b/llvm.cpp
index d04bd1b..9597236 100644
--- a/llvm.cpp
+++ b/llvm.cpp
@@ -50,13 +50,13 @@ lltype(const AType* t)
{
switch (t->kind) {
case AType::VAR:
- throw Error((format("non-compilable type `%1%'") % t->str()).str(), t->loc);
+ throw Error(t->loc, (format("non-compilable type `%1%'") % t->str()).str());
return NULL;
case AType::PRIM:
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() + "'", t->loc);
+ throw Error(t->loc, string("Unknown primitive type `") + t->str() + "'");
case AType::EXPR:
if (t->at(0)->str() == "Pair") {
vector<const Type*> types;
@@ -155,17 +155,17 @@ compileFunction(CEnv& cenv, const std::string& name, const Type* retT, const ATu
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", protT.at(i)->loc)
+ THROW_IF(!lltype(at), protT.at(i)->loc, "function parameter is untyped")
cprot.push_back(lltype(at));
}
- THROW_IF(!retT, "function return is untyped", loc);
+ THROW_IF(!retT, loc, "function return is untyped");
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", loc);
+ throw Error(loc, "function redefined");
}
// Set argument names in generated code
@@ -223,7 +223,7 @@ AClosure::liftCall(CEnv& cenv, const vector<AType*>& argsT)
argsSubst[*genericProtT->at(i)->to<AType*>()] = argsT.at(i)->to<AType*>();
thisType = argsSubst.apply(genericType)->as<AType*>();
if (!thisType->concrete())
- throw Error("unable to resolve concrete type for function", loc);
+ throw Error(loc, "unable to resolve concrete type for function");
} else {
thisType = genericType;
}
@@ -290,9 +290,9 @@ ACall::lift(CEnv& cenv)
if (!c) return; // Primitive
if (c->prot()->size() < size() - 1)
- throw Error((format("too many arguments to function `%1%'") % at(0)->str()).str(), loc);
+ throw Error(loc, (format("too many arguments to function `%1%'") % at(0)->str()).str());
if (c->prot()->size() > size() - 1)
- throw Error((format("too few arguments to function `%1%'") % at(0)->str()).str(), loc);
+ throw Error(loc, (format("too few arguments to function `%1%'") % at(0)->str()).str());
c->liftCall(cenv, argsT); // Lift called closure
}
@@ -312,7 +312,7 @@ ACall::compile(CEnv& cenv)
assert(gt != cenv.tenv.genericTypes.end());
AType* fnT = new AType(loc, cenv.penv.sym("Fn"), protT, cenv.type(this), 0);
Function* f = (Function*)c->funcs.find(fnT);
- THROW_IF(!f, (format("callee failed to compile for type %1%") % fnT->str()).str(), loc)
+ THROW_IF(!f, loc, (format("callee failed to compile for type %1%") % fnT->str()).str())
vector<Value*> params(size() - 1);
for (size_t i = 1; i < size(); ++i)
@@ -426,7 +426,7 @@ APrimitive::compile(CEnv& cenv)
return llengine(cenv)->builder.CreateICmp(pred, a, b);
}
- throw Error("unknown primitive", loc);
+ throw Error(loc, "unknown primitive");
}
AType*
@@ -560,7 +560,7 @@ eval(CEnv& cenv, const string& name, istream& is)
}
const Type* ctype = lltype(resultType);
- THROW_IF(!ctype, "body has non-compilable type", cursor)
+ THROW_IF(!ctype, cursor, "body has non-compilable type")
// Create function for top-level of program
Function* f = compileFunction(cenv, "main", ctype, ATuple(cursor), cursor);
@@ -604,7 +604,7 @@ repl(CEnv& cenv)
cenv.tsubst = Subst::compose(cenv.tsubst, TEnv::unify(c)); // Solve type constraints
AType* bodyT = cenv.type(body);
- THROW_IF(!bodyT, "call to untyped body", cursor)
+ THROW_IF(!bodyT, cursor, "call to untyped body")
body->lift(cenv);
diff --git a/tuplr.cpp b/tuplr.cpp
index fbd3bd3..10233f9 100644
--- a/tuplr.cpp
+++ b/tuplr.cpp
@@ -72,7 +72,7 @@ readExpression(Cursor& cur, istream& in)
while (int c = readChar(cur, in)) {
switch (c) {
case EOF:
- THROW_IF(!stk.empty(), "unexpected end of file", cur)
+ THROW_IF(!stk.empty(), cur, "unexpected end of file")
return SExp(cur);
case ';':
while ((c = readChar(cur, in)) != '\n') {}
@@ -90,7 +90,7 @@ readExpression(Cursor& cur, istream& in)
case ')':
switch (stk.size()) {
case 0:
- throw Error("unexpected `)'", cur);
+ throw Error(cur, "unexpected `)'");
case 1:
PUSH(stk, tok);
return stk.top();
@@ -114,7 +114,7 @@ readExpression(Cursor& cur, istream& in)
switch (stk.size()) {
case 0: return SExp(loc, tok);
case 1: return stk.top();
- default: throw Error("missing `)'", cur);
+ default: throw Error(cur, "missing `)'");
}
return SExp(cur);
}
@@ -127,7 +127,7 @@ readExpression(Cursor& cur, istream& in)
inline SExp
macDef(PEnv& penv, const SExp& exp)
{
- THROW_IF(exp.size() != 3, "[MAC] `def' requires exactly 2 arguments", exp.loc)
+ THROW_IF(exp.size() != 3, exp.loc, "[MAC] `def' requires exactly 2 arguments")
if (exp.at(1).type == SExp::ATOM) {
return exp;
} else {
@@ -170,9 +170,9 @@ inline AST*
parseFn(PEnv& penv, const SExp& exp, void* arg)
{
if (exp.size() < 2)
- throw Error("Missing function parameters and body", exp.loc);
+ throw Error(exp.loc, "Missing function parameters and body");
else if (exp.size() < 3)
- throw Error("Missing function body", exp.loc);
+ throw Error(exp.loc, "Missing function body");
SExp::const_iterator a = exp.begin(); ++a;
AClosure* ret = new AClosure(exp.loc, penv.sym("fn"), new ATuple(penv.parseTuple(*a++)));
while (a != exp.end())
diff --git a/tuplr.hpp b/tuplr.hpp
index 2f66d9f..025dd55 100644
--- a/tuplr.hpp
+++ b/tuplr.hpp
@@ -50,10 +50,10 @@ struct Cursor {
/// Compiler error
struct Error {
- Error(const string& m, Cursor c) : msg(m), loc(c) {}
+ Error(Cursor c, const string& m) : loc(c), msg(m) {}
const string what() const { return (loc ? loc.str() + ": " : "") + "error: " + msg; }
- string msg;
Cursor loc;
+ string msg;
};
/// Expression ::= Atom | (SubExp*)
@@ -160,7 +160,7 @@ struct AST {
template<typename T> T to() const { return dynamic_cast<T>(this); }
template<typename T> T as() {
T t = dynamic_cast<T>(this);
- if (!t) throw Error("internal error: bad cast", loc);
+ if (!t) throw Error(loc, "internal error: bad cast");
return t;
}
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", loc); }
+ CValue compile(CEnv& cenv) { throw Error(loc, "tuple compiled"); }
};
/// Type Expression, e.g. "Int", "(Fn (Int Int) Float)"
@@ -414,7 +414,7 @@ struct PEnv : private map<const string, ASymbol*> {
}
AST* parse(const SExp& exp) {
if (exp.type == SExp::LIST) {
- if (exp.empty()) throw Error("call to empty list", exp.loc);
+ if (exp.empty()) throw Error(exp.loc, "call to empty list");
if (exp.front().type == SExp::ATOM) {
MF mf = mac(exp.front().atom);
SExp expanded = (mf ? mf(*this, exp) : exp);
diff --git a/typing.cpp b/typing.cpp
index 699589b..8487001 100644
--- a/typing.cpp
+++ b/typing.cpp
@@ -34,7 +34,7 @@ ASymbol::constrain(TEnv& tenv, Constraints& c) const
{
addr = tenv.lookup(this);
if (!addr)
- throw Error((format("undefined symbol `%1%'") % cppstr).str(), loc);
+ throw Error(loc, (format("undefined symbol `%1%'") % cppstr).str());
c.push_back(Constraint(tenv.var(this), tenv.deref(addr).second, loc));
}
@@ -64,9 +64,9 @@ AClosure::constrain(TEnv& tenv, Constraints& c) const
for (size_t i = 0; i < prot()->size(); ++i) {
ASymbol* sym = prot()->at(i)->to<ASymbol*>();
if (!sym)
- throw Error("parameter name is not a symbol", prot()->at(i)->loc);
+ throw Error(prot()->at(i)->loc, "parameter name is not a symbol");
if (defined.find(sym) != defined.end())
- throw Error((format("duplicate parameter `%1%'") % sym->str()).str(), sym->loc);
+ throw Error(sym->loc, (format("duplicate parameter `%1%'") % sym->str()).str());
defined.insert(sym);
frame.push_back(make_pair(sym, make_pair((AST*)NULL, (AType*)NULL)));
}
@@ -79,7 +79,7 @@ AClosure::constrain(TEnv& tenv, Constraints& c) const
if (def) {
ASymbol* sym = def->sym();
if (defined.find(sym) != defined.end())
- throw Error((format("`%1%' defined twice") % sym->str()).str(), def->loc);
+ throw Error(def->loc, (format("`%1%' defined twice") % sym->str()).str());
defined.insert(def->sym());
frame.push_back(make_pair(def->sym(), make_pair(def->at(2), (AType*)NULL)));
}
@@ -127,7 +127,7 @@ ACall::constrain(TEnv& tenv, Constraints& c) const
AClosure* closure = callee->to<AClosure*>();
if (closure) {
if (size() - 1 != closure->prot()->size())
- throw Error("incorrect number of arguments", loc);
+ throw Error(loc, "incorrect number of arguments");
TEnv::GenericTypes::iterator gt = tenv.genericTypes.find(closure);
if (gt != tenv.genericTypes.end()) {
for (size_t i = 1; i < size(); ++i)
@@ -149,9 +149,9 @@ ACall::constrain(TEnv& tenv, Constraints& c) const
void
ADefinition::constrain(TEnv& tenv, Constraints& c) const
{
- THROW_IF(size() != 3, "`def' requires exactly 2 arguments", loc);
+ THROW_IF(size() != 3, loc, "`def' requires exactly 2 arguments");
const ASymbol* sym = this->sym();
- THROW_IF(!sym, "`def' has no symbol", loc)
+ THROW_IF(!sym, loc, "`def' has no symbol")
AType* tvar = tenv.var(at(2));
tenv.def(sym, make_pair(at(2), tvar));
@@ -162,8 +162,8 @@ ADefinition::constrain(TEnv& tenv, Constraints& c) const
void
AIf::constrain(TEnv& tenv, Constraints& c) const
{
- THROW_IF(size() < 4, "`if' requires at least 3 arguments", loc);
- THROW_IF(size() % 2 != 0, "`if' missing final else clause", loc)
+ THROW_IF(size() < 4, loc, "`if' requires at least 3 arguments");
+ THROW_IF(size() % 2 != 0, loc, "`if' missing final else clause")
for (size_t i = 1; i < size(); ++i)
at(i)->constrain(tenv, c);
AType* retT = tenv.var(this);
@@ -191,7 +191,7 @@ APrimitive::constrain(TEnv& tenv, Constraints& c) const
else if (n == "=" || n == "!=" || n == ">" || n == ">=" || n == "<" || n == "<=")
type = COMPARISON;
else
- throw Error((format("unknown primitive `%1%'") % n).str(), loc);
+ throw Error(loc, (format("unknown primitive `%1%'") % n).str());
for (size_t i = 1; i < size(); ++i)
at(i)->constrain(tenv, c);
@@ -199,38 +199,38 @@ APrimitive::constrain(TEnv& tenv, Constraints& c) const
switch (type) {
case ARITHMETIC:
if (size() < 3)
- throw Error((format("`%1%' requires at least 2 arguments") % n).str(), loc);
+ throw Error(loc, (format("`%1%' requires at least 2 arguments") % n).str());
for (size_t i = 1; i < size(); ++i)
c.constrain(tenv, at(i), tenv.var(this));
break;
case BINARY:
if (size() != 3)
- throw Error((format("`%1%' requires exactly 2 arguments") % n).str(), loc);
+ throw Error(loc, (format("`%1%' requires exactly 2 arguments") % n).str());
c.constrain(tenv, at(1), tenv.var(this));
c.constrain(tenv, at(2), tenv.var(this));
break;
case LOGICAL:
if (size() != 3)
- throw Error((format("`%1%' requires exactly 2 arguments") % n).str(), loc);
+ throw Error(loc, (format("`%1%' requires exactly 2 arguments") % n).str());
c.constrain(tenv, this, tenv.named("Bool"));
c.constrain(tenv, at(1), tenv.named("Bool"));
c.constrain(tenv, at(2), tenv.named("Bool"));
break;
case COMPARISON:
if (size() != 3)
- throw Error((format("`%1%' requires exactly 2 arguments") % n).str(), loc);
+ throw Error(loc, (format("`%1%' requires exactly 2 arguments") % n).str());
c.constrain(tenv, this, tenv.named("Bool"));
c.constrain(tenv, at(1), tenv.var(at(2)));
break;
default:
- throw Error((format("unknown primitive `%1%'") % n).str(), loc);
+ throw Error(loc, (format("unknown primitive `%1%'") % n).str());
}
}
void
AConsCall::constrain(TEnv& tenv, Constraints& c) const
{
- THROW_IF(size() != 3, "`cons' requires exactly 2 arguments", loc)
+ THROW_IF(size() != 3, loc, "`cons' requires exactly 2 arguments")
AType* t = new AType(loc, tenv.penv.sym("Pair"), 0);
for (size_t i = 1; i < size(); ++i) {
at(i)->constrain(tenv, c);
@@ -242,7 +242,7 @@ AConsCall::constrain(TEnv& tenv, Constraints& c) const
void
ACarCall::constrain(TEnv& tenv, Constraints& c) const
{
- THROW_IF(size() != 2, "`car' requires exactly 1 argument", loc)
+ THROW_IF(size() != 2, loc, "`car' requires exactly 1 argument")
at(1)->constrain(tenv, c);
AType* carT = tenv.var(this);
AType* pairT = new AType(at(1)->loc, tenv.penv.sym("Pair"), carT, tenv.var(), 0);
@@ -253,7 +253,7 @@ ACarCall::constrain(TEnv& tenv, Constraints& c) const
void
ACdrCall::constrain(TEnv& tenv, Constraints& c) const
{
- THROW_IF(size() != 2, "`cdr' requires exactly 1 argument", loc)
+ THROW_IF(size() != 2, loc, "`cdr' requires exactly 1 argument")
at(1)->constrain(tenv, c);
AType* cdrT = tenv.var(this);
AType* pairT = new AType(at(1)->loc, tenv.penv.sym("Pair"), tenv.var(), cdrT, 0);
@@ -332,8 +332,8 @@ TEnv::unify(const Constraints& constraints) // TAPL 22.4
}
return unify(cp);
} else {
- throw Error((format("type is `%1%' but should be `%2%'") % s->str() % t->str()).str(),
- s->loc ? s->loc : t->loc);
+ throw Error(s->loc ? s->loc : t->loc,
+ (format("type is `%1%' but should be `%2%'") % s->str() % t->str()).str());
}
}