[pypy-svn] r14600 - in pypy/dist/pypy: objspace/std translator translator/test

arigo at codespeak.net arigo at codespeak.net
Wed Jul 13 01:02:37 CEST 2005


Author: arigo
Date: Wed Jul 13 01:02:33 2005
New Revision: 14600

Modified:
   pypy/dist/pypy/objspace/std/listsort.py
   pypy/dist/pypy/translator/annrpython.py
   pypy/dist/pypy/translator/test/test_annrpython.py
Log:
Preserve a meaningful knowntypedata across links, by renaming the variables.

Gave up on nonneg in listsort.py, and added an explicit assert just before the
slicing.



Modified: pypy/dist/pypy/objspace/std/listsort.py
==============================================================================
--- pypy/dist/pypy/objspace/std/listsort.py	(original)
+++ pypy/dist/pypy/objspace/std/listsort.py	Wed Jul 13 01:02:33 2005
@@ -183,7 +183,6 @@
                 ofs = m         # key <= a[m]
 
         assert lastofs == ofs         # so a[ofs-1] < key <= a[ofs]
-        assert ofs >= 0               # annotator hint
         return ofs
 
     # hint for the annotator: the argument 'rightmost' is always passed in as
@@ -554,35 +553,30 @@
     "A sublist of a list."
 
     def __init__(self, list, base, len):
-        assert base >= 0
-        assert len >= 0
         self.list = list
         self.base = base
         self.len  = len
 
     def copyitems(self):
         "Make a copy of the slice of the original list."
-        return ListSlice(self.list[self.base:self.base+self.len], 0, self.len)
+        start = self.base
+        stop  = self.base + self.len
+        assert 0 <= start <= stop     # annotator hint
+        return ListSlice(self.list[start:stop], 0, self.len)
 
     def advance(self, n):
         self.base += n
-        len = self.len - n
-        assert len >= 0      # annotator hint, don't remove
-        self.len = len
+        self.len -= n
 
     def popleft(self):
         result = self.list[self.base]
         self.base += 1
-        len = self.len - 1
-        assert len >= 0      # annotator hint, don't remove
-        self.len = len
+        self.len -= 1
         return result
 
     def popright(self):
-        len = self.len - 1
-        assert len >= 0      # annotator hint, don't remove
-        self.len = len
-        return self.list[self.base + len]
+        self.len -= 1
+        return self.list[self.base + self.len]
 
     def reverse(self):
         "Reverse the slice in-place."

Modified: pypy/dist/pypy/translator/annrpython.py
==============================================================================
--- pypy/dist/pypy/translator/annrpython.py	(original)
+++ pypy/dist/pypy/translator/annrpython.py	Wed Jul 13 01:02:33 2005
@@ -532,6 +532,20 @@
                             newcell.const = cell.const
                         cell = newcell
                         cell.is_type_of = renamed_is_type_of
+
+                    if hasattr(cell, 'knowntypedata'):
+                        renamed_knowntypedata = {}
+                        for (value, v), s in cell.knowntypedata.items():
+                            new_vs = renaming.get(v, [])
+                            for new_v in new_vs:
+                                renamed_knowntypedata[value, new_v] = s
+                        assert isinstance(cell, annmodel.SomeBool)
+                        newcell = annmodel.SomeBool()
+                        if cell.is_constant():
+                            newcell.const = cell.const
+                        cell = newcell
+                        cell.knowntypedata = renamed_knowntypedata
+
                     cells.append(cell)
 
             if in_except_block:

Modified: pypy/dist/pypy/translator/test/test_annrpython.py
==============================================================================
--- pypy/dist/pypy/translator/test/test_annrpython.py	(original)
+++ pypy/dist/pypy/translator/test/test_annrpython.py	Wed Jul 13 01:02:33 2005
@@ -1264,6 +1264,14 @@
         s = a.build_types(f, [int]*8)
         assert s == annmodel.SomeTuple([annmodel.SomeInteger(nonneg=True)] * 8)
 
+    def test_more_nonneg_cleverness(self):
+        def f(start, stop):
+            assert 0 <= start <= stop
+            return start, stop
+        a = self.RPythonAnnotator()
+        s = a.build_types(f, [int, int])
+        assert s == annmodel.SomeTuple([annmodel.SomeInteger(nonneg=True)] * 2)
+
     def test_attr_moving_into_parent(self):
         class A: pass
         class B(A): pass



More information about the Pypy-commit mailing list