From f5f5c2e1f9c27a6aa6cbb5370fd5c2943d577367 Mon Sep 17 00:00:00 2001 From: Alexey Prokhin Date: Fri, 17 Dec 2010 12:55:28 +0300 Subject: [PATCH] Fixed invoking of delegates inside CTFE. --- dmd2/expression.h | 1 + dmd2/interpret.c | 29 ++++++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/dmd2/expression.h b/dmd2/expression.h index e175b13a..381d7716 100644 --- a/dmd2/expression.h +++ b/dmd2/expression.h @@ -1145,6 +1145,7 @@ struct AddrExp : UnaExp #if IN_LLVM DValue* toElem(IRState* irs); llvm::Constant *toConstElem(IRState *irs); + Expression *interpret(InterState *istate); #endif }; diff --git a/dmd2/interpret.c b/dmd2/interpret.c index 250be4a8..df35ad9b 100644 --- a/dmd2/interpret.c +++ b/dmd2/interpret.c @@ -1193,6 +1193,25 @@ Expression *DelegateExp::interpret(InterState *istate) return this; } +#if IN_LLVM + +Expression *AddrExp::interpret(InterState *istate) +{ +#if LOG + printf("AddrExpExp::interpret() %s\n", toChars()); +#endif + if (e1->op == TOKvar) + { VarExp *ve = (VarExp *)e1; + if (ve->var->isFuncDeclaration()) + return this; + + } + error("Cannot interpret %s at compile time", toChars()); + return EXP_CANT_INTERPRET; +} + +#endif + // ------------------------------------------------------------- // Remove out, ref, and this @@ -2714,9 +2733,17 @@ Expression *CallExp::interpret(InterState *istate) fd = ((SymOffExp *)vd->value)->var->isFuncDeclaration(); else { ecall = vd->value->interpret(istate); +#if IN_LLVM + if (ecall->op == TOKaddress) { + AddrExp *e = (AddrExp*)ecall; + if (e->e1->op == TOKvar) + fd = ((VarExp *)e->e1)->var->isFuncDeclaration(); + } +#else if (ecall->op == TOKsymoff) fd = ((SymOffExp *)ecall)->var->isFuncDeclaration(); - } +#endif + } } else ecall = ((PtrExp*)ecall)->e1->interpret(istate);