[pypy-svn] r35709 - in pypy/dist/pypy/annotation: . test
arigo at codespeak.net
arigo at codespeak.net
Wed Dec 13 22:45:40 CET 2006
Author: arigo
Date: Wed Dec 13 22:45:38 2006
New Revision: 35709
Modified:
pypy/dist/pypy/annotation/builtin.py
pypy/dist/pypy/annotation/test/test_annrpython.py
Log:
max(nonneg, *whatever) always returns a nonneg.
This is very much a just-because check-in.
Modified: pypy/dist/pypy/annotation/builtin.py
==============================================================================
--- pypy/dist/pypy/annotation/builtin.py (original)
+++ pypy/dist/pypy/annotation/builtin.py Wed Dec 13 22:45:38 2006
@@ -218,7 +218,19 @@
else:
return unionof(*s_values)
-builtin_max = builtin_min
+def builtin_max(*s_values):
+ if len(s_values) == 1: # xxx do we support this?
+ s_iter = s_values[0].iter()
+ return s_iter.next()
+ else:
+ s = unionof(*s_values)
+ if type(s) is SomeInteger:
+ nonneg = False
+ for s1 in s_values:
+ nonneg |= s1.nonneg
+ if nonneg:
+ s = SomeInteger(nonneg=True, knowntype=s.knowntype)
+ return s
def builtin_apply(*stuff):
getbookkeeper().warning("ignoring apply%r" % (stuff,))
Modified: pypy/dist/pypy/annotation/test/test_annrpython.py
==============================================================================
--- pypy/dist/pypy/annotation/test/test_annrpython.py (original)
+++ pypy/dist/pypy/annotation/test/test_annrpython.py Wed Dec 13 22:45:38 2006
@@ -1417,7 +1417,14 @@
wg2 = graphof(a, witness2)
assert a.binding(wg1.getargs()[0]).knowntype is r_ulonglong
assert a.binding(wg2.getargs()[0]).knowntype is r_ulonglong
-
+
+ def test_nonneg_cleverness_in_max(self):
+ def f(x):
+ return max(x, 0) + max(0, x)
+ a = self.RPythonAnnotator()
+ s = a.build_types(f, [int])
+ assert s.nonneg
+
def test_attr_moving_into_parent(self):
class A: pass
class B(A): pass
More information about the Pypy-commit
mailing list