# HG changeset patch # User lindquist # Date 1192808626 -7200 # Node ID e5c4bece7fa1a085a2b6364d660bb0de75f20180 # Parent 4d171915a77b0d4fc0b932dcb618b45a150b934c [svn r53] added basic support for delegate literals. if you access outer variables you get a broken module diff -r 4d171915a77b -r e5c4bece7fa1 gen/toir.c --- a/gen/toir.c Fri Oct 19 17:15:30 2007 +0200 +++ b/gen/toir.c Fri Oct 19 17:43:46 2007 +0200 @@ -570,8 +570,10 @@ e->inplace = true; e->mem = l->mem; } - else - assert(0); + else { + LLVM_DtoDelegateCopy(l->mem, r->getValue()); + e->mem = l->mem; + } } else assert(0); @@ -2581,6 +2583,39 @@ ////////////////////////////////////////////////////////////////////////////////////////// +elem* FuncExp::toElem(IRState* p) +{ + Logger::print("FuncExp::toElem: %s | %s\n", toChars(), type->toChars()); + LOG_SCOPE; + + assert(fd); + + if (fd->isNested()) Logger::println("nested"); + Logger::println("kind = %s\n", fd->kind()); + + fd->toObjFile(); + + llvm::Value* lval = p->toplval(); + + elem* e = new elem; + + llvm::Value* context = LLVM_DtoGEPi(lval,0,0,"tmp",p->scopebb()); + //llvm::Value* castcontext = llvm::ConstantPointerNull::get(context->getType()); + //new llvm::StoreInst(castcontext, context, p->scopebb()); + + llvm::Value* fptr = LLVM_DtoGEPi(lval,0,1,"tmp",p->scopebb()); + + assert(fd->llvmValue); + llvm::Value* castfptr = new llvm::BitCastInst(fd->llvmValue,fptr->getType()->getContainedType(0),"tmp",p->scopebb()); + new llvm::StoreInst(castfptr, fptr, p->scopebb()); + + e->inplace = true; + + return e; +} + +////////////////////////////////////////////////////////////////////////////////////////// + #define STUB(x) elem *x::toElem(IRState * p) {error("Exp type "#x" not implemented: %s", toChars()); fatal(); return 0; } //STUB(IdentityExp); //STUB(CondExp); @@ -2622,7 +2657,7 @@ STUB(TypeDotIdExp); //STUB(DotVarExp); //STUB(AssertExp); -STUB(FuncExp); +//STUB(FuncExp); //STUB(DelegateExp); //STUB(VarExp); //STUB(DeclarationExp); diff -r 4d171915a77b -r e5c4bece7fa1 gen/tollvm.c --- a/gen/tollvm.c Fri Oct 19 17:15:30 2007 +0200 +++ b/gen/tollvm.c Fri Oct 19 17:43:46 2007 +0200 @@ -276,6 +276,10 @@ else assert(0); } + else if (fdecl->isNested()) { + paramvec.push_back(llvm::PointerType::get(llvm::Type::Int8Ty)); + usesthis = true; + } size_t n = Argument::dim(f->parameters); for (int i=0; i < n; ++i) { diff -r 4d171915a77b -r e5c4bece7fa1 test/bug19.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/bug19.d Fri Oct 19 17:43:46 2007 +0200 @@ -0,0 +1,7 @@ +module bug19; + +void main() +{ + auto dg = (int i) { return i*2; }; + assert(dg(2) == 4); +}