diff options
Diffstat (limited to 'llvm.cpp')
-rw-r--r-- | llvm.cpp | 23 |
1 files changed, 6 insertions, 17 deletions
@@ -146,17 +146,6 @@ 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)) -template<typename T> -T -checked_cast(AST* ast) -{ - T t = dynamic_cast<T>(ast); - if (!t) - throw Error((format("internal error: `%1%' should be a `%2%'") - % typeid(ast).name() % typeid(T).name()).str(), ast->loc); - return t; -} - static Function* compileFunction(CEnv& cenv, const std::string& name, const Type* retT, const ATuple& protT, const vector<string> argNames=vector<string>()) @@ -165,7 +154,7 @@ 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 = checked_cast<AType*>(protT.at(i)); + AType* at = protT.at(i)->as<AType*>(); if (!lltype(at)) throw Error("function parameter is untyped"); cprot.push_back(lltype(at)); } @@ -226,7 +215,7 @@ AClosure::lift(CEnv& cenv) const_iterator p = prot()->begin(); size_t i = 0; for (Function::arg_iterator a = f->arg_begin(); a != f->arg_end(); ++a, ++p) - cenv.def(checked_cast<ASymbol*>(*p), *p, checked_cast<AType*>(protT->at(i++)), &*a); + cenv.def((*p)->as<ASymbol*>(), *p, protT->at(i++)->as<AType*>(), &*a); // Write function body try { @@ -286,7 +275,7 @@ AClosure::liftCall(CEnv& cenv, const vector<AType*>& argsT) const_iterator p = prot()->begin(); size_t i = 0; for (Function::arg_iterator a = f->arg_begin(); a != f->arg_end(); ++a, ++p) - cenv.def(checked_cast<ASymbol*>(*p), *p, checked_cast<AType*>(protT->at(i++)), &*a); + cenv.def((*p)->as<ASymbol*>(), *p, protT->at(i++)->as<AType*>(), &*a); // Write function body try { @@ -347,7 +336,7 @@ ACall::lift(CEnv& cenv) cenv.push(); for (size_t i = 1; i < size(); ++i) - cenv.def(checked_cast<ASymbol*>(c->prot()->at(i-1)), 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 @@ -382,10 +371,10 @@ ACall::compile(CEnv& cenv) void ADefinition::lift(CEnv& cenv) { - if (cenv.code.lookup(checked_cast<ASymbol*>(at(1)))) + if (cenv.code.lookup(at(1)->as<ASymbol*>())) throw Error(string("`") + at(1)->str() + "' redefined", loc); // Define first for recursion - cenv.def(checked_cast<ASymbol*>(at(1)), at(2), cenv.type(at(2)), NULL); + cenv.def(at(1)->as<ASymbol*>(), at(2), cenv.type(at(2)), NULL); at(2)->lift(cenv); } |