[pypy-svn] r48433 - in pypy/branch/pypy-rpython-unicode/rpython: . ootypesystem

antocuni at codespeak.net antocuni at codespeak.net
Thu Nov 8 20:43:50 CET 2007


Author: antocuni
Date: Thu Nov  8 20:43:50 2007
New Revision: 48433

Modified:
   pypy/branch/pypy-rpython-unicode/rpython/llinterp.py
   pypy/branch/pypy-rpython-unicode/rpython/ootypesystem/ooregistry.py
   pypy/branch/pypy-rpython-unicode/rpython/ootypesystem/ootype.py
   pypy/branch/pypy-rpython-unicode/rpython/ootypesystem/rstr.py
Log:
more work towards ootype unicode



Modified: pypy/branch/pypy-rpython-unicode/rpython/llinterp.py
==============================================================================
--- pypy/branch/pypy-rpython-unicode/rpython/llinterp.py	(original)
+++ pypy/branch/pypy-rpython-unicode/rpython/llinterp.py	Thu Nov  8 20:43:50 2007
@@ -1079,6 +1079,9 @@
     def op_oostring(self, obj, base):
         return ootype.oostring(obj, base)
 
+    def op_oounicode(self, obj, base):
+        return ootype.oounicode(obj, base)
+
     def op_ooparse_int(self, s, base):
         try:
             return ootype.ooparse_int(s, base)

Modified: pypy/branch/pypy-rpython-unicode/rpython/ootypesystem/ooregistry.py
==============================================================================
--- pypy/branch/pypy-rpython-unicode/rpython/ootypesystem/ooregistry.py	(original)
+++ pypy/branch/pypy-rpython-unicode/rpython/ootypesystem/ooregistry.py	Thu Nov  8 20:43:50 2007
@@ -24,6 +24,19 @@
         vlist = hop.inputargs(hop.args_r[0], ootype.Signed)
         return hop.genop('oostring', vlist, resulttype = ootype.String)
 
+class Entry_oounicode(ExtRegistryEntry):
+    _about_ = ootype.oounicode
+
+    def compute_result_annotation(self, obj_s, base_s):
+        assert isinstance(obj_s, annmodel.SomeUnicodeCodePoint)
+        assert isinstance(base_s, annmodel.SomeInteger)
+        return annmodel.SomeOOInstance(ootype.Unicode)
+
+    def specialize_call(self, hop):
+        assert isinstance(hop.args_s[0],annmodel.SomeUnicodeCodePoint)
+        vlist = hop.inputargs(hop.args_r[0], ootype.Signed)
+        return hop.genop('oounicode', vlist, resulttype = ootype.Unicode)
+    
 
 class Entry_ootype_string(ExtRegistryEntry):
     _type_ = ootype._string

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 20:43:50 2007
@@ -1557,6 +1557,17 @@
         obj = '<%s object>' % obj._inst._TYPE._name
     return make_string(str(obj))
 
+def oounicode(obj, base):
+    """
+    Convert an unichar into an unicode string.
+
+    base must be -1, for consistency with oostring.
+    """
+    assert base == -1
+    assert isinstance(obj, unicode)
+    assert len(obj) == 1
+    return make_unicode(obj)
+
 def ooparse_int(s, base):
     return int(s._str, base)
 

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 20:43:50 2007
@@ -1,7 +1,8 @@
+from pypy.tool.pairtype import pairtype
 from pypy.rpython.error import TyperError
 from pypy.rpython.rstr import AbstractStringRepr,AbstractCharRepr,\
      AbstractUniCharRepr, AbstractStringIteratorRepr,\
-     AbstractLLHelpers
+     AbstractLLHelpers, AbstractUnicodeRepr
 from pypy.rpython.rmodel import IntegerRepr
 from pypy.rpython.lltypesystem.lltype import Ptr, Char, UniChar
 from pypy.rpython.ootypesystem import ootype
@@ -45,25 +46,35 @@
     def make_string(self, value):
         return ootype.make_string(value)
 
-class UnicodeRepr(AbstractOOStringRepr):
+class UnicodeRepr(AbstractOOStringRepr, AbstractUnicodeRepr):
     lowleveltype = ootype.Unicode
     basetype = basestring
 
     def make_string(self, value):
         return ootype.make_unicode(value)
 
-
 class CharRepr(AbstractCharRepr, StringRepr):
     lowleveltype = Char
 
-class UniCharRepr(AbstractUniCharRepr):
+class UniCharRepr(AbstractUniCharRepr, UnicodeRepr):
     lowleveltype = UniChar
 
+
+class __extend__(pairtype(UniCharRepr, UnicodeRepr)):
+    def convert_from_to((r_from, r_to), v, llops):
+        rstr = llops.rtyper.type_system.rstr
+        if r_from == unichar_repr and r_to == unicode_repr:
+            return llops.gendirectcall(r_from.ll.ll_unichr2unicode, v)
+        return NotImplemented
+
 class LLHelpers(AbstractLLHelpers):
 
     def ll_chr2str(ch):
         return ootype.oostring(ch, -1)
 
+    def ll_unichr2unicode(ch):
+        return ootype.oounicode(ch, -1)
+
     def ll_strhash(s):
         return ootype.oohash(s)
 


More information about the pypy-svn mailing list