fixes for compile-time slicing
authorStefan Behnel <scoder@users.berlios.de>
Mon, 27 Oct 2008 21:29:57 +0000 (22:29 +0100)
committerStefan Behnel <scoder@users.berlios.de>
Mon, 27 Oct 2008 21:29:57 +0000 (22:29 +0100)
Cython/Compiler/ExprNodes.py
tests/run/ct_DEF.pyx

index 8613c0cfa97e56d90453d39f3a955f77f4dae1fb..c294d2c196a185d9cb259f0894b5ff58cf1e0bb4 100644 (file)
@@ -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:
index 97c80046773613a94f5f96d5345b219d9c8609fa..540f7ebc1021c3ffd06def2068346f8a0fce36fc 100644 (file)
@@ -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