diff options
Diffstat (limited to 'llvm.cpp')
-rw-r--r-- | llvm.cpp | 21 |
1 files changed, 13 insertions, 8 deletions
@@ -42,9 +42,10 @@ static const Type* llType(const AType* t) { if (t->kind == 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; + if (t->at(0)->str() == "Nothing") return Type::VoidTy; + 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(t->loc, string("Unknown primitive type `") + t->str() + "'"); } return NULL; // non-primitive type @@ -113,9 +114,13 @@ struct LLVMEngine : public Engine { return f; } - void finishFunction(CEnv& cenv, CFunction f, CValue ret) { - Value* retVal = llVal(ret); - builder.CreateRet(retVal); + void finishFunction(CEnv& cenv, CFunction f, const AType* retT, CValue ret) { + if (retT->concrete()) { + Value* retVal = llVal(ret); + builder.CreateRet(retVal); + } else { + builder.CreateRetVoid(); + } verifyFunction(*static_cast<Function*>(f)); if (cenv.args.find("-g") == cenv.args.end()) @@ -240,7 +245,7 @@ AFn::liftCall(CEnv& cenv, const AType& argsT) thisType = argsSubst.apply(thisType)->as<AType*>(); if (!thisType->concrete()) throw Error(loc, string("unable to resolve concrete type for function :: ") - + thisType->str()); + + thisType->str() + "\n" + this->str()); } Object::pool.addRoot(thisType); @@ -326,7 +331,7 @@ AFn::liftCall(CEnv& cenv, const AType& argsT) CValue retVal = NULL; for (size_t i = 2; i < size(); ++i) retVal = cenv.compile(at(i)); - cenv.engine()->finishFunction(cenv, f, retVal); + cenv.engine()->finishFunction(cenv, f, cenv.type(at(size()-1)), retVal); } catch (Error& e) { f->eraseFromParent(); // Error reading body, remove function cenv.pop(); |