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

fijal at codespeak.net fijal at codespeak.net
Thu Nov 8 21:19:53 CET 2007


Author: fijal
Date: Thu Nov  8 21:19:53 2007
New Revision: 48444

Modified:
   pypy/branch/pypy-rpython-unicode/rpython/ootypesystem/ootype.py
   pypy/branch/pypy-rpython-unicode/rpython/ootypesystem/rstr.py
Log:
Squash few failures, now 7 out of 13 tests are failing


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 21:19:53 2007
@@ -400,13 +400,13 @@
 
 # WARNING: the name 'StringBuilder' is rebound at the end of file
 class StringBuilder(BuiltinADTType):
-    def __init__(self):
+    def __init__(self, STRINGTP, CHARTP):
         self._null = _null_string_builder(self)
         self._GENERIC_METHODS = frozendict({
             "ll_allocate": Meth([Signed], Void),
-            "ll_append_char": Meth([Char], Void),
-            "ll_append": Meth([String], Void),
-            "ll_build": Meth([], String),
+            "ll_append_char": Meth([CHARTP], Void),
+            "ll_append": Meth([STRINGTP], Void),
+            "ll_build": Meth([], STRINGTP),
             })
         self._setup_methods({})
 
@@ -1191,7 +1191,7 @@
         # do nothing
 
     def ll_append_char(self, ch):
-        assert isinstance(ch, str) and len(ch) == 1
+        assert isinstance(ch, basestring) and len(ch) == 1
         self._buf.append(ch)
 
     def ll_append(self, s):
@@ -1199,7 +1199,10 @@
         self._buf.append(s._str)
 
     def ll_build(self):
-        return make_string(''.join(self._buf))
+        if self._TYPE is StringBuilder:
+            return make_string(''.join(self._buf))
+        else:
+            return make_unicode(u''.join(self._buf))
 
 class _null_string_builder(_null_mixin(_string_builder), _string_builder):
     def __init__(self, STRING_BUILDER):
@@ -1597,6 +1600,9 @@
 ROOT = Instance('Root', None, _is_root=True)
 String = String()
 Unicode = Unicode()
-StringBuilder = StringBuilder()
+UnicodeBuilder = StringBuilder(Unicode, UniChar)
+StringBuilder = StringBuilder(String, Char)
+String.builder = StringBuilder
+Unicode.builder = UnicodeBuilder
 WeakReference = WeakReference()
 dead_wref = new(WeakReference)

Modified: pypy/branch/pypy-rpython-unicode/rpython/ootypesystem/rstr.py
==============================================================================
--- pypy/branch/pypy-rpython-unicode/rpython/ootypesystem/rstr.py	(original)
+++ pypy/branch/pypy-rpython-unicode/rpython/ootypesystem/rstr.py	Thu Nov  8 21:19:53 2007
@@ -4,14 +4,15 @@
      AbstractUniCharRepr, AbstractStringIteratorRepr,\
      AbstractLLHelpers, AbstractUnicodeRepr
 from pypy.rpython.rmodel import IntegerRepr
-from pypy.rpython.lltypesystem.lltype import Ptr, Char, UniChar
+from pypy.rpython.lltypesystem.lltype import Ptr, Char, UniChar, typeOf
 from pypy.rpython.ootypesystem import ootype
+from pypy.rpython.rmodel import Repr
 
 # TODO: investigate if it's possible and it's worth to concatenate a
 # String and a Char directly without passing to Char-->String
 # conversion
 
-class AbstractOOStringRepr(AbstractStringRepr):
+class BaseOOStringRepr(Repr):
 
     def __init__(self, *args):
         AbstractStringRepr.__init__(self, *args)
@@ -39,14 +40,14 @@
         return c_length, v_lst
 
 
-class StringRepr(AbstractOOStringRepr):
+class StringRepr(BaseOOStringRepr, AbstractStringRepr):
     lowleveltype = ootype.String
     basetype = str
 
     def make_string(self, value):
         return ootype.make_string(value)
 
-class UnicodeRepr(AbstractOOStringRepr, AbstractUnicodeRepr):
+class UnicodeRepr(BaseOOStringRepr, AbstractUnicodeRepr):
     lowleveltype = ootype.Unicode
     basetype = basestring
 
@@ -72,8 +73,8 @@
     def ll_chr2str(ch):
         return ootype.oostring(ch, -1)
 
-    def ll_str2unicode(s):
-        return s
+    #def ll_str2unicode(s):
+    #    return ootype.oounicode(s, -1)
 
     def ll_unichr2unicode(ch):
         return ootype.oounicode(ch, -1)
@@ -87,7 +88,10 @@
     def ll_char_mul(ch, times):
         if times < 0:
             times = 0
-        buf = ootype.new(ootype.StringBuilder)
+        if typeOf(ch) == Char:
+            buf = ootype.new(ootype.StringBuilder)
+        else:
+            buf = ootype.new(ootype.UnicodeBuilder)
         buf.ll_allocate(times)
         i = 0
         while i<times:
@@ -109,7 +113,7 @@
 
     def ll_join(s, length_dummy, lst):
         length = lst.ll_length()
-        buf = ootype.new(ootype.StringBuilder)
+        buf = ootype.new(typeOf(s).builder)
 
         # TODO: check if it's worth of preallocating the buffer with
         # the exact length
@@ -133,7 +137,10 @@
         return buf.ll_build()
 
     def ll_join_chars(length_dummy, lst):
-        buf = ootype.new(ootype.StringBuilder)
+        if typeOf(lst)._ITEMTYPE == Char:
+            buf = ootype.new(ootype.StringBuilder)
+        else:
+            buf = ootype.new(ootype.UnicodeBuilder)
         length = lst.ll_length()
         buf.ll_allocate(length)
         i = 0
@@ -143,7 +150,10 @@
         return buf.ll_build()
 
     def ll_join_strs(length_dummy, lst):
-        buf = ootype.new(ootype.StringBuilder)
+        if typeOf(lst)._ITEMTYPE == ootype.String:
+            buf = ootype.new(ootype.StringBuilder)
+        else:
+            buf = ootype.new(ootype.UnicodeBuilder)
         length = lst.ll_length()
         #buf.ll_allocate(length)
         i = 0



More information about the Pypy-commit mailing list