[svn r53] added basic support for delegate literals. if you access outer variables you get a broken module

This commit is contained in:
Tomas Lindquist Olsen
2007-10-19 17:43:46 +02:00
parent 6445254a7b
commit f16a0c35b5
3 changed files with 49 additions and 3 deletions

View File

@@ -570,8 +570,10 @@ elem* AssignExp::toElem(IRState* p)
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 @@ llvm::Constant* ArrayLiteralExp::toConstElem(IRState* p)
//////////////////////////////////////////////////////////////////////////////////////////
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(DotTypeExp);
STUB(TypeDotIdExp);
//STUB(DotVarExp);
//STUB(AssertExp);
STUB(FuncExp);
//STUB(FuncExp);
//STUB(DelegateExp);
//STUB(VarExp);
//STUB(DeclarationExp);

View File

@@ -276,6 +276,10 @@ const llvm::FunctionType* LLVM_DtoFunctionType(FuncDeclaration* fdecl)
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) {

7
test/bug19.d Normal file
View File

@@ -0,0 +1,7 @@
module bug19;
void main()
{
auto dg = (int i) { return i*2; };
assert(dg(2) == 4);
}