On 26.03.2007, at 23:30, Simon Burton wrote:

>
> The attached script is an attempt to get __str__ to work in rpython.
> After annotation, it looks for str(someinstance), rewriting the  
> block to call __str__.
> Then the modified blocks are fed back into the annotator.
>
> It seems to work. (And now i know a lot more about the internals of  
> the translation process...)
>
> I had a think about over-riding consider_op_str. It would seem  
> natural for this code
> to go there, but the annotator is not really set up to handle  
> rewriting.

This looks good, congrats!

I had a different approach in mind which
would work without explicitly adding a pass to the
annotator, no idea which idea is more practical.

What I wanted to do is a tiny patch to flow space
that allows to add little plugins for extension.
My plugin would intercept things like str(...)
during flowing, and rewrite accordingly. This is quite
similar to what you did, but does things earlier.

I'm not sure about this yet, but I think when doing
these things after annotation, then there might be
some trouble with annotating certain things, especially
when I think of supporting __add__ and friends. It might
be necessary to do this expansion earlier to make
annotation work. As I'm writing this, I'm now pretty
sure that this is true.

Conclusion (should think before writing)

My idea (and plan) in general is to add an interceptor
plugin to flow space (or a subclass, trying to make tiny
additions only that don't break anything).
Then all special methods are checked for all operations
and the code is inserted, like a preprocessor during flowing.

cheers - chris
_______________________________________________
[email protected]
http://codespeak.net/mailman/listinfo/pypy-dev

Reply via email to