[pypy-svn] r35323 - in pypy/dist/pypy/rpython: . ootypesystem test
arigo at codespeak.net
arigo at codespeak.net
Tue Dec 5 19:19:09 CET 2006
Author: arigo
Date: Tue Dec 5 19:19:07 2006
New Revision: 35323
Modified:
pypy/dist/pypy/rpython/ootypesystem/rstr.py
pypy/dist/pypy/rpython/rmodel.py
pypy/dist/pypy/rpython/rtyper.py
pypy/dist/pypy/rpython/test/test_rlist.py
pypy/dist/pypy/rpython/test/test_rstr.py
Log:
(pedronis, arigo)
Fix %-formatting of lists and tuples, a bit here and there.
Modified: pypy/dist/pypy/rpython/ootypesystem/rstr.py
==============================================================================
--- pypy/dist/pypy/rpython/ootypesystem/rstr.py (original)
+++ pypy/dist/pypy/rpython/ootypesystem/rstr.py Tue Dec 5 19:19:07 2006
@@ -238,9 +238,8 @@
vitem, r_arg = argsiter.next()
if not hasattr(r_arg, 'll_str'):
raise TyperError("ll_str unsupported for: %r" % r_arg)
- if code == 's':
- # TODO: for now it works only with types supported by oostring
- vchunk = hop.genop('oostring', [vitem, cm1], resulttype=ootype.String)
+ if code == 's' or (code == 'r' and isinstance(r_arg, InstanceRepr)):
+ vchunk = hop.gendirectcall(r_arg.ll_str, vitem)
elif code == 'd':
assert isinstance(r_arg, IntegerRepr)
vchunk = hop.genop('oostring', [vitem, c10], resulttype=ootype.String)
@@ -253,8 +252,6 @@
elif code == 'o':
assert isinstance(r_arg, IntegerRepr)
vchunk = hop.genop('oostring', [vitem, c8], resulttype=ootype.String)
- elif code == 'r' and isinstance(r_arg, InstanceRepr):
- vchunk = hop.gendirectcall(r_arg.ll_str, vitem)
else:
raise TyperError, "%%%s is not RPython" % (code, )
else:
Modified: pypy/dist/pypy/rpython/rmodel.py
==============================================================================
--- pypy/dist/pypy/rpython/rmodel.py (original)
+++ pypy/dist/pypy/rpython/rmodel.py Tue Dec 5 19:19:07 2006
@@ -353,6 +353,7 @@
def get_ll_eq_function(self): return None
def get_ll_hash_function(self): return ll_hash_void
get_ll_fasthash_function = get_ll_hash_function
+ def ll_str(self, nothing): raise AssertionError("unreachable code")
impossible_repr = VoidRepr()
class SimplePointerRepr(Repr):
Modified: pypy/dist/pypy/rpython/rtyper.py
==============================================================================
--- pypy/dist/pypy/rpython/rtyper.py (original)
+++ pypy/dist/pypy/rpython/rtyper.py Tue Dec 5 19:19:07 2006
@@ -846,7 +846,7 @@
newargs_v = []
for v in args_v:
if v.concretetype is Void:
- s_value = rtyper.binding(v)
+ s_value = rtyper.binding(v, default=annmodel.s_None)
if not s_value.is_constant():
raise TyperError("non-constant variable of type Void")
if not isinstance(s_value, annmodel.SomePBC):
Modified: pypy/dist/pypy/rpython/test/test_rlist.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_rlist.py (original)
+++ pypy/dist/pypy/rpython/test/test_rlist.py Tue Dec 5 19:19:07 2006
@@ -735,6 +735,12 @@
res = self.interpret(fn, [])
assert self.ll_to_string(res) == fn()
+ def fn():
+ return str([])
+
+ res = self.interpret(fn, [])
+ assert self.ll_to_string(res) == fn()
+
def test_list_or_None(self):
empty_list = []
nonempty_list = [1, 2]
Modified: pypy/dist/pypy/rpython/test/test_rstr.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_rstr.py (original)
+++ pypy/dist/pypy/rpython/test/test_rstr.py Tue Dec 5 19:19:07 2006
@@ -472,6 +472,32 @@
res = res.replace('pypy.rpython.test.test_rstr.', '')
assert res == 'what a nice <D object>, much nicer than <C object>'
+ def test_percentformat_tuple(self):
+ for t, expected in [((), "<<<()>>>"),
+ ((5,), "<<<(5,)>>>"),
+ ((5, 6), "<<<(5, 6)>>>"),
+ ((5, 6, 7), "<<<(5, 6, 7)>>>")]:
+ def getter():
+ return t
+ def dummy():
+ return "<<<%s>>>" % (getter(),)
+
+ res = self.ll_to_string(self.interpret(dummy, []))
+ assert res == expected
+
+ def test_percentformat_list(self):
+ for t, expected in [([], "<<<[]>>>"),
+ ([5], "<<<[5]>>>"),
+ ([5, 6], "<<<[5, 6]>>>"),
+ ([5, 6, 7], "<<<[5, 6, 7]>>>")]:
+ def getter():
+ return t
+ def dummy():
+ return "<<<%s>>>" % (getter(),)
+
+ res = self.ll_to_string(self.interpret(dummy, []))
+ assert res == expected
+
def test_split(self):
def fn(i):
s = ['', '0.1.2.4.8', '.1.2', '1.2.', '.1.2.4.'][i]
More information about the pypy-svn
mailing list