comparison 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
comparison
equal deleted inserted replaced
718:72ee105be27b 719:7261ff0f95ff
73 { 73 {
74 return fn->getRVal(); 74 return fn->getRVal();
75 } 75 }
76 else if (type->ty == Tdelegate) 76 else if (type->ty == Tdelegate)
77 { 77 {
78 LLValue* dg = fn->getRVal(); 78 if (fn->isLVal())
79 if (Logger::enabled()) 79 {
80 Logger::cout() << "delegate: " << *dg << '\n'; 80 LLValue* dg = fn->getLVal();
81 LLValue* funcptr = DtoGEPi(dg, 0, 1); 81 LLValue* funcptr = DtoGEPi(dg, 0, 1);
82 return DtoLoad(funcptr); 82 return DtoLoad(funcptr);
83 }
84 else
85 {
86 LLValue* dg = fn->getRVal();
87 assert(isaStruct(dg));
88 return gIR->ir->CreateExtractValue(dg, 1, ".funcptr");
89 }
83 } 90 }
84 else 91 else
85 { 92 {
86 assert(0 && "not a callable type"); 93 assert(0 && "not a callable type");
87 return NULL; 94 return NULL;
264 args.push_back(thisarg); 271 args.push_back(thisarg);
265 } 272 }
266 // ... or a delegate context arg 273 // ... or a delegate context arg
267 else if (delegatecall) 274 else if (delegatecall)
268 { 275 {
269 LLValue* ctxarg = DtoLoad(DtoGEPi(fnval->getRVal(), 0,0)); 276 LLValue* ctxarg;
277 if (fnval->isLVal())
278 {
279 ctxarg = DtoLoad(DtoGEPi(fnval->getLVal(), 0,0));
280 }
281 else
282 {
283 ctxarg = gIR->ir->CreateExtractValue(fnval->getRVal(), 0, ".ptr");
284 }
270 assert(ctxarg->getType() == argiter->get()); 285 assert(ctxarg->getType() == argiter->get());
271 ++argiter; 286 ++argiter;
272 args.push_back(ctxarg); 287 args.push_back(ctxarg);
273 } 288 }
274 // ... or a nested function context arg 289 // ... or a nested function context arg