[pypy-svn] r14598 - in pypy/dist/pypy: annotation interpreter objspace/std

arigo at codespeak.net arigo at codespeak.net
Wed Jul 13 00:20:19 CEST 2005


Author: arigo
Date: Wed Jul 13 00:20:13 2005
New Revision: 14598

Modified:
   pypy/dist/pypy/annotation/binaryop.py
   pypy/dist/pypy/interpreter/pycode.py
   pypy/dist/pypy/objspace/std/listobject.py
   pypy/dist/pypy/objspace/std/listsort.py
   pypy/dist/pypy/objspace/std/longobject.py
   pypy/dist/pypy/objspace/std/stringobject.py
   pypy/dist/pypy/objspace/std/strutil.py
   pypy/dist/pypy/objspace/std/typeobject.py
   pypy/dist/pypy/objspace/std/unicodeobject.py
Log:
Minor annotator hints to help it figure out which numbers are non-negative.
This is needed for slicing in the rtyper.



Modified: pypy/dist/pypy/annotation/binaryop.py
==============================================================================
--- pypy/dist/pypy/annotation/binaryop.py	(original)
+++ pypy/dist/pypy/annotation/binaryop.py	Wed Jul 13 00:20:13 2005
@@ -230,7 +230,7 @@
     def lshift((int1, int2)):
         if int1.unsigned:
             return SomeInteger(unsigned=True)
-        return SomeInteger()
+        return SomeInteger(nonneg = int1.nonneg)
     lshift.can_only_throw = [ValueError]
     rshift = lshift
     lshift_ovf = _clone(lshift, [ValueError, OverflowError])
@@ -238,7 +238,7 @@
     def pow((int1, int2), obj3):
         if int1.unsigned or int2.unsigned or getattr(obj3, 'unsigned', False):
             return SomeInteger(unsigned=True)
-        return SomeInteger()
+        return SomeInteger(nonneg = int1.nonneg)
     pow.can_only_throw = [ZeroDivisionError]
     pow_ovf = _clone(pow, [ZeroDivisionError, OverflowError])
 

Modified: pypy/dist/pypy/interpreter/pycode.py
==============================================================================
--- pypy/dist/pypy/interpreter/pycode.py	(original)
+++ pypy/dist/pypy/interpreter/pycode.py	Wed Jul 13 00:20:13 2005
@@ -31,6 +31,7 @@
 def cpython_code_signature(code):
     "([list-of-arg-names], vararg-name-or-None, kwarg-name-or-None)."
     argcount = code.co_argcount
+    assert argcount >= 0     # annotator hint
     argnames = list(code.co_varnames[:argcount])
     if code.co_flags & CO_VARARGS:
         varargname = code.co_varnames[argcount]

Modified: pypy/dist/pypy/objspace/std/listobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/listobject.py	(original)
+++ pypy/dist/pypy/objspace/std/listobject.py	Wed Jul 13 00:20:13 2005
@@ -314,8 +314,8 @@
     if step == 1:  # Support list resizing for non-extended slices
         oldsize = w_list.ob_size
         delta = len2 - slicelength
-        newsize = oldsize + delta
         if delta >= 0:
+            newsize = oldsize + delta
             _list_resize(w_list, newsize)
             w_list.ob_size = newsize
             items = w_list.ob_item

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 00:20:13 2005
@@ -183,6 +183,7 @@
                 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
@@ -553,6 +554,8 @@
     "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
@@ -563,17 +566,23 @@
 
     def advance(self, n):
         self.base += n
-        self.len -= n
+        len = self.len - n
+        assert len >= 0      # annotator hint, don't remove
+        self.len = len
 
     def popleft(self):
         result = self.list[self.base]
         self.base += 1
-        self.len -= 1
+        len = self.len - 1
+        assert len >= 0      # annotator hint, don't remove
+        self.len = len
         return result
 
     def popright(self):
-        self.len -= 1
-        return self.list[self.base + self.len]
+        len = self.len - 1
+        assert len >= 0      # annotator hint, don't remove
+        self.len = len
+        return self.list[self.base + len]
 
     def reverse(self):
         "Reverse the slice in-place."

Modified: pypy/dist/pypy/objspace/std/longobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/longobject.py	(original)
+++ pypy/dist/pypy/objspace/std/longobject.py	Wed Jul 13 00:20:13 2005
@@ -74,7 +74,9 @@
 
     def longval(self): #YYYYYY
         l = 0
-        for d in self.digits[::-1]:
+        digits = list(self.digits)
+        digits.reverse()
+        for d in digits:
             l = l << SHIFT
             l += long(d)
         return l * self.sign

Modified: pypy/dist/pypy/objspace/std/stringobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/stringobject.py	(original)
+++ pypy/dist/pypy/objspace/std/stringobject.py	Wed Jul 13 00:20:13 2005
@@ -599,6 +599,7 @@
         while rpos > lpos and u_self[rpos - 1] in u_chars:
            rpos -= 1
        
+    assert rpos >= lpos    # annotator hint, don't remove
     return space.wrap(u_self[lpos:rpos])
 
 def _strip_none(space, w_self, left, right):
@@ -617,6 +618,7 @@
         while rpos > lpos and _isspace(u_self[rpos - 1]):
            rpos -= 1
        
+    assert rpos >= lpos    # annotator hint, don't remove
     return space.wrap(u_self[lpos:rpos])
 
 def str_strip__String_String(space, w_self, w_chars):

Modified: pypy/dist/pypy/objspace/std/strutil.py
==============================================================================
--- pypy/dist/pypy/objspace/std/strutil.py	(original)
+++ pypy/dist/pypy/objspace/std/strutil.py	Wed Jul 13 00:20:13 2005
@@ -15,6 +15,7 @@
         p += 1
     while p < q and s[q-1] in ' \f\n\r\t\v':
         q -= 1
+    assert q >= p     # annotator hint, don't remove
     return s[p:q]
 
 class ParseStringError(Exception):

Modified: pypy/dist/pypy/objspace/std/typeobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/typeobject.py	(original)
+++ pypy/dist/pypy/objspace/std/typeobject.py	Wed Jul 13 00:20:13 2005
@@ -29,7 +29,11 @@
 
     tlen = len(klass) + len(name)
     if tlen > MANGLE_LEN:
-        klass = klass[:MANGLE_LEN-tlen]
+        end = len(klass) + MANGLE_LEN-tlen
+        if end < 0:
+            klass = ''     # annotator hint
+        else:
+            klass = klass[:end]
 
     return "_%s%s" % (klass, name)
 

Modified: pypy/dist/pypy/objspace/std/unicodeobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/unicodeobject.py	(original)
+++ pypy/dist/pypy/objspace/std/unicodeobject.py	Wed Jul 13 00:20:13 2005
@@ -232,7 +232,11 @@
     uni = w_uni._value
     length = len(uni)
     start, stop, step, sl = slicetype.indices4(space, w_slice, length)
-    return W_UnicodeObject(space, uni[start:stop])
+    if start > stop:
+        return W_UnicodeObject(space, [])
+    else:
+        assert 0 <= start <= stop
+        return W_UnicodeObject(space, uni[start:stop])
 
 def mul__Unicode_ANY(space, w_uni, w_times):
     chars = w_uni._value



More information about the Pypy-commit mailing list