Blocks with return values in compiler

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Blocks with return values in compiler

Gamehaxe
Hi Nicolas,
Since you have been so helpful so far, I have another one for you.
Is there any way to directly tell from the AST the difference
between these two blocks:

var y = { var x = 5; x * x; }

and

{ var x = 5; x * x; }

ie, they differ only in the fact the the "return value" is used.
They both have "etype" Int.
I can track whether a block is used and go from that but
if there is a more elegant way it would be useful.

Thanks in advance,

Hugh

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Blocks with return values in compiler

Nicolas Cannasse
Hugh Sanderson a écrit :

> Hi Nicolas,
> Since you have been so helpful so far, I have another one for you.
> Is there any way to directly tell from the AST the difference
> between these two blocks:
>
> var y = { var x = 5; x * x; }
>
> and
>
> { var x = 5; x * x; }
>
> ie, they differ only in the fact the the "return value" is used.
> They both have "etype" Int.
> I can track whether a block is used and go from that but
> if there is a more elegant way it would be useful.

Tracking if a value is indeed used or not is done per-generator.

Check how the "retval" parameter is passed through functions in genSWF8
and genSWF9.

I could add these informations in the AST by adding the case :
   TIgnore of expr
But that would greatly increase the size of the AST, and not all
generators need this information.

Best,
Nicolas

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Blocks with return values in compiler

Gamehaxe
Ok, no worries, I already do this.  I'll rename my variable retval
can carry on.  If you ever find a compelling readon for TIgnore, I
can update later.

Hugh

> Hugh Sanderson a écrit :
>> Hi Nicolas,
>> Since you have been so helpful so far, I have another one for you.
>> Is there any way to directly tell from the AST the difference
>> between these two blocks:
>>  var y = { var x = 5; x * x; }
>>  and
>>  { var x = 5; x * x; }
>>  ie, they differ only in the fact the the "return value" is used.
>> They both have "etype" Int.
>> I can track whether a block is used and go from that but
>> if there is a more elegant way it would be useful.
>
> Tracking if a value is indeed used or not is done per-generator.
>
> Check how the "retval" parameter is passed through functions in genSWF8  
> and genSWF9.
>
> I could add these informations in the AST by adding the case :
>    TIgnore of expr
> But that would greatly increase the size of the AST, and not all  
> generators need this information.
>
> Best,
> Nicolas
>



--
haXe - an open source web programming language
http://haxe.org