[pypy-svn] r36328 - in pypy/dist/pypy/rpython: . ootypesystem test
arigo at codespeak.net
arigo at codespeak.net
Tue Jan 9 11:55:18 CET 2007
Author: arigo
Date: Tue Jan 9 11:55:14 2007
New Revision: 36328
Modified:
pypy/dist/pypy/rpython/ootypesystem/ootype.py
pypy/dist/pypy/rpython/rlist.py
pypy/dist/pypy/rpython/rrange.py
pypy/dist/pypy/rpython/test/test_rrange.py
Log:
(mwh, arigo)
Make empty range()es rtype correctly.
Modified: pypy/dist/pypy/rpython/ootypesystem/ootype.py
==============================================================================
--- pypy/dist/pypy/rpython/ootypesystem/ootype.py (original)
+++ pypy/dist/pypy/rpython/ootypesystem/ootype.py Tue Jan 9 11:55:14 2007
@@ -379,6 +379,10 @@
# 'ITEMTYPE_T' is used as a placeholder for indicating
# arguments that should have ITEMTYPE type. 'SELFTYPE_T' indicates 'self'
+ # XXX clean-up later! Rename _ITEMTYPE to ITEM. For now they are
+ # just synonyms, please use ITEM in new code.
+ self.ITEM = self._ITEMTYPE
+
generic_types = {
self.SELFTYPE_T: self,
self.ITEMTYPE_T: self._ITEMTYPE,
@@ -463,6 +467,11 @@
return self._KEYTYPE is not None and self._VALUETYPE is not None
def _init_methods(self):
+ # XXX clean-up later! Rename _KEYTYPE and _VALUETYPE to KEY and VALUE.
+ # For now they are just synonyms, please use KEY/VALUE in new code.
+ self.KEY = self._KEYTYPE
+ self.VALUE = self._VALUETYPE
+
self._generic_types = frozendict({
self.SELFTYPE_T: self,
self.KEYTYPE_T: self._KEYTYPE,
Modified: pypy/dist/pypy/rpython/rlist.py
==============================================================================
--- pypy/dist/pypy/rpython/rlist.py (original)
+++ pypy/dist/pypy/rpython/rlist.py Tue Jan 9 11:55:14 2007
@@ -31,7 +31,8 @@
def rtyper_makerepr(self, rtyper):
listitem = self.listdef.listitem
s_value = listitem.s_value
- if listitem.range_step is not None and not listitem.mutated:
+ if (listitem.range_step is not None and not listitem.mutated and
+ not isinstance(s_value, annmodel.SomeImpossibleValue)):
return rtyper.type_system.rrange.RangeRepr(listitem.range_step)
elif (s_value.__class__ is annmodel.SomeObject and s_value.knowntype == object):
return robject.pyobj_repr
Modified: pypy/dist/pypy/rpython/rrange.py
==============================================================================
--- pypy/dist/pypy/rpython/rrange.py (original)
+++ pypy/dist/pypy/rpython/rrange.py Tue Jan 9 11:55:14 2007
@@ -118,11 +118,12 @@
raise ValueError
length = _ll_rangelen(start, stop, step)
l = LIST.ll_newlist(length)
- idx = 0
- while idx < length:
- l.ll_setitem_fast(idx, start)
- start += step
- idx += 1
+ if LIST.ITEM is not Void:
+ idx = 0
+ while idx < length:
+ l.ll_setitem_fast(idx, start)
+ start += step
+ idx += 1
return l
# ____________________________________________________________
Modified: pypy/dist/pypy/rpython/test/test_rrange.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_rrange.py (original)
+++ pypy/dist/pypy/rpython/test/test_rrange.py Tue Jan 9 11:55:14 2007
@@ -124,6 +124,17 @@
res = self.interpret(fn, args)
assert res == intmask(fn(*args))
+ def test_empty_range(self):
+ def g(lst):
+ total = 0
+ for i in range(len(lst)):
+ total += lst[i]
+ return total
+ def fn():
+ return g([])
+ res = self.interpret(fn, [])
+ assert res == 0
+
class TestLLtype(BaseTestRrange, LLRtypeMixin):
from pypy.rpython.lltypesystem import rrange
More information about the Pypy-commit
mailing list