[pypy-svn] r7207 - pypy/trunk/src/pypy/annotation

arigo at codespeak.net arigo at codespeak.net
Thu Nov 11 11:17:40 CET 2004


Author: arigo
Date: Thu Nov 11 11:17:39 2004
New Revision: 7207

Modified:
   pypy/trunk/src/pypy/annotation/binaryop.py
   pypy/trunk/src/pypy/annotation/builtin.py
   pypy/trunk/src/pypy/annotation/model.py
   pypy/trunk/src/pypy/annotation/unaryop.py
Log:
Added SomeChar annotation for strings of length 1.


Modified: pypy/trunk/src/pypy/annotation/binaryop.py
==============================================================================
--- pypy/trunk/src/pypy/annotation/binaryop.py	(original)
+++ pypy/trunk/src/pypy/annotation/binaryop.py	Thu Nov 11 11:17:39 2004
@@ -4,7 +4,7 @@
 
 from pypy.annotation.pairtype import pair, pairtype
 from pypy.annotation.model import SomeObject, SomeInteger, SomeBool
-from pypy.annotation.model import SomeString, SomeList, SomeDict
+from pypy.annotation.model import SomeString, SomeChar, SomeList, SomeDict
 from pypy.annotation.model import SomeTuple, SomeImpossibleValue
 from pypy.annotation.model import SomeInstance, SomeFunction, SomeMethod
 from pypy.annotation.model import SomeBuiltin, SomeIterator
@@ -154,6 +154,12 @@
         generalize(lst1.factories, s_value)
 
 
+class __extend__(pairtype(SomeString, SomeInteger)):
+
+    def getitem((str1, int2)):
+        return SomeChar()
+
+
 class __extend__(pairtype(SomeInteger, SomeList)):
     
     def mul((int1, lst2)):

Modified: pypy/trunk/src/pypy/annotation/builtin.py
==============================================================================
--- pypy/trunk/src/pypy/annotation/builtin.py	(original)
+++ pypy/trunk/src/pypy/annotation/builtin.py	Thu Nov 11 11:17:39 2004
@@ -2,7 +2,7 @@
 Built-in functions.
 """
 
-from pypy.annotation.model import SomeInteger, SomeObject
+from pypy.annotation.model import SomeInteger, SomeObject, SomeChar
 from pypy.annotation.factory import ListFactory, getbookkeeper
 import pypy.objspace.std.restricted_int
 
@@ -27,6 +27,9 @@
 def restricted_uint(s_obj):    # for r_uint
     return SomeInteger(nonneg=True, unsigned=True)
 
+def builtin_chr(s_int):
+    return SomeChar()
+
 
 # collect all functions
 import __builtin__

Modified: pypy/trunk/src/pypy/annotation/model.py
==============================================================================
--- pypy/trunk/src/pypy/annotation/model.py	(original)
+++ pypy/trunk/src/pypy/annotation/model.py	Thu Nov 11 11:17:39 2004
@@ -69,6 +69,9 @@
     "Stands for an object which is known to be a string."
     knowntype = str
 
+class SomeChar(SomeString):
+    "Stands for an object known to be a string of length 1."
+
 class SomeList(SomeObject):
     "Stands for a homogenous list of any length."
     knowntype = list

Modified: pypy/trunk/src/pypy/annotation/unaryop.py
==============================================================================
--- pypy/trunk/src/pypy/annotation/unaryop.py	(original)
+++ pypy/trunk/src/pypy/annotation/unaryop.py	Thu Nov 11 11:17:39 2004
@@ -5,7 +5,7 @@
 from types import FunctionType
 from pypy.annotation.pairtype import pair
 from pypy.annotation.model import SomeObject, SomeInteger, SomeBool
-from pypy.annotation.model import SomeString, SomeList, SomeDict
+from pypy.annotation.model import SomeString, SomeChar, SomeList, SomeDict
 from pypy.annotation.model import SomeTuple, SomeImpossibleValue
 from pypy.annotation.model import SomeInstance, SomeBuiltin, SomeClass
 from pypy.annotation.model import SomeFunction, SomeMethod, SomeIterator
@@ -68,6 +68,18 @@
         return SomeIterator(lst.s_item)
 
 
+class __extend__(SomeString):
+
+    def iter(str):
+        return SomeIterator(SomeChar())
+
+
+class __extend__(SomeChar):
+
+    def len(chr):
+        return immutablevalue(1)
+
+
 class __extend__(SomeIterator):
 
     def next(itr):



More information about the Pypy-commit mailing list