comparison gen/toir.cpp @ 520:73e41129b7f3

Fix function literals. They never carry a context. Fixes: run/f/foreach_36_A
author Christian Kamm <kamm incasoftware de>
date Sat, 16 Aug 2008 13:33:37 +0200
parents 0d286cd9fd08
children 99e95dae90d5
comparison
equal deleted inserted replaced
519:bc0835cd3440 520:73e41129b7f3
2062 if (fd->isNested()) Logger::println("nested"); 2062 if (fd->isNested()) Logger::println("nested");
2063 Logger::println("kind = %s\n", fd->kind()); 2063 Logger::println("kind = %s\n", fd->kind());
2064 2064
2065 DtoForceDefineDsymbol(fd); 2065 DtoForceDefineDsymbol(fd);
2066 2066
2067 const LLType* dgty = DtoType(type); 2067 LLValue *lval, *fptr;
2068 LLValue* lval = DtoAlloca(dgty,"dgstorage"); 2068 if(fd->tok == TOKdelegate) {
2069 2069 const LLType* dgty = DtoType(type);
2070 LLValue* context = DtoGEPi(lval,0,0); 2070 lval = DtoAlloca(dgty,"dgstorage");
2071 LLValue* cval; 2071
2072 IrFunction* irfn = p->func(); 2072 LLValue* context = DtoGEPi(lval,0,0);
2073 if (irfn->nestedVar) 2073 LLValue* cval;
2074 cval = irfn->nestedVar; 2074 IrFunction* irfn = p->func();
2075 else if (irfn->nestArg) 2075 if (irfn->nestedVar)
2076 cval = irfn->nestArg; 2076 cval = irfn->nestedVar;
2077 else if (irfn->nestArg)
2078 cval = irfn->nestArg;
2079 else
2080 cval = getNullPtr(getVoidPtrType());
2081 cval = DtoBitCast(cval, context->getType()->getContainedType(0));
2082 DtoStore(cval, context);
2083
2084 fptr = DtoGEPi(lval,0,1,"tmp",p->scopebb());
2085 } else if(fd->tok == TOKfunction) {
2086 const LLType* fnty = DtoType(type);
2087 lval = DtoAlloca(fnty,"fnstorage");
2088 fptr = lval;
2089 }
2077 else 2090 else
2078 cval = getNullPtr(getVoidPtrType()); 2091 assert(0 && "fd->tok must be TOKfunction or TOKdelegate");
2079 cval = DtoBitCast(cval, context->getType()->getContainedType(0));
2080 DtoStore(cval, context);
2081
2082 LLValue* fptr = DtoGEPi(lval,0,1,"tmp",p->scopebb());
2083 2092
2084 assert(fd->ir.irFunc->func); 2093 assert(fd->ir.irFunc->func);
2085 LLValue* castfptr = DtoBitCast(fd->ir.irFunc->func, fptr->getType()->getContainedType(0)); 2094 LLValue* castfptr = DtoBitCast(fd->ir.irFunc->func, fptr->getType()->getContainedType(0));
2086 DtoStore(castfptr, fptr); 2095 DtoStore(castfptr, fptr);
2087 2096