[Compiler-sig] merging branches

Jeremy Hylton jeremy at alum.mit.edu
Wed Oct 19 23:08:11 CEST 2005


I think you're right that there is no way to treat nodes generically. 
Perhaps we should generate some generic traversal code-- something
that takes an AST node and a function pointer of visitor functions. 
It walks the AST and calls each visitor function as the node is
encountered (the function could be NULL in which case nothing is
done).  Then it would be easy to write little analyses like the one
for if 0:.

Jeremy

On 10/19/05, Neil Schemenauer <nas at arctrix.com> wrote:
> [Note: compiler-sig added to Cc list]
>
> On Wed, Oct 19, 2005 at 01:00:08PM -0600, Neil Schemenauer wrote:
> > On Wed, Oct 19, 2005 at 11:28:06AM -0400, Jeremy Hylton wrote:
> > > test_02_arigo (__main__.TraceTestCase) ... FAIL
> >
> > This one fails because the new compiler does dead code elimination
> > for "while 0" but not for "if 0".  I've added optimization for "if
> > 0" and disabled the "while 0" optimization for now.
>
> Oops, the "if 0" optimization is tricker than I thought.  The new
> compiler needs something like look_for_offending_return() to detect
> illegal "return" statements inside generator functions.  It's harder
> to do in the new compiler because nodes cannot be treated
> generically (the look_for_offending_return() is pretty simple and
> just self recurses).
>
> This check needs to be done after the symtable does its pass
> (symtable_visit_expr and friends).   I wonder if it would be a good
> idea to add another general pass that runs between the symtable
> building and the code generation.  Initially it would only check for
> illegal return statements but if we wanted to add pychecker type
> stuff in the future then that would seem to be the place to do it.
>
> Am I making this more complicated then it needs to be?  Maybe I'm
> missing some easy way to write a look_for_offending_return()
> equivalent.
>
>   Neil
>


More information about the Compiler-sig mailing list