[Python-Dev] Policy for making changes to the AST (original) (raw)

Dino Viehland dinov at microsoft.com
Mon Apr 4 22:05:11 CEST 2011


Terry wrote:

Are at least some of the implementation methods similar enough that they could use the same AST? It is, after all, a semantic translation into another language, and that need not depend on subsequent transforation and compilation to the ultimate target. A multiple-implementation AST could still be x.y dependent.

For IronPython we have our own AST which is closely tied to the DLR ASTs (our AST nodes are actually subclasses of the core DLR Expression node which then "reduce" to the core DLR nodes on-demand). We already do a huge amount of manipulation of those ASTs from optimizations (constant folding being the primary one) to re-writing them completely for things like generators or sys.settrace support and other optimizations like runtime optimized fast exception support. But our ASTs are probably sufficiently different and sufficiently tied to the DLR that we couldn't share the exact same optimizations on the ASTs but it would probably make it easier to steal ideas from CPython if you did them at the AST level as well.

They also have other differences such as the fact that they're effectively immutable. Likely when we implement the _ast module it'll just transform our ASTs into the shared ASTs via some additional attributes we attach to our ASTs rather than making them the core AST implementation.



More information about the Python-Dev mailing list