diff options
Diffstat (limited to 'src/llvm.cpp')
-rw-r--r-- | src/llvm.cpp | 46 |
1 files changed, 9 insertions, 37 deletions
diff --git a/src/llvm.cpp b/src/llvm.cpp index cd5314a..0f7e7d4 100644 --- a/src/llvm.cpp +++ b/src/llvm.cpp @@ -139,12 +139,10 @@ struct LLVMEngine : public Engine { } void finishFunction(CEnv& cenv, CFunction f, const AType* retT, CValue ret) { - if (retT->concrete()) { - Value* retVal = llVal(ret); - builder.CreateRet(retVal); - } else { + if (retT->concrete()) + builder.CreateRet(llVal(ret)); + else builder.CreateRetVoid(); - } /*std::cerr << "MODULE {" << endl; module->dump(); @@ -232,39 +230,15 @@ AFn::liftCall(CEnv& cenv, const AType& argsT) AType* thisType = genericType; Subst argsSubst; + // Build and apply substitution to get concrete type for this call if (!genericType->concrete()) { - // Build substitution to apply to generic type - assert(argsT.size() == prot()->size()); - const ATuple* genericProtT = gt->second->at(1)->as<const ATuple*>(); - ATuple::const_iterator g = genericProtT->begin(); - AType::const_iterator a = argsT.begin(); - for (; a != argsT.end(); ++a, ++g) { - assert(g != genericProtT->end()); - const AType* genericArgT = (*g)->to<const AType*>(); - AType* callArgT = (*a)->to<AType*>(); - assert(genericArgT); - assert(callArgT); - if (callArgT->kind == AType::EXPR) { - assert(genericArgT->kind == AType::EXPR); - assert(callArgT->size() == genericArgT->size()); - for (size_t i = 0; i < callArgT->size(); ++i) { - const AType* gT = genericArgT->at(i)->to<const AType*>(); - AType* aT = callArgT->at(i)->to<AType*>(); - if (gT && aT) - argsSubst.add(gT, aT); - } - } else { - argsSubst.add(genericArgT, callArgT); - } - } - - // Apply substitution to get concrete type for this call + argsSubst = cenv.tenv.buildSubst(genericType, argsT); thisType = argsSubst.apply(genericType)->as<AType*>(); - THROW_IF(!thisType->concrete(), loc, - string("unable to resolve concrete type for function :: ") - + thisType->str() + "\n" + this->str()); } + THROW_IF(!thisType->concrete(), loc, + string("call has non-concrete type %1%\n") + thisType->str()); + Object::pool.addRoot(thisType); if (impls.find(thisType)) return; @@ -272,9 +246,8 @@ AFn::liftCall(CEnv& cenv, const AType& argsT) ATuple* protT = thisType->at(1)->as<ATuple*>(); vector<string> argNames; - for (size_t i = 0; i < prot()->size(); ++i) { + for (size_t i = 0; i < prot()->size(); ++i) argNames.push_back(prot()->at(i)->str()); - } // Write function declaration const string name = (this->name == "") ? cenv.penv.gensymstr("_fn") : this->name; @@ -310,7 +283,6 @@ AFn::liftCall(CEnv& cenv, const AType& argsT) #endif } - #ifdef EXPLICIT_STACK_FRAMES IRBuilder<> builder = engine->builder; |