Commit 6ca2b4a9 authored by Stefan Behnel's avatar Stefan Behnel

simplify some code, add some comments

parent 5297e74b
...@@ -632,8 +632,7 @@ class IterationTransform(Visitor.EnvTransform): ...@@ -632,8 +632,7 @@ class IterationTransform(Visitor.EnvTransform):
if len(args) < 3: if len(args) < 3:
step_pos = range_function.pos step_pos = range_function.pos
step_value = 1 step_value = 1
step = ExprNodes.IntNode(step_pos, value='1', step = ExprNodes.IntNode(step_pos, value='1', constant_result=1)
constant_result=1)
else: else:
step = args[2] step = args[2]
step_pos = step.pos step_pos = step.pos
...@@ -664,6 +663,7 @@ class IterationTransform(Visitor.EnvTransform): ...@@ -664,6 +663,7 @@ class IterationTransform(Visitor.EnvTransform):
if abs_step != 1: if abs_step != 1:
if (isinstance(bound1.constant_result, (int, long)) and if (isinstance(bound1.constant_result, (int, long)) and
isinstance(bound2.constant_result, (int, long))): isinstance(bound2.constant_result, (int, long))):
# calculate final bounds now
if step_value < 0: if step_value < 0:
begin_value = bound2.constant_result begin_value = bound2.constant_result
end_value = bound1.constant_result end_value = bound1.constant_result
...@@ -677,6 +677,7 @@ class IterationTransform(Visitor.EnvTransform): ...@@ -677,6 +677,7 @@ class IterationTransform(Visitor.EnvTransform):
bound1.pos, value=str(bound1_value), constant_result=bound1_value, bound1.pos, value=str(bound1_value), constant_result=bound1_value,
type=PyrexTypes.spanning_type(bound1.type, bound2.type)) type=PyrexTypes.spanning_type(bound1.type, bound2.type))
else: else:
# evaluate the same expression as above at runtime
bound2_ref_node = UtilNodes.LetRefNode(bound2) bound2_ref_node = UtilNodes.LetRefNode(bound2)
spanning_type = PyrexTypes.spanning_type(bound1.type, bound2.type) spanning_type = PyrexTypes.spanning_type(bound1.type, bound2.type)
spanning_step_type = PyrexTypes.spanning_type(spanning_type, step.type) spanning_step_type = PyrexTypes.spanning_type(spanning_type, step.type)
...@@ -685,19 +686,17 @@ class IterationTransform(Visitor.EnvTransform): ...@@ -685,19 +686,17 @@ class IterationTransform(Visitor.EnvTransform):
begin_value = bound2_ref_node begin_value = bound2_ref_node
end_value = bound1 end_value = bound1
final_op = '-' final_op = '-'
final_node = ExprNodes.SubNode
else: else:
begin_value = bound1 begin_value = bound1
end_value = bound2_ref_node end_value = bound2_ref_node
final_op = '+' final_op = '+'
final_node = ExprNodes.AddNode
bound1 = final_node( bound1 = ExprNodes.binop_node(
bound1.pos, bound1.pos,
operand1=final_node( operand1=ExprNodes.binop_node(
bound1.pos, bound1.pos,
operand1=bound2_ref_node, operand1=bound2_ref_node,
operator=final_op, operator=final_op, # +/-
operand2=ExprNodes.MulNode( operand2=ExprNodes.MulNode(
bound1.pos, bound1.pos,
operand1=ExprNodes.IntNode( operand1=ExprNodes.IntNode(
...@@ -731,7 +730,7 @@ class IterationTransform(Visitor.EnvTransform): ...@@ -731,7 +730,7 @@ class IterationTransform(Visitor.EnvTransform):
type=spanning_step_type), type=spanning_step_type),
type=spanning_step_type), type=spanning_step_type),
type=spanning_step_type), type=spanning_step_type),
operator=final_op, operator=final_op, # +/-
operand2=ExprNodes.IntNode( operand2=ExprNodes.IntNode(
bound1.pos, bound1.pos,
value='1', value='1',
...@@ -747,10 +746,7 @@ class IterationTransform(Visitor.EnvTransform): ...@@ -747,10 +746,7 @@ class IterationTransform(Visitor.EnvTransform):
if not bound2.is_literal: if not bound2.is_literal:
# stop bound must be immutable => keep it in a temp var # stop bound must be immutable => keep it in a temp var
bound2_is_temp = True bound2_is_temp = True
if bound2_ref_node: bound2 = bound2_ref_node or UtilNodes.LetRefNode(bound2)
bound2 = bound2_ref_node
else:
bound2 = UtilNodes.LetRefNode(bound2)
else: else:
bound2_is_temp = False bound2_is_temp = False
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment