[Cython] When to run tree transformations
Robert Bradshaw
robertwb at math.washington.edu
Sat Mar 15 22:04:35 CET 2008
On Mar 15, 2008, at 3:34 AM, Stefan Behnel wrote:
> Hi,
>
> as I suggested before, I think it would be helpful if plugins could
> tell the
> compiler directly when they were to run (without the current -T
> option). I
> think there would at least be an analysis step in addition to the
> existing
> tree processing step for the plugin lifecycle, but the plugin might
> also need
> to run at different times of the compiler lifecycle, and treat
> different
> syntax structures. I see the following lifecycle hooks here:
>
> - pre analyse types
> - post analyse types
- post type conversion phase?
> - pre generate code
> - post generate code
What would happen in this last one?
> I would suggest mapping these to method names in the plugins. You
> could then write
>
> class MyTransform(Transform):
> def pre_analyse_types(self, node, name):
> ...
>
> instead of the current "process_node()" method.
I think process_node offers more flexibility of phases, which may
change/become more granular later on. Some transforms may need to
know what the current phase is though.
> I could also imagine keeping a set of node types in the plugin that
> would be
> used for selecting appropriate transformations for the current
> node. In the
> transformation example, there is this line
>
> if isinstance(node, Nodes.ForInStatNode) ...
>
> that determines when to run the plugin. If the plugin provided a
> set of
> interesting nodes instead, the infrastructure could store them in a
> dict
> (mapping node types to a list of plugins) and directly select the
> transformations that can run on that node. Question in that case:
> how to deal
> with subtypes? Would they be expected to match? Or should the
> plugin just
> specify all node types, including their expected subtypes?
Perhaps. One would have to come up with a reasonable way to filter
things. The current approach seems the simplest way to get something
up and running.
- Robert
- Robert
More information about the Cython-dev
mailing list