From adc75dd37727427ceb930471716ff0260e9137f9 Mon Sep 17 00:00:00 2001 From: Tomas Lindquist Olsen Date: Fri, 25 Jan 2008 01:42:36 +0100 Subject: [PATCH] [svn r147] tango.io.Console is now working. True this time :) Yay! --- gen/dvalue.h | 2 +- gen/toir.cpp | 21 ++++++-- llvmdc.kdevelop | 88 -------------------------------- tango/lib/compiler/llvmdc/cast.d | 2 +- tangotests/t.d | 37 +++++++------- 5 files changed, 38 insertions(+), 112 deletions(-) diff --git a/gen/dvalue.h b/gen/dvalue.h index 9ee9afd8..c534e19b 100644 --- a/gen/dvalue.h +++ b/gen/dvalue.h @@ -69,7 +69,7 @@ struct DImValue : DValue llvm::Value* val; bool inplace; - DImValue(Type* t, llvm::Value* v, bool i = false) { type = t; val = v; inplace = i; } + DImValue(Type* t, llvm::Value* v, bool in_place = false) { type = t; val = v; inplace = in_place; } virtual llvm::Value* getRVal() { assert(val); return val; } diff --git a/gen/toir.cpp b/gen/toir.cpp index 2a812ba2..c82c4a35 100644 --- a/gen/toir.cpp +++ b/gen/toir.cpp @@ -2173,19 +2173,20 @@ DValue* DelegateExp::toElem(IRState* p) Logger::print("DelegateExp::toElem: %s | %s\n", toChars(), type->toChars()); LOG_SCOPE; - DValue* u = e1->toElem(p); - const llvm::PointerType* int8ptrty = getPtrToType(llvm::Type::Int8Ty); llvm::Value* lval; + bool inplace = false; if (p->topexp() && p->topexp()->e2 == this) { assert(p->topexp()->v); lval = p->topexp()->v->getLVal(); + inplace = true; } else { lval = new llvm::AllocaInst(DtoType(type), "tmpdelegate", p->topallocapoint()); } + DValue* u = e1->toElem(p); llvm::Value* uval; if (DFuncValue* f = u->isFunc()) { //assert(f->vthis); @@ -2197,9 +2198,21 @@ DValue* DelegateExp::toElem(IRState* p) uval = llvm::ConstantPointerNull::get(int8ptrty); } else { - uval = u->getRVal(); + DValue* src = u; + if (ClassDeclaration* cd = u->getType()->isClassHandle()) + { + Logger::println("context type is class handle"); + if (cd->isInterfaceDeclaration()) + { + Logger::println("context type is interface"); + src = DtoCastInterfaceToObject(u, ClassDeclaration::object->type); + } + } + uval = src->getRVal(); } + Logger::cout() << "context = " << *uval << '\n'; + llvm::Value* context = DtoGEPi(lval,0,0,"tmp"); llvm::Value* castcontext = DtoBitCast(uval, int8ptrty); DtoStore(castcontext, context); @@ -2221,7 +2234,7 @@ DValue* DelegateExp::toElem(IRState* p) castfptr = DtoBitCast(castfptr, fptr->getType()->getContainedType(0)); DtoStore(castfptr, fptr); - return new DVarValue(type, lval, true); + return new DImValue(type, lval, inplace); } ////////////////////////////////////////////////////////////////////////////////////////// diff --git a/llvmdc.kdevelop b/llvmdc.kdevelop index a777c095..3968f8d3 100644 --- a/llvmdc.kdevelop +++ b/llvmdc.kdevelop @@ -572,94 +572,6 @@ dmd25/utf.h dmd25/version.c dmd25/version.h - dmd26 - dmd26/access.c - dmd26/aggregate.h - dmd26/array.c - dmd26/arraytypes.h - dmd26/attrib.c - dmd26/attrib.h - dmd26/cast.c - dmd26/class.c - dmd26/complex_t.h - dmd26/cond.c - dmd26/cond.h - dmd26/constfold.c - dmd26/dchar.c - dmd26/dchar.h - dmd26/declaration.c - dmd26/declaration.h - dmd26/delegatize.c - dmd26/doc.c - dmd26/doc.h - dmd26/dsymbol.c - dmd26/dsymbol.h - dmd26/dump.c - dmd26/entity.c - dmd26/enum.c - dmd26/enum.h - dmd26/expression.c - dmd26/expression.h - dmd26/func.c - dmd26/gnuc.c - dmd26/gnuc.h - dmd26/hdrgen.c - dmd26/hdrgen.h - dmd26/html.c - dmd26/html.h - dmd26/identifier.c - dmd26/identifier.h - dmd26/idgen.c - dmd26/impcnvgen.c - dmd26/import.c - dmd26/import.h - dmd26/inifile.c - dmd26/init.c - dmd26/init.h - dmd26/inline.c - dmd26/interpret.c - dmd26/lexer.c - dmd26/lexer.h - dmd26/link.c - dmd26/lstring.c - dmd26/lstring.h - dmd26/macro.c - dmd26/macro.h - dmd26/mangle.c - dmd26/mars.c - dmd26/mars.h - dmd26/mem.c - dmd26/mem.h - dmd26/module.c - dmd26/module.h - dmd26/mtype.c - dmd26/mtype.h - dmd26/opover.c - dmd26/optimize.c - dmd26/parse.c - dmd26/parse.h - dmd26/port.h - dmd26/root.c - dmd26/root.h - dmd26/scope.c - dmd26/scope.h - dmd26/statement.c - dmd26/statement.h - dmd26/staticassert.c - dmd26/staticassert.h - dmd26/stringtable.c - dmd26/stringtable.h - dmd26/struct.c - dmd26/template.c - dmd26/template.h - dmd26/total.h - dmd26/unialpha.c - dmd26/utf.c - dmd26/utf.h - dmd26/version.c - dmd26/version.h - todo - todo/lib.d make diff --git a/tango/lib/compiler/llvmdc/cast.d b/tango/lib/compiler/llvmdc/cast.d index dcff9817..2c9ae6e4 100644 --- a/tango/lib/compiler/llvmdc/cast.d +++ b/tango/lib/compiler/llvmdc/cast.d @@ -27,7 +27,7 @@ extern (C): -debug = PRINTF; +//debug = PRINTF; debug(PRINTF) int printf(char*, ...); /****************************************** diff --git a/tangotests/t.d b/tangotests/t.d index fc4d95cd..9591261f 100644 --- a/tangotests/t.d +++ b/tangotests/t.d @@ -1,33 +1,34 @@ interface MyInterface { - void func(); + int func(); } -abstract class MyBaseClass : MyInterface +class MyClass : MyInterface { - abstract void func(); + int var; + int func() + { + return var; + } } -class MyClass : MyBaseClass +void func1(MyInterface i) { - void func() - { - } + int delegate() dg = &i.func; + func2(dg); +} - MyBaseClass toBase() - { - return this; - } +extern(C) int printf(char*, ...); + +void func2(int delegate() dg) +{ + int i = dg(); + printf("%d\n", i); } void main() { - printf("STARTING\n"); auto c = new MyClass; - printf("c = %p\n", c); - auto b = c.toBase; - printf("b = %p\n", b); - printf("FINISHED\n"); + c.var = 42; + func1(c); } - -extern(C) int printf(char*, ...);