diff options
Diffstat (limited to 'llvm.cpp')
-rw-r--r-- | llvm.cpp | 39 |
1 files changed, 31 insertions, 8 deletions
@@ -47,6 +47,25 @@ llType(const AType* t) 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() + "'"); + /*} else if (t->kind == AType::EXPR && t->at(0)->str() == "Fn") { + AType* retT = t->at(2)->as<AType*>(); + if (!llType(retT)) + return NULL; + + vector<const Type*> cprot; + const ATuple* prot = t->at(1)->to<ATuple*>(); + for (size_t i = 0; i < prot->size(); ++i) { + AType* at = prot->at(i)->to<AType*>(); + const Type* lt = llType(at); + if (lt) + cprot.push_back(lt); + else + return NULL; + } + + FunctionType* fT = FunctionType::get(llType(retT), cprot, false); + return PointerType::get(fT, 0); + */ } return NULL; // non-primitive type } @@ -120,6 +139,9 @@ struct LLVMEngine : public Engine { builder.CreateRetVoid(); } + /*std::cerr << "MODULE {" << endl; + module->dump(); + std::cerr << "}" << endl;*/ verifyFunction(*static_cast<Function*>(f)); if (cenv.args.find("-g") == cenv.args.end()) opt.run(*static_cast<Function*>(f)); @@ -230,10 +252,11 @@ AFn::liftCall(CEnv& cenv, const AType& argsT) { TEnv::GenericTypes::const_iterator gt = cenv.tenv.genericTypes.find(this); assert(gt != cenv.tenv.genericTypes.end()); - AType* thisType = new AType(*gt->second); + AType* genericType = new AType(*gt->second); + AType* thisType = genericType; Subst argsSubst; - if (!thisType->concrete()) { + if (!genericType->concrete()) { // Build substitution to apply to generic type assert(argsT.size() == prot()->size()); ATuple* genericProtT = gt->second->at(1)->as<ATuple*>(); @@ -249,18 +272,18 @@ AFn::liftCall(CEnv& cenv, const AType& argsT) AType* gT = genericArgT->at(i)->to<AType*>(); AType* aT = callArgT->at(i)->to<AType*>(); if (gT && aT) - argsSubst[gT] = aT; + argsSubst.add(gT, aT); } } else { - argsSubst[genericArgT] = callArgT; + argsSubst.add(genericArgT, callArgT); } } // Apply substitution to get concrete type for this call - thisType = argsSubst.apply(thisType)->as<AType*>(); - if (!thisType->concrete()) - throw Error(loc, string("unable to resolve concrete type for function :: ") - + thisType->str() + "\n" + this->str()); + thisType = argsSubst.apply(genericType)->as<AType*>(); + THROW_IF(!thisType->concrete(), loc, + string("unable to resolve concrete type for function :: ") + + thisType->str() + "\n" + this->str()); } Object::pool.addRoot(thisType); |