[pypy-svn] r48362 - in pypy/branch/pypy-rpython-unicode/rpython: . lltypesystem test

fijal at codespeak.net fijal at codespeak.net
Wed Nov 7 16:04:58 CET 2007


Author: fijal
Date: Wed Nov  7 16:04:57 2007
New Revision: 48362

Modified:
   pypy/branch/pypy-rpython-unicode/rpython/lltypesystem/rstr.py
   pypy/branch/pypy-rpython-unicode/rpython/rstr.py
   pypy/branch/pypy-rpython-unicode/rpython/test/test_rstr.py
Log:
unichr -> unicode translation


Modified: pypy/branch/pypy-rpython-unicode/rpython/lltypesystem/rstr.py
==============================================================================
--- pypy/branch/pypy-rpython-unicode/rpython/lltypesystem/rstr.py	(original)
+++ pypy/branch/pypy-rpython-unicode/rpython/lltypesystem/rstr.py	Wed Nov  7 16:04:57 2007
@@ -8,12 +8,12 @@
 from pypy.rpython.rmodel import inputconst, IntegerRepr
 from pypy.rpython.rstr import AbstractStringRepr,AbstractCharRepr,\
      AbstractUniCharRepr, AbstractStringIteratorRepr,\
-     AbstractLLHelpers
+     AbstractLLHelpers, AbstractUnicodeRepr
 from pypy.rpython.lltypesystem import ll_str
 from pypy.rpython.lltypesystem.lltype import \
      GcStruct, Signed, Array, Char, UniChar, Ptr, malloc, \
      Bool, Void, GcArray, nullptr, pyobjectptr, cast_primitive, typeOf
-
+from pypy.rpython.rmodel import Repr
 
 # ____________________________________________________________
 #
@@ -33,11 +33,7 @@
 CONST_STR_CACHE = WeakValueDictionary()
 CONST_UNICODE_CACHE = WeakValueDictionary()
 
-class BaseStringRepr(AbstractStringRepr):
-    def __init__(self, *args):
-        AbstractStringRepr.__init__(self, *args)
-        self.ll = LLHelpers
-
+class BaseLLStringRepr(Repr):
     def convert_const(self, value):
         if value is None:
             return nullptr(self.lowleveltype.TO)
@@ -73,24 +69,26 @@
         v_items = hop.gendirectcall(LIST.ll_items, v_lst)
         return v_length, v_items
 
-class StringRepr(BaseStringRepr):
+class StringRepr(BaseLLStringRepr, AbstractStringRepr):
     lowleveltype = Ptr(STR)
     basetype = str
     base = Char
     CACHE = CONST_STR_CACHE
 
     def __init__(self, *args):
-        BaseStringRepr.__init__(self, *args)
+        AbstractStringRepr.__init__(self, *args)
+        self.ll = LLHelpers
         self.malloc = mallocstr
     
-class UnicodeRepr(BaseStringRepr):
+class UnicodeRepr(BaseLLStringRepr, AbstractUnicodeRepr):
     lowleveltype = Ptr(UNICODE)
     basetype = basestring
     base = UniChar
     CACHE = CONST_UNICODE_CACHE
 
     def __init__(self, *args):
-        BaseStringRepr.__init__(self, *args)
+        AbstractUnicodeRepr.__init__(self, *args)
+        self.ll = LLHelpers
         self.malloc = mallocunicode
 
 class CharRepr(AbstractCharRepr, StringRepr):
@@ -802,6 +800,7 @@
 
 StringRepr.repr = string_repr
 UnicodeRepr.repr = unicode_repr
+UniCharRepr.repr = unicode_repr
 
 class BaseStringIteratorRepr(AbstractStringIteratorRepr):
 

Modified: pypy/branch/pypy-rpython-unicode/rpython/rstr.py
==============================================================================
--- pypy/branch/pypy-rpython-unicode/rpython/rstr.py	(original)
+++ pypy/branch/pypy-rpython-unicode/rpython/rstr.py	Wed Nov  7 16:04:57 2007
@@ -16,7 +16,10 @@
 class AbstractCharRepr(AbstractStringRepr):
     pass
 
-class AbstractUniCharRepr(Repr):
+class AbstractUniCharRepr(AbstractStringRepr):
+    pass
+
+class AbstractUnicodeRepr(AbstractStringRepr):
     pass
 
 class __extend__(annmodel.SomeString):
@@ -496,10 +499,12 @@
 #
 # _________________________ Conversions _________________________
 
-class __extend__(pairtype(AbstractCharRepr, AbstractStringRepr)):
+class __extend__(pairtype(AbstractCharRepr, AbstractStringRepr),
+                 pairtype(AbstractUniCharRepr, AbstractUnicodeRepr)):
     def convert_from_to((r_from, r_to), v, llops):
         rstr = llops.rtyper.type_system.rstr
-        if r_from == rstr.char_repr and r_to == rstr.string_repr:
+        if (r_from == rstr.char_repr and r_to == rstr.string_repr) or\
+           (r_from == rstr.unichar_repr and r_to == rstr.unicode_repr):
             return llops.gendirectcall(r_from.ll.ll_chr2str, v)
         return NotImplemented
 

Modified: pypy/branch/pypy-rpython-unicode/rpython/test/test_rstr.py
==============================================================================
--- pypy/branch/pypy-rpython-unicode/rpython/test/test_rstr.py	(original)
+++ pypy/branch/pypy-rpython-unicode/rpython/test/test_rstr.py	Wed Nov  7 16:04:57 2007
@@ -90,13 +90,14 @@
             assert res is True
         
     def test_char_constant(self):
+        const = self.const
         def fn(s):
-            return s + '.'
-        res = self.interpret(fn, ['x'])
+            return s + const('.')
+        res = self.interpret(fn, [const('x')])
         res = self.ll_to_string(res)
         assert len(res) == 2
-        assert res[0] == 'x'
-        assert res[1] == '.'
+        assert res[0] == const('x')
+        assert res[1] == const('.')
 
     def test_char_isxxx(self):
         def fn(s):



More information about the Pypy-commit mailing list