FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Java & D function evaluation order

 
Post new topic   Reply to topic     Forum Index -> Tioport
View previous topic :: View next topic  
Author Message
phoenix



Joined: 06 Mar 2005
Posts: 68

PostPosted: Sat Apr 14, 2007 7:45 am    Post subject: Java & D function evaluation order Reply with quote

Hi. While working on JDT code, I've encountered an interesting piece of code that I wonder if Tioport handles correctly (not that I'm using TioPort):

Code:
System.arraycopy(this.children, 0, this.children = new ILangElement[length + 1], 0, length);


This works in Java because the order of evaluation in function calls is well defined (left to right) AND because the arguments are bound to parameters as they are evaluated (and not after all are evaluated).
In D this behavior is unspecified ( http://www.digitalmars.com/d/expression.html , Evaluation Order), even tough DMD seems to follow a Java-like behavior. (haven't tried gdc)
_________________
Bruno Medeiros
Back to top
View user's profile Send private message
keinfarbton



Joined: 03 Dec 2005
Posts: 224
Location: Stuttgart - Germany

PostPosted: Sun Apr 15, 2007 4:47 am    Post subject: Reply with quote

This is a problem i also have noticed. TioPort also has special code to handle such things.
http://dsource.org/projects/tioport/wiki/EvalOrder

But I was not aware of the case of eval order in method calls Confused
Actually TioPort handles the bitwise or/and/xor operations.

How can your example call be rewritten in D to work? Is it possible without temporary variables?

I will need to add this functionality for method calls to TioPort.
Back to top
View user's profile Send private message
keinfarbton



Joined: 03 Dec 2005
Posts: 224
Location: Stuttgart - Germany

PostPosted: Sun Apr 15, 2007 5:15 am    Post subject: Reply with quote

With temporary variables this can be refactored to:

Code:

Type tempvar1 = void;
Type tempvar2 = void;
int tempvar3 = void;
( tempvar1 = this.children, tempvar2 = this.children = new ILangElement[length + 1], tempvar3 = length, System.arraycopy(tempvar1, 0, tempvar2, 0, tempvar3));
Back to top
View user's profile Send private message
phoenix



Joined: 06 Mar 2005
Posts: 68

PostPosted: Thu Apr 26, 2007 4:46 am    Post subject: Reply with quote

For those interested, I made a post in the NG about this.
-> news://news.digitalmars.com:119/f0pvsn$1pju$1@digitalmars.com
_________________
Bruno Medeiros
Back to top
View user's profile Send private message
jcc7



Joined: 22 Feb 2004
Posts: 657
Location: Muskogee, OK, USA

PostPosted: Thu Apr 26, 2007 6:58 am    Post subject: Reply with quote

phoenix wrote:
For those interested, I made a post in the NG about this.
-> news://news.digitalmars.com:119/f0pvsn$1pju$1@digitalmars.com

FYI, this is the corresponding WebNews link.
Back to top
View user's profile Send private message AIM Address
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> Tioport All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group