Hi Eric,
On Sat, May 28, 2005 at 03:52:15PM +0200, Eric van Riet Paap wrote:
> *def h(n):
> return not n*
>
> An additional block is generated. Is this something that should/can be
> avoided by the annotator?
This is due to the ultimate source of the flow graph, which is the
pypy/interpreter/*.py code itself. We have something called
space.not_() which is not really an operation per se, but a shortcut
defined in baseobjspace.py:
def not_(self, w_obj):
return self.wrap(not self.is_true(w_obj))
('self' is the space here.) The self.is_true() is responsible for
creating the branch in the flow graph. Looking at the generated flow
graphs like you do is, I guess, a good way to detect when is_true() is
used a bit too much. In this case, it should be possible to rewrite
not_() without using it, but using the 'space.nonzero()' operation
instead. (The difference between nonzero() and is_true() is that
nonzero() is a regular operation returning a wrapped boolean, which the
flow graph translates as just one line in a block; is_true() returns a
real True or False and the flow graph must generate a branch, where each
branch records what occurs in each of the two cases.) E.g., this looks
convoluted but does the trick:
def not_(self, w_obj):
return self.xor(self.nonzero(w_obj), self.w_True)
Armin
_______________________________________________
[email protected]
http://codespeak.net/mailman/listinfo/pypy-dev