[pypy-svn] r31344 - in pypy/dist/pypy: annotation rpython
arigo at codespeak.net
arigo at codespeak.net
Wed Aug 16 13:59:28 CEST 2006
Author: arigo
Date: Wed Aug 16 13:59:25 2006
New Revision: 31344
Modified:
pypy/dist/pypy/annotation/binaryop.py
pypy/dist/pypy/annotation/model.py
pypy/dist/pypy/rpython/rtuple.py
Log:
Oups! I broke translation again with this tuple slicing
(more precisely, list slicing was broken).
Modified: pypy/dist/pypy/annotation/binaryop.py
==============================================================================
--- pypy/dist/pypy/annotation/binaryop.py (original)
+++ pypy/dist/pypy/annotation/binaryop.py Wed Aug 16 13:59:25 2006
@@ -459,10 +459,8 @@
class __extend__(pairtype(SomeTuple, SomeSlice)):
def getitem((tup, slic)):
- if not slic.is_immutable_constant():
- raise Exception("not supported: "
- "tuple slicing with non-constant indexes")
- return SomeTuple(tup.items[slic.const])
+ start, stop, step = slic.constant_indices()
+ return SomeTuple(tup.items[start:stop:step])
getitem.can_only_throw = []
Modified: pypy/dist/pypy/annotation/model.py
==============================================================================
--- pypy/dist/pypy/annotation/model.py (original)
+++ pypy/dist/pypy/annotation/model.py Wed Aug 16 13:59:25 2006
@@ -231,10 +231,14 @@
self.start = start
self.stop = stop
self.step = step
- if (start.is_immutable_constant() and
- stop .is_immutable_constant() and
- step .is_immutable_constant()):
- self.const = slice(start.const, stop.const, step.const)
+
+ def constant_indices(self):
+ if (self.start.is_immutable_constant() and
+ self.stop .is_immutable_constant() and
+ self.step .is_immutable_constant()):
+ return self.start.const, self.stop.const, self.step.const
+ else:
+ raise Exception("need constant indices for this slice")
def can_be_none(self):
return False
Modified: pypy/dist/pypy/rpython/rtuple.py
==============================================================================
--- pypy/dist/pypy/rpython/rtuple.py (original)
+++ pypy/dist/pypy/rpython/rtuple.py Wed Aug 16 13:59:25 2006
@@ -157,12 +157,10 @@
class __extend__(pairtype(AbstractTupleRepr, AbstractSliceRepr)):
def rtype_getitem((r_tup, r_slice), hop):
- s_slice = hop.args_s[1]
- if not s_slice.is_immutable_constant():
- raise TyperError("non-constant tuple slicing index")
v_tup = hop.inputarg(r_tup, arg=0)
-
- indices = range(len(r_tup.items_r))[s_slice.const]
+ s_slice = hop.args_s[1]
+ start, stop, step = s_slice.constant_indices()
+ indices = range(len(r_tup.items_r))[start:stop:step]
assert len(indices) == len(hop.r_result.items_r)
items_v = [r_tup.getitem_internal(hop.llops, v_tup, i)
More information about the Pypy-commit
mailing list