Hello Dave 

Thank you for the reply and I have another query. 

I could visualize that ContextVisitor is used to setting and retrieving the 
context for each node. Thus using the current context returned by the 
ContextVisitor I was able to set the context for the "async" node (generated by 
me). Each async requires a "closure" as a parameter and this closure should not 
be accepting any parameters. But when the java code is generated I see that a 
Closure class is generated. To the "runAsync()" method an instance of this 
Closure class is passed which accepts some parameters. These parameters are the 
variables which may be used inside the "async" but are not declared within the 
"async". Also the Closure class has its own set of these variables which get 
initialized by its constructor during call to "runAsync()". 

Interestingly in the code generated by me all the free variables that may be 
used by the "async body" are not captured by the Closure class. For generation 
of an "async" node, is "AsyncSynth" the right class? If it is so then how come 
the Closure generated in the "getStmt()" method (present in AsyncSynth class) 
not capturing the free variables. Even though I tried to modify the "getStmt()" 
method such that Closure generated gets a list of parameters, that didn't seem 
to work. 

Thank you 

Regards 

Suyash 


From: "David P Grove" <gro...@us.ibm.com> 
To: "Mailing list for users of the X10 programming language" 
<x10-users@lists.sourceforge.net> 
Sent: Thursday, March 27, 2014 3:40:52 AM 
Subject: Re: [X10-users] Regarding Context for X10 AST nodes 



suy...@cse.iitm.ac.in wrote on 03/26/2014 12:46:45 PM: 
> 
> I am currently working on X10 compiler as I wish to implement an 
> optimization in it. For this purpose I have to modify the existing 
> AST and add new nodes in the AST. For this purpose I believe methods 
> of the classes AltSynthesizer, Synthesizer and AsyncSynth come into 
> use. I have been able to construct most of the nodes for my 
> optimization except for "Async". I wish to add a new AST node for 
> "Async" and that I can do with the help of "getStmt()" method in 
> "AsyncSynth". 
> 
> But for async creation it requires a "Context". Now if I have a code 
> something like this: 
> 
> for(var j:Int=0; j<m; j++) { 
> val ni=j; 
> async { 
> for(var i:Int=0; i<n; i++) { 
> ..... 
> } 
> } 
> } 
> 
> Then what all would be part of the context of "async", outer and 
> inner "for" loop. Will only be type information be pushed and will 
> context for all of these be separate "Kind". For the two loops I 
> created an "emptyContext()" and that was working. So I was able to 
> add nested loops to the AST. But as soon as I added an "Async" and 
> passed an "emptyContext()" to it, the program started error. I am 
> actually stuck with how and with what to set the context for these 
> constructs. 
> 

Hi, 

The usual pattern is to use a ContextVisitor (or subclass of ContextVisitor). 
Then the context is maintained by the visitor as scopes are entered/exited and 
local decls encountered and is simply available as an instance field of the 
visitor (context) when visiting a node. 

--dave 

------------------------------------------------------------------------------ 

_______________________________________________ 
X10-users mailing list 
X10-users@lists.sourceforge.net 
https://lists.sourceforge.net/lists/listinfo/x10-users 
------------------------------------------------------------------------------
_______________________________________________
X10-users mailing list
X10-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/x10-users

Reply via email to