From: Stefan Behnel Date: Thu, 18 Dec 2008 09:20:09 +0000 (+0100) Subject: cleanup, keep for-range optimisation more local X-Git-Tag: 0.11-beta~117 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=d5f88aac790f53afafa4c4d644c05c0b1a6a2243;p=cython.git cleanup, keep for-range optimisation more local --- diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py index eda47c8c..8500e843 100644 --- a/Cython/Compiler/Nodes.py +++ b/Cython/Compiler/Nodes.py @@ -3870,13 +3870,6 @@ class ForFromStatNode(LoopNode, StatNode): self.bound2.release_temp(env) if self.step is not None: self.step.release_temp(env) - - def reanalyse_c_loop(self, env): - # only make sure all subnodes have an integer type - self.bound1 = self.bound1.coerce_to_integer(env) - self.bound2 = self.bound2.coerce_to_integer(env) - if self.step is not None: - self.step = self.step.coerce_to_integer(env) def generate_execution_code(self, code): old_loop_labels = code.new_loop_labels() diff --git a/Cython/Compiler/Optimize.py b/Cython/Compiler/Optimize.py index d2a442ef..c7362997 100644 --- a/Cython/Compiler/Optimize.py +++ b/Cython/Compiler/Optimize.py @@ -115,33 +115,31 @@ class IterationTransform(Visitor.VisitorTransform): else: step = args[2] step_pos = step.pos - if step.constant_result is ExprNodes.not_a_constant: + if not isinstance(step.constant_result, (int, long)): # cannot determine step direction return node - try: - # FIXME: check how Python handles rounding here, e.g. from float - step_value = int(step.constant_result) - except: + step_value = step.constant_result + if step_value == 0: + # will lead to an error elsewhere return node if not isinstance(step, ExprNodes.IntNode): step = ExprNodes.IntNode(step_pos, value=step_value) - if step_value > 0: - relation1 = '<=' - relation2 = '<' - elif step_value < 0: + if step_value < 0: step.value = -step_value relation1 = '>=' relation2 = '>' else: - return node + relation1 = '<=' + relation2 = '<' if len(args) == 1: bound1 = ExprNodes.IntNode(range_function.pos, value=0) - bound2 = args[0] + bound2 = args[0].coerce_to_integer(self.current_scope) else: - bound1 = args[0] - bound2 = args[1] + bound1 = args[0].coerce_to_integer(self.current_scope) + bound2 = args[1].coerce_to_integer(self.current_scope) + step = step.coerce_to_integer(self.current_scope) for_node = Nodes.ForFromStatNode( node.pos, @@ -151,8 +149,6 @@ class IterationTransform(Visitor.VisitorTransform): step=step, body=node.body, else_clause=node.else_clause, loopvar_name = node.target.entry.cname) - for_node.reanalyse_c_loop(self.current_scope) -# for_node.analyse_expressions(self.current_scope) return for_node def _transform_dict_iteration(self, node, dict_obj, keys, values):