diff options
-rw-r--r-- | llvm.cpp | 29 |
1 files changed, 8 insertions, 21 deletions
@@ -213,22 +213,19 @@ AClosure::liftCall(CEnv& cenv, const vector<AType*>& argsT) assert(gt != cenv.tenv.genericTypes.end()); AType* genericType = new AType(*gt->second); - AType* thisType = NULL; + AType* thisType = genericType; Subst argsSubst; - if (!genericType->concrete()) { + if (!thisType->concrete()) { // Find type and build substitution assert(argsT.size() == prot()->size()); - ATuple* genericProtT = genericType->at(1)->to<ATuple*>(); - assert(genericProtT); + ATuple* genericProtT = genericType->at(1)->as<ATuple*>(); for (size_t i = 0; i < argsT.size(); ++i) 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); } else { - thisType = cenv.type(this); + thisType = genericType; } if (funcs.find(thisType)) @@ -277,20 +274,10 @@ AClosure::compile(CEnv& cenv) return NULL; } -static -AST* -maybeLookup(CEnv& cenv, AST* ast) -{ - ASymbol* s = ast->to<ASymbol*>(); - if (s && s->addr) - return cenv.tenv.deref(s->addr).first; - return ast; -} - void ACall::lift(CEnv& cenv) { - AClosure* c = maybeLookup(cenv, at(0))->to<AClosure*>(); + AClosure* c = cenv.tenv.resolve(at(0))->to<AClosure*>(); vector<AType*> argsT; // Lift arguments @@ -312,7 +299,7 @@ ACall::lift(CEnv& cenv) CValue ACall::compile(CEnv& cenv) { - AClosure* c = maybeLookup(cenv, at(0))->to<AClosure*>(); + AClosure* c = cenv.tenv.resolve(at(0))->to<AClosure*>(); if (!c) return NULL; // Primitive @@ -512,7 +499,7 @@ AConsCall::compile(CEnv& cenv) CValue ACarCall::compile(CEnv& cenv) { - AST* arg = maybeLookup(cenv, at(1)); + AST* arg = cenv.tenv.resolve(at(1)); Value* sP = LLVal(cenv.compile(arg)); Value* s = llengine(cenv)->builder.CreateGEP(sP, ConstantInt::get(Type::Int32Ty, 0), "pair"); Value* carP = llengine(cenv)->builder.CreateStructGEP(s, 0, "car"); @@ -522,7 +509,7 @@ ACarCall::compile(CEnv& cenv) CValue ACdrCall::compile(CEnv& cenv) { - AST* arg = maybeLookup(cenv, at(1)); + AST* arg = cenv.tenv.resolve(at(1)); Value* sP = LLVal(cenv.compile(arg)); Value* s = llengine(cenv)->builder.CreateGEP(sP, ConstantInt::get(Type::Int32Ty, 0), "pair"); Value* cdrP = llengine(cenv)->builder.CreateStructGEP(s, 1, "cdr"); |