[Cython] Patch ready (was: Re: Done with prototype for "parse tree transforms")
Dag Sverre Seljebotn
dagss at student.matnat.uio.no
Sat Mar 8 13:43:42 CET 2008
Robert Bradshaw wrote:
> This looks very, very interesting and promising. I was thinking about
> code transformations like this quite a while ago for optimization
> reasons. I think this is the way to go.
In that case, I've cleaned it up a little bit and now submit it as a
patch against the current cython-devel repo (see attachment); I believe
it is ready for inclusion in the cython-devel branch if you approve.
It doesn't *do* anything currently, and really shouldn't affect
behaviour if one doesn't use the new -T switch (so regression testing
for this patch can be done simply by checking that the same code is
generated for a lot of examples -- I didn't take time for this though).
However placing it in the main repository means that more people than
myself can start playing with applying transforms that actually does
something.
Changes:
A little code has been added all over the place, but most of it doesn't
"interact" at all with existing code, unless you count declaring new
symbols. The diff is small enough that you can simply read it .. the
"worst" parts:
- Node.generate_function_definitions got an extra argument everywhere
(but I grepped for usages and am pretty sure I fixed all calls, at least
within the Compiler module).
- FuncDefNode.generate_function_definitions has calls to the transforms
added:
self.declare_arguments(lenv)
+ transforms.run('before_analyse_function', self, env=env,
lenv=lenv, genv=genv)
self.body.analyse_declarations(lenv)
self.body.analyse_expressions(lenv)
+ transforms.run('after_analyse_function', self, env=env,
lenv=lenv, genv=genv)
(Without program arguments, these will iterate an empty list and return.)
Known problems:
- Only two cut-points/phases for transforms are provided, and more are
neeeded, especially one in-between type deduction and type coercion, but
this requires more intrusive refactoring that is better left for a
seperate commit. This gives a start though.
- The lists of which attributes for each node constitute "children" in
the tree can probably be tuned a bit, however this is best left for when
one actually have a use-case (transform) making use of the node type in
question.
Dag Sverre
-------------- next part --------------
A non-text attachment was scrubbed...
Name: treetransform.diff
Type: text/x-patch
Size: 30685 bytes
Desc: not available
Url : http://codespeak.net/pipermail/cython-dev/attachments/20080308/2b779953/attachment-0001.bin
More information about the Cython-dev
mailing list