From: Stefan Behnel Date: Mon, 27 Oct 2008 21:29:57 +0000 (+0100) Subject: fixes for compile-time slicing X-Git-Tag: 0.9.9.2.beta~8 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=b08908187c953dd4d84c0902e7ee726b17df512f;p=cython.git fixes for compile-time slicing --- diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py index 8613c0cf..c294d2c1 100644 --- a/Cython/Compiler/ExprNodes.py +++ b/Cython/Compiler/ExprNodes.py @@ -1754,8 +1754,14 @@ class SliceIndexNode(ExprNode): def compile_time_value(self, denv): base = self.base.compile_time_value(denv) - start = self.start.compile_time_value(denv) - stop = self.stop.compile_time_value(denv) + if self.start is None: + start = 0 + else: + start = self.start.compile_time_value(denv) + if self.stop is None: + stop = None + else: + stop = self.stop.compile_time_value(denv) try: return base[start:stop] except Exception, e: @@ -1837,8 +1843,14 @@ class SliceNode(ExprNode): def compile_time_value(self, denv): start = self.start.compile_time_value(denv) - stop = self.stop.compile_time_value(denv) - step = step.step.compile_time_value(denv) + if self.stop is None: + stop = None + else: + stop = self.stop.compile_time_value(denv) + if self.step is None: + step = None + else: + step = self.step.compile_time_value(denv) try: return slice(start, stop, step) except Exception, e: diff --git a/tests/run/ct_DEF.pyx b/tests/run/ct_DEF.pyx index 97c80046..540f7ebc 100644 --- a/tests/run/ct_DEF.pyx +++ b/tests/run/ct_DEF.pyx @@ -51,6 +51,8 @@ DEF TWO = TUPLE[1] DEF FIVE = TWO + 3 DEF TRUE = TRUE_FALSE[0] DEF FALSE = TRUE_FALSE[1] +DEF INT_TUPLE1 = TUPLE[:2] +DEF INT_TUPLE2 = TUPLE[1:4:2] def c(): cdef char c @@ -108,6 +110,12 @@ def two(): two = TWO return two +# this doesn't currently work! +#def two2(): +# cdef int two +# two = INT_TUPLE1[-1] +# return two + def five(): cdef int five five = FIVE