[pypy-svn] r48408 - pypy/branch/pypy-rpython-unicode/rpython/ootypesystem

cfbolz at codespeak.net cfbolz at codespeak.net
Thu Nov 8 13:46:19 CET 2007


Author: cfbolz
Date: Thu Nov  8 13:46:19 2007
New Revision: 48408

Modified:
   pypy/branch/pypy-rpython-unicode/rpython/ootypesystem/ootype.py
Log:
introduce Unicode. check in to have Anto take over.


Modified: pypy/branch/pypy-rpython-unicode/rpython/ootypesystem/ootype.py
==============================================================================
--- pypy/branch/pypy-rpython-unicode/rpython/ootypesystem/ootype.py	(original)
+++ pypy/branch/pypy-rpython-unicode/rpython/ootypesystem/ootype.py	Thu Nov  8 13:46:19 2007
@@ -322,16 +322,14 @@
         return set()
 
 
-# WARNING: the name 'String' is rebound at the end of file
-class String(BuiltinADTType):
-    SELFTYPE_T = object()
+class AbstractString(BuiltinADTType):
 
     def __init__(self):
         self._null = _null_string(self)
 
         generic_types = { self.SELFTYPE_T: self }
         self._GENERIC_METHODS = frozendict({
-            "ll_stritem_nonneg": Meth([Signed], Char),
+            "ll_stritem_nonneg": Meth([Signed], self.CHAR),
             "ll_strlen": Meth([], Signed),
             "ll_strconcat": Meth([self.SELFTYPE_T], self.SELFTYPE_T),
             "ll_streq": Meth([self.SELFTYPE_T], Bool),
@@ -341,25 +339,19 @@
             "ll_find": Meth([self.SELFTYPE_T, Signed, Signed], Signed),
             "ll_rfind": Meth([self.SELFTYPE_T, Signed, Signed], Signed),
             "ll_count": Meth([self.SELFTYPE_T, Signed, Signed], Signed),
-            "ll_find_char": Meth([Char, Signed, Signed], Signed),
-            "ll_rfind_char": Meth([Char, Signed, Signed], Signed),
-            "ll_count_char": Meth([Char, Signed, Signed], Signed),
-            "ll_strip": Meth([Char, Bool, Bool], self.SELFTYPE_T),
+            "ll_find_char": Meth([self.CHAR, Signed, Signed], Signed),
+            "ll_rfind_char": Meth([self.CHAR, Signed, Signed], Signed),
+            "ll_count_char": Meth([self.CHAR, Signed, Signed], Signed),
+            "ll_strip": Meth([self.CHAR, Bool, Bool], self.SELFTYPE_T),
             "ll_upper": Meth([], self.SELFTYPE_T),
             "ll_lower": Meth([], self.SELFTYPE_T),
             "ll_substring": Meth([Signed, Signed], self.SELFTYPE_T), # ll_substring(start, count)
-            "ll_split_chr": Meth([Char], List(self.SELFTYPE_T)),
-            "ll_contains": Meth([Char], Bool),
-            "ll_replace_chr_chr": Meth([Char, Char], self.SELFTYPE_T),
+            "ll_split_chr": Meth([self.CHAR], List(self.SELFTYPE_T)),
+            "ll_contains": Meth([self.CHAR], Bool),
+            "ll_replace_chr_chr": Meth([self.CHAR, self.CHAR], self.SELFTYPE_T),
             })
         self._setup_methods(generic_types)
 
-    def _enforce(self, value):
-        TYPE = typeOf(value)
-        if TYPE == Char:
-            return make_string(value)
-        else:
-            return BuiltinADTType._enforce(self, value)
 
     # TODO: should it return _null or ''?
     def _defl(self):
@@ -373,6 +365,35 @@
     def _specialize(self, generic_types):
         return self
 
+# WARNING: the name 'String' is rebound at the end of file
+class String(AbstractString):
+    SELFTYPE_T = object()
+    CHAR = Char
+
+    def _enforce(self, value):
+        # XXX share this with Unicode?
+        TYPE = typeOf(value)
+        if TYPE == self.CHAR:
+            return make_string(value)
+        else:
+            return BuiltinADTType._enforce(self, value)
+
+
+# WARNING: the name 'Unicode' is rebound at the end of file
+class Unicode(AbstractString):
+    SELFTYPE_T = object()
+    Char = UniChar
+
+    def _enforce(self, value):
+        TYPE = typeOf(value)
+        if TYPE == self.CHAR:
+            return make_unicode(value)
+        else:
+            return BuiltinADTType._enforce(self, value)
+
+
+
+
 # WARNING: the name 'StringBuilder' is rebound at the end of file
 class StringBuilder(BuiltinADTType):
     def __init__(self):
@@ -837,6 +858,10 @@
     assert isinstance(value, str)
     return _string(String, value)
 
+def make_unicode(value):
+    assert isinstance(value, unicode)
+    return _string(Unicode, value)
+
 def make_instance(INSTANCE):
     inst = _instance(INSTANCE)
     if STATICNESS:



More information about the Pypy-commit mailing list