[pypy-svn] r48367 - in pypy/branch/pypy-rpython-unicode/rpython: . lltypesystem module test
fijal at codespeak.net
fijal at codespeak.net
Wed Nov 7 18:00:45 CET 2007
Author: fijal
Date: Wed Nov 7 18:00:44 2007
New Revision: 48367
Modified:
pypy/branch/pypy-rpython-unicode/rpython/lltypesystem/rstr.py
pypy/branch/pypy-rpython-unicode/rpython/module/support.py
pypy/branch/pypy-rpython-unicode/rpython/rstr.py
pypy/branch/pypy-rpython-unicode/rpython/test/test_runicode.py
pypy/branch/pypy-rpython-unicode/rpython/test/tool.py
Log:
Whack, whack.. another tests are passing
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 18:00:44 2007
@@ -197,6 +197,13 @@
s.chars[0] = ch
return s
+ def ll_str2unicode(str):
+ lgt = len(str.chars)
+ s = mallocunicode(lgt)
+ for i in range(lgt):
+ s.chars[i] = cast_primitive(UniChar, str.chars[i])
+ return s
+
def ll_strhash(s):
# unlike CPython, there is no reason to avoid to return -1
# but our malloc initializes the memory to zero, so we use zero as the
Modified: pypy/branch/pypy-rpython-unicode/rpython/module/support.py
==============================================================================
--- pypy/branch/pypy-rpython-unicode/rpython/module/support.py (original)
+++ pypy/branch/pypy-rpython-unicode/rpython/module/support.py Wed Nov 7 18:00:44 2007
@@ -29,6 +29,16 @@
return p
to_rstr = staticmethod(to_rstr)
+ def to_runicode(s):
+ from pypy.rpython.lltypesystem.rstr import UNICODE, mallocunicode
+ if s is None:
+ return lltype.nullptr(UNICODE)
+ p = mallocunicode(len(s))
+ for i in range(len(s)):
+ p.chars[i] = s[i]
+ return p
+ to_runicode = staticmethod(to_runicode)
+
def from_rstr(rs):
if not rs: # null pointer
return None
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 18:00:44 2007
@@ -82,7 +82,11 @@
v_str, = hop.inputargs(string_repr)
c_zero = inputconst(Signed, 0)
v_chr = hop.gendirectcall(self.ll.ll_stritem_nonneg, v_str, c_zero)
- return hop.genop('cast_char_to_int', [v_chr], resulttype=Signed)
+ if string_repr is hop.rtyper.type_system.rstr.string_repr:
+ return hop.genop('cast_char_to_int', [v_chr], resulttype=Signed)
+ else:
+ assert string_repr is hop.rtyper.type_system.rstr.unicode_repr
+ return hop.genop('cast_unichar_to_int', [v_chr], resulttype=Signed)
def rtype_method_startswith(self, hop):
str1_repr, str2_repr = self._str_reprs(hop)
@@ -238,6 +242,12 @@
hop.exception_is_here()
return hop.gendirectcall(self.ll.ll_int, v_str, v_base)
+ def rtype_unicode(self, hop):
+ repr = hop.args_r[0].repr
+ v_str = hop.inputarg(repr, 0)
+ hop.exception_cannot_occur()
+ return hop.gendirectcall(self.ll.ll_str2unicode, v_str)
+
def rtype_float(self, hop):
hop.has_implicit_exception(ValueError) # record that we know about it
string_repr = hop.rtyper.type_system.rstr.string_repr
@@ -414,18 +424,21 @@
def rtype_method_islower(self, hop):
return self._rtype_method_isxxx(self.ll.ll_char_islower, hop)
-class __extend__(pairtype(AbstractCharRepr, IntegerRepr)):
+class __extend__(pairtype(AbstractCharRepr, IntegerRepr),
+ pairtype(AbstractUniCharRepr, IntegerRepr)):
def rtype_mul((r_chr, r_int), hop):
+ char_repr = r_chr.char_repr
rstr = hop.rtyper.type_system.rstr
- v_char, v_int = hop.inputargs(rstr.char_repr, Signed)
+ v_char, v_int = hop.inputargs(char_repr, Signed)
return hop.gendirectcall(r_chr.ll.ll_char_mul, v_char, v_int)
rtype_inplace_mul = rtype_mul
-class __extend__(pairtype(IntegerRepr, AbstractCharRepr)):
+class __extend__(pairtype(IntegerRepr, AbstractCharRepr),
+ pairtype(IntegerRepr, AbstractUniCharRepr)):
def rtype_mul((r_int, r_chr), hop):
- rstr = hop.rtyper.type_system.rstr
- v_int, v_char = hop.inputargs(Signed, rstr.char_repr)
+ char_repr = r_chr.char_repr
+ v_int, v_char = hop.inputargs(Signed, char_repr)
return hop.gendirectcall(r_chr.ll.ll_char_mul, v_char, v_int)
rtype_inplace_mul = rtype_mul
Modified: pypy/branch/pypy-rpython-unicode/rpython/test/test_runicode.py
==============================================================================
--- pypy/branch/pypy-rpython-unicode/rpython/test/test_runicode.py (original)
+++ pypy/branch/pypy-rpython-unicode/rpython/test/test_runicode.py Wed Nov 7 18:00:44 2007
@@ -10,11 +10,38 @@
const = unicode
constchar = unichr
+ def test_unicode_explicit_conv(self):
+ def f(x):
+ return unicode(x)
+
+ for v in ['x', u'x']:
+ res = self.interpret(f, [v])
+ assert self.ll_to_unicode(res) == v
+
+ def f(x):
+ if x > 1:
+ y = const('yxx')
+ else:
+ y = const('xx')
+ return unicode(y)
+
+ const = str
+ assert self.ll_to_unicode(self.interpret(f, [1])) == f(1)
+
+ def f(x):
+ if x > 1:
+ y = const('yxx')
+ else:
+ y = const('xx')
+ return unicode(y)
+
+ # a copy, because llinterp caches functions
+
+ const = unicode
+ assert self.ll_to_unicode(self.interpret(f, [1])) == f(1)
+
def test_char_isxxx(self):
py.test.skip("not supported")
- def test_char_mul(self):
- py.test.skip("not supported by now")
-
class TestLLtype(BaseTestRUnicode, LLRtypeMixin):
pass
Modified: pypy/branch/pypy-rpython-unicode/rpython/test/tool.py
==============================================================================
--- pypy/branch/pypy-rpython-unicode/rpython/test/tool.py (original)
+++ pypy/branch/pypy-rpython-unicode/rpython/test/tool.py Wed Nov 7 18:00:44 2007
@@ -34,10 +34,17 @@
def ll_to_string(self, s):
return ''.join(s.chars)
+ def ll_to_unicode(self, s):
+ return u''.join(s.chars)
+
def string_to_ll(self, s):
from pypy.rpython.module.support import LLSupport
return LLSupport.to_rstr(s)
+ def unicode_to_ll(self, s):
+ from pypy.rpython.module.support import LLSupport
+ return LLSupport.to_runicode(s)
+
def ll_to_list(self, l):
r = []
items = l.ll_items()
More information about the Pypy-commit
mailing list