[Python-Dev] a Python interface for the AST (WAS: DRAFT: python-dev...)
Brett Cannon
bcannon at gmail.com
Thu Nov 24 07:52:12 CET 2005
On 11/23/05, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
> Brett Cannon wrote:
>
> > There are two problems to this topic; how to
> > get the AST structs into Python objects and how to allow Python code
> > to modify the AST before bytecode emission
>
> I'm astounded to hear that the AST isn't made from
> Python objects in the first place. Is there a particular
> reason it wasn't done that way?
>
I honestly don't know, Greg. All of the structs are generated by
Parser/asdl_c.py which reads in the AST definition from
Parser/Python.asdl . The code that is used to allocate and initialize
the structs is in Python/Python-ast.c and is also auto-generated by
Parser/asdl_c.py .
I am guessing here, but it might have to do with type safety. Some
nodes can be different kinds of subnodes (like the stmt node) and thus
are created using a single struct and a bunch unions internally. So
there is some added security that stuff is being done correctly.
Otherwise memory is the only other reason I can think of. Or Jeremy
just didn't think of doing it that way when this was all started years
ago. =) But since it is all auto-generated it should be doable to
make them Python objects.
-Brett
More information about the Python-Dev
mailing list