cython-devel
changeset 1470:49a8357fc01e
fixed FlattenInListTransform by providing a temp block expression that injects the temp result into a subexpression
| author | Stefan Behnel <scoder@users.berlios.de> |
|---|---|
| date | Sun Dec 07 21:14:13 2008 +0100 (3 years ago) |
| parents | 67cfcfc0e4c5 |
| children | 5c0b99aebb9b |
| files | Cython/Compiler/Main.py Cython/Compiler/Optimize.py Cython/Compiler/UtilNodes.py |
line diff
1.1 --- a/Cython/Compiler/Main.py Sun Dec 07 21:12:58 2008 +0100
1.2 +++ b/Cython/Compiler/Main.py Sun Dec 07 21:14:13 2008 +0100
1.3 @@ -114,7 +114,7 @@
1.4 _specific_post_parse,
1.5 InterpretCompilerDirectives(self, self.pragma_overrides),
1.6 _align_function_definitions,
1.7 -# FlattenInListTransform(),
1.8 + FlattenInListTransform(),
1.9 WithTransform(self),
1.10 DecoratorTransform(self),
1.11 AnalyseDeclarationsTransform(self),
2.1 --- a/Cython/Compiler/Optimize.py Sun Dec 07 21:12:58 2008 +0100
2.2 +++ b/Cython/Compiler/Optimize.py Sun Dec 07 21:14:13 2008 +0100
2.3 @@ -321,11 +321,7 @@
2.4 if len(args) == 0:
2.5 return ExprNodes.BoolNode(pos = node.pos, value = node.operator == 'not_in')
2.6
2.7 - if True or node.operand1.is_simple():
2.8 - lhs = node.operand1
2.9 - else:
2.10 - # FIXME: allocate temp for evaluated node.operand1
2.11 - return node
2.12 + lhs = UtilNodes.ResultRefNode(node.operand1)
2.13
2.14 conds = []
2.15 for arg in args:
2.16 @@ -339,8 +335,6 @@
2.17 pos = node.pos,
2.18 operand = cond,
2.19 type = PyrexTypes.c_bint_type))
2.20 - if type(lhs) is not ExprNodes.CloneNode:
2.21 - lhs = ExprNodes.CloneNode(lhs)
2.22 def concat(left, right):
2.23 return ExprNodes.BoolBinopNode(
2.24 pos = node.pos,
2.25 @@ -348,8 +342,9 @@
2.26 operand1 = left,
2.27 operand2 = right)
2.28
2.29 - return reduce(concat, conds)
2.30 -
2.31 + condition = reduce(concat, conds)
2.32 + return UtilNodes.TempBlockExprNode(lhs, condition)
2.33 +
2.34 def visit_Node(self, node):
2.35 self.visitchildren(node)
2.36 return node
3.1 --- a/Cython/Compiler/UtilNodes.py Sun Dec 07 21:12:58 2008 +0100
3.2 +++ b/Cython/Compiler/UtilNodes.py Sun Dec 07 21:14:13 2008 +0100
3.3 @@ -105,3 +105,72 @@
3.4 def annotate(self, code):
3.5 self.body.annotate(code)
3.6
3.7 +
3.8 +class ResultRefNode(AtomicExprNode):
3.9 + # A reference to the result of an expression. The result_code
3.10 + # must be set externally (usually a temp name).
3.11 +
3.12 + subexprs = []
3.13 +
3.14 + def __init__(self, expression):
3.15 + self.pos = expression.pos
3.16 + self.expression = expression
3.17 +
3.18 + def analyse_types(self, env):
3.19 + self.type = self.expression.type
3.20 +
3.21 + def result(self):
3.22 + return self.result_code
3.23 +
3.24 + def generate_evaluation_code(self, code):
3.25 + pass
3.26 +
3.27 + def generate_result_code(self, code):
3.28 + pass
3.29 +
3.30 + def generate_disposal_code(self, code):
3.31 + pass
3.32 +
3.33 + def allocate_temps(self, env):
3.34 + pass
3.35 +
3.36 + def release_temp(self, env):
3.37 + pass
3.38 +
3.39 + def free_temps(self, code):
3.40 + pass
3.41 +
3.42 +
3.43 +class TempBlockExprNode(ExprNodes.NewTempExprNode):
3.44 + # A wrapper around a subexpression that moves an expression into a
3.45 + # temp variable and provides it to the subexpression.
3.46 +
3.47 + subexprs = ['temp_expression', 'subexpression']
3.48 +
3.49 + def __init__(self, lazy_temp, subexpression):
3.50 + self.pos = subexpression.pos
3.51 + self.lazy_temp = lazy_temp
3.52 + self.temp_expression = lazy_temp.expression
3.53 + self.subexpression = subexpression
3.54 +
3.55 + def result(self):
3.56 + return self.subexpression.result()
3.57 +
3.58 + def analyse_types(self, env):
3.59 + self.temp_expression.analyse_types(env)
3.60 + self.subexpression.analyse_types(env)
3.61 + self.type = self.subexpression.type
3.62 +
3.63 + def generate_evaluation_code(self, code):
3.64 + self.temp_expression.generate_evaluation_code(code)
3.65 + if self.temp_expression.is_temp:
3.66 + temp = self.temp_expression.result()
3.67 + else:
3.68 + self.temp_expression.make_owned_reference(code)
3.69 + temp = code.funcstate.allocate_temp(
3.70 + self.temp_expression.type, manage_ref=True)
3.71 + code.putln("%s = %s;" % (temp, self.temp_expression.result()))
3.72 + self.lazy_temp.result_code = temp
3.73 + self.subexpression.generate_evaluation_code(code)
3.74 + if not self.temp_expression.is_temp:
3.75 + code.funcstate.release_temp(temp)
