diff dmd/interpret.c @ 159:5acec6b2eef8 trunk

[svn r175] merged dmd 1.029
author ChristianK
date Thu, 01 May 2008 15:15:28 +0200
parents 5825d48b27d1
children aaade6ded589
line wrap: on
line diff
--- a/dmd/interpret.c	Thu May 01 13:33:02 2008 +0200
+++ b/dmd/interpret.c	Thu May 01 15:15:28 2008 +0200
@@ -1,6 +1,6 @@
 
 // Compiler implementation of the D programming language
-// Copyright (c) 1999-2007 by Digital Mars
+// Copyright (c) 1999-2008 by Digital Mars
 // All Rights Reserved
 // written by Walter Bright
 // http://www.digitalmars.com
@@ -109,7 +109,7 @@
     istatex.caller = istate;
     istatex.fd = this;
 
-    Expressions vsave;
+    Expressions vsave;		// place to save previous parameter values
     size_t dim = 0;
     if (arguments)
     {
@@ -117,9 +117,40 @@
 	assert(!dim || parameters->dim == dim);
 	vsave.setDim(dim);
 
+	/* Evaluate all the arguments to the function,
+	 * store the results in eargs[]
+	 */
+	Expressions eargs;
+	eargs.setDim(dim);
+
 	for (size_t i = 0; i < dim; i++)
 	{   Expression *earg = (Expression *)arguments->data[i];
 	    Argument *arg = Argument::getNth(tf->parameters, i);
+
+	    if (arg->storageClass & (STCout | STCref))
+	    {
+	    }
+	    else
+	    {	/* Value parameters
+		 */
+		Type *ta = arg->type->toBasetype();
+		if (ta->ty == Tsarray && earg->op == TOKaddress)
+		{
+		    /* Static arrays are passed by a simple pointer.
+		     * Skip past this to get at the actual arg.
+		     */
+		    earg = ((AddrExp *)earg)->e1;
+		}
+		earg = earg->interpret(istate ? istate : &istatex);
+		if (earg == EXP_CANT_INTERPRET)
+		    return NULL;
+	    }
+	    eargs.data[i] = earg;
+	}
+
+	for (size_t i = 0; i < dim; i++)
+	{   Expression *earg = (Expression *)eargs.data[i];
+	    Argument *arg = Argument::getNth(tf->parameters, i);
 	    VarDeclaration *v = (VarDeclaration *)parameters->data[i];
 	    vsave.data[i] = v->value;
 #if LOG
@@ -161,17 +192,6 @@
 	    else
 	    {	/* Value parameters
 		 */
-		Type *ta = arg->type->toBasetype();
-		if (ta->ty == Tsarray && earg->op == TOKaddress)
-		{
-		    /* Static arrays are passed by a simple pointer.
-		     * Skip past this to get at the actual arg.
-		     */
-		    earg = ((AddrExp *)earg)->e1;
-		}
-		earg = earg->interpret(istate ? istate : &istatex);
-		if (earg == EXP_CANT_INTERPRET)
-		    return NULL;
 		v->value = earg;
 	    }
 #if LOG
@@ -584,6 +604,8 @@
 
     while (1)
     {
+	if (!condition)
+	    goto Lhead;
 	e = condition->interpret(istate);
 	if (e == EXP_CANT_INTERPRET)
 	    break;
@@ -592,7 +614,9 @@
 	    break;
 	}
 	if (e->isBool(TRUE))
-	{   e = body ? body->interpret(istate) : NULL;
+	{
+	Lhead:
+	    e = body ? body->interpret(istate) : NULL;
 	    if (e == EXP_CANT_INTERPRET)
 		break;
 	    if (e == EXP_BREAK_INTERPRET)
@@ -602,9 +626,12 @@
 	    if (e && e != EXP_CONTINUE_INTERPRET)
 		break;
 	Lcontinue:
-	    e = increment->interpret(istate);
-	    if (e == EXP_CANT_INTERPRET)
-		break;
+	    if (increment)
+	    {
+		e = increment->interpret(istate);
+		if (e == EXP_CANT_INTERPRET)
+		    break;
+	    }
 	}
 	else if (e->isBool(FALSE))
 	{   e = NULL;