Mercurial > projects > ddmd
diff dmd/CallExp.d @ 63:cab4c37afb89
A bunch of implementations
author | korDen |
---|---|
date | Mon, 23 Aug 2010 16:52:24 +0400 |
parents | 10317f0c89a5 |
children | 4290d870944a |
line wrap: on
line diff
--- a/dmd/CallExp.d Mon Aug 23 03:21:32 2010 +0400 +++ b/dmd/CallExp.d Mon Aug 23 16:52:24 2010 +0400 @@ -1,6 +1,7 @@ module dmd.CallExp; import dmd.Expression; +import dmd.Cast; import dmd.WANT; import dmd.BUILTIN; import dmd.TypeFunction; @@ -70,6 +71,8 @@ import dmd.backend.TYM; import dmd.codegen.Util; +import std.stdio; + class CallExp : UnaExp { Expressions arguments; @@ -807,9 +810,83 @@ return e; } - Expression interpret(InterState* istate) + Expression interpret(InterState istate) { - assert(false); + Expression e = EXP_CANT_INTERPRET; + +version (LOG) { + printf("CallExp.interpret() %.*s\n", toChars()); +} + if (e1.op == TOKdotvar) + { + Expression pthis = (cast(DotVarExp)e1).e1; + FuncDeclaration fd = (cast(DotVarExp)e1).var.isFuncDeclaration(); + TypeFunction tf = fd ? cast(TypeFunction)fd.type : null; + if (tf) + { + // Member function call + if(pthis.op == TOKthis) + pthis = istate.localThis; + Expression eresult = fd.interpret(istate, arguments, pthis); + if (eresult) + e = eresult; + else if (fd.type.toBasetype().nextOf().ty == Tvoid && !global.errors) + e = EXP_VOID_INTERPRET; + else + error("cannot evaluate %s at compile time", toChars()); + return e; + } + error("cannot evaluate %s at compile time", toChars()); + return EXP_CANT_INTERPRET; + } + if (e1.op == TOKvar) + { + FuncDeclaration fd = (cast(VarExp)e1).var.isFuncDeclaration(); + if (fd) + { +///version (DMDV2) { + BUILTIN b = fd.isBuiltin(); + if (b) + { + scope Expressions args = new Expressions(); + args.setDim(arguments.dim); + for (size_t i = 0; i < args.dim; i++) + { + Expression earg = cast(Expression)arguments.data[i]; + earg = earg.interpret(istate); + if (earg == EXP_CANT_INTERPRET) + return earg; + args.data[i] = cast(void*)earg; + } + e = eval_builtin(b, args); + if (!e) + e = EXP_CANT_INTERPRET; + } + else +///} + // Inline .dup + if (fd.ident == Id.adDup && arguments && arguments.dim == 2) + { + e = cast(Expression)arguments.data[1]; + e = e.interpret(istate); + if (e !is EXP_CANT_INTERPRET) + { + e = expType(type, e); + } + } + else + { + Expression eresult = fd.interpret(istate, arguments); + if (eresult) + e = eresult; + else if (fd.type.toBasetype().nextOf().ty == Tvoid && !global.errors) + e = EXP_VOID_INTERPRET; + else + error("cannot evaluate %s at compile time", toChars()); + } + } + } + return e; } bool checkSideEffect(int flag)