Mercurial > projects > ldc
diff gen/tocall.cpp @ 719:7261ff0f95ff
Implemented first class delegates. closes #101
author | Tomas Lindquist Olsen <tomas.l.olsen@gmail.com> |
---|---|
date | Wed, 22 Oct 2008 21:50:08 +0200 |
parents | 30b42a283c8e |
children | e177ae483f8e |
line wrap: on
line diff
--- a/gen/tocall.cpp Wed Oct 22 20:00:57 2008 +0200 +++ b/gen/tocall.cpp Wed Oct 22 21:50:08 2008 +0200 @@ -75,11 +75,18 @@ } else if (type->ty == Tdelegate) { - LLValue* dg = fn->getRVal(); - if (Logger::enabled()) - Logger::cout() << "delegate: " << *dg << '\n'; - LLValue* funcptr = DtoGEPi(dg, 0, 1); - return DtoLoad(funcptr); + if (fn->isLVal()) + { + LLValue* dg = fn->getLVal(); + LLValue* funcptr = DtoGEPi(dg, 0, 1); + return DtoLoad(funcptr); + } + else + { + LLValue* dg = fn->getRVal(); + assert(isaStruct(dg)); + return gIR->ir->CreateExtractValue(dg, 1, ".funcptr"); + } } else { @@ -266,7 +273,15 @@ // ... or a delegate context arg else if (delegatecall) { - LLValue* ctxarg = DtoLoad(DtoGEPi(fnval->getRVal(), 0,0)); + LLValue* ctxarg; + if (fnval->isLVal()) + { + ctxarg = DtoLoad(DtoGEPi(fnval->getLVal(), 0,0)); + } + else + { + ctxarg = gIR->ir->CreateExtractValue(fnval->getRVal(), 0, ".ptr"); + } assert(ctxarg->getType() == argiter->get()); ++argiter; args.push_back(ctxarg);