[pypy-svn] r48360 - in pypy/branch/pypy-rpython-unicode/rpython: . lltypesystem test
fijal at codespeak.net
fijal at codespeak.net
Wed Nov 7 14:48:26 CET 2007
Author: fijal
Date: Wed Nov 7 14:48:26 2007
New Revision: 48360
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:
Iteration over unicode strings works.
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 14:48:26 2007
@@ -56,7 +56,7 @@
return p
def make_iterator_repr(self):
- return string_iterator_repr
+ return self.iterator_repr
def can_ll_be_null(self, s_value):
# XXX unicode
@@ -803,18 +803,32 @@
StringRepr.repr = string_repr
UnicodeRepr.repr = unicode_repr
-class StringIteratorRepr(AbstractStringIteratorRepr):
+class BaseStringIteratorRepr(AbstractStringIteratorRepr):
+ def __init__(self):
+ self.ll_striter = ll_striter
+ self.ll_strnext = ll_strnext
+
+class StringIteratorRepr(BaseStringIteratorRepr):
+
lowleveltype = Ptr(GcStruct('stringiter',
('string', string_repr.lowleveltype),
('index', Signed)))
- def __init__(self):
- self.ll_striter = ll_striter
- self.ll_strnext = ll_strnext
+class UnicodeIteratorRepr(BaseStringIteratorRepr):
+
+ lowleveltype = Ptr(GcStruct('unicodeiter',
+ ('string', unicode_repr.lowleveltype),
+ ('index', Signed)))
def ll_striter(string):
- iter = malloc(string_iterator_repr.lowleveltype.TO)
+ if typeOf(string) == string_repr.lowleveltype:
+ TP = string_repr.iterator_repr.lowleveltype.TO
+ elif typeOf(string) == unicode_repr.lowleveltype:
+ TP = unicode_repr.iterator_repr.lowleveltype.TO
+ else:
+ raise TypeError("Unknown string type %s" % (typeOf(string),))
+ iter = malloc(TP)
iter.string = string
iter.index = 0
return iter
@@ -827,8 +841,8 @@
iter.index = index + 1
return chars[index]
-string_iterator_repr = StringIteratorRepr()
-
+string_repr.iterator_repr = StringIteratorRepr()
+unicode_repr.iterator_repr = UnicodeIteratorRepr()
# these should be in rclass, but circular imports prevent (also it's
# not that insane that a string constant is built in this file).
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 14:48:26 2007
@@ -523,7 +523,7 @@
class AbstractStringIteratorRepr(IteratorRepr):
def newiter(self, hop):
- string_repr = hop.rtyper.type_system.rstr.string_repr
+ string_repr = hop.args_r[0].repr
v_str, = hop.inputargs(string_repr)
return hop.gendirectcall(self.ll_striter, v_str)
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 14:48:26 2007
@@ -73,8 +73,9 @@
assert self.ll_to_string(res) == fn(i, j)
def test_iter(self):
+ const = self.const
def fn(i):
- s = ['', 'a', 'hello'][i]
+ s = [const(''), const('a'), const('hello')][i]
i = 0
for c in s:
if c != s[i]:
More information about the Pypy-commit
mailing list