[pypy-svn] r48388 - in pypy/branch/pypy-rpython-unicode: annotation rpython/test
fijal at codespeak.net
fijal at codespeak.net
Thu Nov 8 01:55:44 CET 2007
Author: fijal
Date: Thu Nov 8 01:55:43 2007
New Revision: 48388
Modified:
pypy/branch/pypy-rpython-unicode/annotation/binaryop.py
pypy/branch/pypy-rpython-unicode/annotation/unaryop.py
pypy/branch/pypy-rpython-unicode/rpython/test/test_rstr.py
pypy/branch/pypy-rpython-unicode/rpython/test/test_runicode.py
Log:
All string tests, which are decided to be supported by now, passes
with unicode (for lltypesystem). There are few todos:
* fix the if typeOf(...) evil hacks
* think about unicode mod sth
* think about str(some_unicode)
Modified: pypy/branch/pypy-rpython-unicode/annotation/binaryop.py
==============================================================================
--- pypy/branch/pypy-rpython-unicode/annotation/binaryop.py (original)
+++ pypy/branch/pypy-rpython-unicode/annotation/binaryop.py Thu Nov 8 01:55:43 2007
@@ -615,10 +615,11 @@
lst1.listdef.resize()
delitem.can_only_throw = []
-class __extend__(pairtype(SomeString, SomeSlice)):
+class __extend__(pairtype(SomeString, SomeSlice),
+ pairtype(SomeUnicodeString, SomeSlice)):
def getitem((str1, slic)):
- return SomeString()
+ return str1.basestringclass()
getitem.can_only_throw = []
class __extend__(pairtype(SomeString, SomeInteger)):
@@ -660,11 +661,12 @@
getbookkeeper().count("str_mul", str1, int2)
return SomeUnicodeString()
-class __extend__(pairtype(SomeInteger, SomeString)):
+class __extend__(pairtype(SomeInteger, SomeString),
+ pairtype(SomeInteger, SomeUnicodeString)):
def mul((int1, str2)): # xxx do we want to support this
getbookkeeper().count("str_mul", str2, int1)
- return SomeString()
+ return str2.basestringclass()
class __extend__(pairtype(SomeUnicodeCodePoint, SomeUnicodeString),
pairtype(SomeUnicodeString, SomeUnicodeCodePoint),
Modified: pypy/branch/pypy-rpython-unicode/annotation/unaryop.py
==============================================================================
--- pypy/branch/pypy-rpython-unicode/annotation/unaryop.py (original)
+++ pypy/branch/pypy-rpython-unicode/annotation/unaryop.py Thu Nov 8 01:55:43 2007
@@ -429,18 +429,20 @@
return SomeInteger(nonneg=True)
def method_strip(str, chr):
- return SomeString()
+ return str.basestringclass()
def method_lstrip(str, chr):
- return SomeString()
+ return str.basestringclass()
def method_rstrip(str, chr):
- return SomeString()
+ return str.basestringclass()
def method_join(str, s_list):
getbookkeeper().count("str_join", str)
s_item = s_list.listdef.read_item()
if isinstance(s_item, SomeImpossibleValue):
+ if isinstance(str, SomeUnicodeString):
+ return immutablevalue(u"")
return immutablevalue("")
return str.basestringclass()
@@ -464,11 +466,12 @@
def method_replace(str, s1, s2):
return str.basestringclass()
- def method_lower(str):
- return str.basestringclass()
-
+class __extend__(SomeString):
def method_upper(str):
- return str.basestringclass()
+ return SomeString()
+
+ def method_lower(str):
+ return SomeString()
class __extend__(SomeChar):
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 Thu Nov 8 01:55:43 2007
@@ -666,34 +666,38 @@
assert res == expected
def test_char_mul_n(self):
+ const = self.const
def f(c, n):
return c*n
- res = self.interpret(f, ['a', 4])
+ res = self.interpret(f, [const('a'), 4])
assert self.ll_to_string(res) == 'a'*4
- res = self.interpret(f, ['a', 0])
+ res = self.interpret(f, [const('a'), 0])
assert self.ll_to_string(res) == ""
def test_char_mul_negative(self):
+ const = self.const
def f(c):
return c * -3
- res = self.interpret(f, ['a'])
+ res = self.interpret(f, [const('a')])
assert self.ll_to_string(res) == ''
def test_n_mul_char(self):
+ const = self.const
def f(c, n):
return n*c
- res = self.interpret(f, ['a', 4])
+ res = self.interpret(f, [const('a'), 4])
assert self.ll_to_string(res) == 'a'*4
- res = self.interpret(f, ['a', 0])
+ res = self.interpret(f, [const('a'), 0])
assert self.ll_to_string(res) == ""
def test_hash(self):
+ const = self.const
def fn(i):
if i == 0:
- s = ''
+ s = const('')
else:
- s = "xxx"
+ s = const("xxx")
return hash(s)
res = self.interpret(fn, [0])
assert res == self.EMPTY_STRING_HASH
@@ -701,45 +705,52 @@
assert typeOf(res) == Signed
def test_call_str_on_string(self):
+ const = self.const
def fn(i):
- s = "x" * i
- return str(s)
+ s = const("x") * i
+ return const(s)
res = self.interpret(fn, [3])
assert self.ll_to_string(res) == 'xxx'
def test_count_char(self):
+ const = self.const
def fn(i):
- s = "".join(["abcasd"] * i)
- return s.count("a") + s.count("a", 2) + s.count("b", 1, 6)
+ s = const("").join([const("abcasd")] * i)
+ return s.count(const("a")) + s.count(const("a"), 2) + \
+ s.count(const("b"), 1, 6)
res = self.interpret(fn, [4])
assert res == 8 + 7 + 1
def test_count(self):
+ const = self.const
def fn(i):
- s = "".join(["abcabsd"] * i)
+ s = const("").join([const("abcabsd")] * i)
one = i / i # confuse the annotator
- return (s.count("abc") + "abcde".count("") +
- "abcda".count("a" * one))
+ return (s.count(const("abc")) + const("abcde").count(const("")) +
+ const("abcda").count(const("a") * one))
res = self.interpret(fn, [4])
assert res == 4 + 6 + 2
def test_count_overlapping_occurences(self):
+ const = self.const
def fn():
- return 'ababa'.count('aba')
+ return const('ababa').count(const('aba'))
res = self.interpret(fn, [])
assert res == 1
def test_hlstr(self):
+ const = self.const
from pypy.rpython.annlowlevel import hlstr
def f(s):
- return "*"+hlstr(s)+"*" == "*abba*"
+ return const("*")+const(hlstr(s))+const("*") == const("*abba*")
- res = self.interpret(f, [self.string_to_ll("abba")])
+ res = self.interpret(f, [self.string_to_ll(const("abba"))])
assert res
def test_getitem_exc(self):
+ const = self.const
def f(x):
- s = "z"
+ s = const("z")
return s[x]
res = self.interpret(f, [0])
@@ -752,13 +763,13 @@
assert False
def f(x):
- s = "z"
+ s = const("z")
try:
return s[x]
except IndexError:
- return 'X'
+ return const('X')
except Exception:
- return ' '
+ return const(' ')
res = self.interpret(f, [0])
assert res == 'z'
@@ -766,11 +777,11 @@
assert res == 'X'
def f(x):
- s = "z"
+ s = const("z")
try:
return s[x]
except Exception:
- return ' '
+ return const(' ')
res = self.interpret(f, [0])
assert res == 'z'
@@ -778,11 +789,11 @@
assert res == ' '
def f(x):
- s = "z"
+ s = const("z")
try:
return s[x]
except ValueError:
- return ' '
+ return const(' ')
res = self.interpret(f, [0])
assert res == 'z'
@@ -794,10 +805,11 @@
assert False
def test_fold_concat(self):
+ const = self.const
def g(tail):
- return "head"+tail
+ return const("head")+tail
def f():
- return g("tail")
+ return g(const("tail"))
from pypy import conftest
t, typer, fgraph = self.gengraph(f, [], backendopt=True)
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 Thu Nov 8 01:55:43 2007
@@ -55,6 +55,7 @@
test_int = unsupported
test_int_valueerror = unsupported
test_float = unsupported
+ test_hlstr = unsupported
class TestLLtype(BaseTestRUnicode, LLRtypeMixin):
EMPTY_STRING_HASH = -1
More information about the Pypy-commit
mailing list