There's no direct support for this but it shouldn't be too hard to do.  You can 
carry the AST around w/ you by doing an Ast.RuntimeConstant(myAstRoot).

For example let's say that we wanted to hold onto the AST for all Python 
functions.  Over in FunctionDefinition.cs we call a helper method called 
MakeFunction to create the real Python function object.  We could add a new 
parameter there (because we don't have enough :)) and then do:

            MSAst.Expression ret = Ast.Call(
                typeof(PythonFunction).GetMethod("MakeFunction"),               
                // method
                Ast.CodeContext(),                                              
                // 1. Emit CodeContext
                Ast.Constant(SymbolTable.IdToString(_name)),                    
                // 2. FunctionName
                Ast.CodeBlockExpression(code, flags != 
FunctionAttributes.None),                // 3. delegate
                Ast.NewArray(typeof(string[]), names),                          
                // 4. parameter names
                Ast.NewArray(typeof(object[]), defaults),                       
                // 5. default values
                Ast.Constant(flags),                                            
                // 6. flags
                Ast.Constant(_body.Documentation, typeof(string)),              
                // 7. doc string or null
                Ast.Constant(this.Start.Line),                                  
                // 8. line number
                Ast.Constant(_sourceUnit.GetSymbolDocument(this.Start.Line), 
typeof(string))    // 9. Filename
                    Ast.Constant(code)          // or maybe code.Body ?
            );


>From there we could then use the AST to create a new AST, create a new 
>CodeBlock, and then replace the delegate the PythonFunction instance holds 
>onto w/ a new delegate.  Unfortunately if there's going to be lots of mutation 
>then there's going to be lots of compilation which isn't going to be too good. 
> You could also try interpreted mode to reduce that overhead (also we do have 
>some profile driven compilation features which could help make this 
>determination for you automatically but they're very naïve at this point).

And as a random thought: does the AST actually need to change or just the 
actions the code performs at runtime?  If the AST just represents the structure 
of the code you could insert a bunch of helper calls who's behavior changes as 
the AST 'mutates'.  As an aside we eventually want to support custom 
DynamicSite's which would enable you to do any 'operation' you care about.  
Once we had that support you could turn these helper calls into dynamic sites 
in order to improve the perf.

That might not have been quite the answer you're looking for but hopefully it's 
some food for thought that will help you determine if you can do what you need.

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of [EMAIL PROTECTED]
Sent: Tuesday, November 13, 2007 6:05 AM
To: users@lists.ironpython.com
Subject: [IronPython] FW: FW: DLR question

>From the silence I'll assume it is :)

I'm prototyping a new language (currently implemented in Python) and I am 
looking at the DLR to see if it can help make it speedy. However my language 
has the property that it can mutate it's own AST at any point, and from reading 
the IronPython and ToyScript sources it looks like the AST of the "source" 
program needs to be static. Is there anything I can make use of in the DLR 
here, or should I be resigned to implementing more than I'd hoped myself?

Cheers,
Ben


________________________________________
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of [EMAIL PROTECTED]
Sent: 13 November 2007 07:53
To: users@lists.ironpython.com
Subject: [IronPython] FW: DLR question

Hi there!

Is this the correct forum for questions about the DLR, or is there a separate 
DLR mailing list somewhere?

Cheers,
Ben

Ben Young - Senior Software Engineer
SunGard - Enterprise House, Vision Park, Histon, Cambridge, CB24 9ZR
Tel +44 1223 266042 - Main +44 1223 266100 - http://www.sungard.com/

CONFIDENTIALITY:  This email (including any attachments) may contain 
confidential, proprietary and privileged information, and unauthorized 
disclosure or use is prohibited.  If you received this email in error, please 
notify the sender and delete this email from your system.  Thank you.

_______________________________________________
Users mailing list
Users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
_______________________________________________
Users mailing list
Users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

Reply via email to