From: Robert Bradshaw Date: Fri, 12 Nov 2010 09:10:37 +0000 (-0800) Subject: Actualy use PyNumber_Inplace* operations. X-Git-Tag: 0.14.alpha0~178^2~4 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=7553a7f16271afc360f7654f35896393de112935;p=cython.git Actualy use PyNumber_Inplace* operations. --- diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py index 0459938f..e6ec4681 100755 --- a/Cython/Compiler/ExprNodes.py +++ b/Cython/Compiler/ExprNodes.py @@ -5407,7 +5407,7 @@ class BinopNode(ExprNode): #print "BinopNode.generate_result_code:", self.operand1, self.operand2 ### if self.operand1.type.is_pyobject: function = self.py_operation_function() - if function == "PyNumber_Power": + if self.operator == '**': extra_args = ", Py_None" else: extra_args = "" @@ -5510,7 +5510,10 @@ class NumBinopNode(BinopNode): BinopNode.is_py_operation_types(self, type1, type2)) def py_operation_function(self): - return self.py_functions[self.operator] + fuction = self.py_functions[self.operator] + if self.inplace: + fuction = fuction.replace('PyNumber_', 'PyNumber_InPlace') + return fuction py_functions = { "|": "PyNumber_Or", @@ -5527,7 +5530,6 @@ class NumBinopNode(BinopNode): "**": "PyNumber_Power" } - class IntBinopNode(NumBinopNode): # Binary operation taking integer arguments. @@ -6642,13 +6644,14 @@ binop_node_classes = { "**": PowNode } -def binop_node(pos, operator, operand1, operand2): +def binop_node(pos, operator, operand1, operand2, inplace=False): # Construct binop node of appropriate class for # given operator. return binop_node_classes[operator](pos, operator = operator, operand1 = operand1, - operand2 = operand2) + operand2 = operand2, + inplace = inplace) #------------------------------------------------------------------- # diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py index d6123ba8..3cfc336b 100644 --- a/Cython/Compiler/Nodes.py +++ b/Cython/Compiler/Nodes.py @@ -3552,21 +3552,6 @@ class InPlaceAssignmentNode(AssignmentNode): self.rhs.generate_disposal_code(code) self.rhs.free_temps(code) - py_functions = { - "|": "PyNumber_InPlaceOr", - "^": "PyNumber_InPlaceXor", - "&": "PyNumber_InPlaceAnd", - "+": "PyNumber_InPlaceAdd", - "-": "PyNumber_InPlaceSubtract", - "*": "PyNumber_InPlaceMultiply", - "/": "__Pyx_PyNumber_InPlaceDivide", - "%": "PyNumber_InPlaceRemainder", - "<<": "PyNumber_InPlaceLshift", - ">>": "PyNumber_InPlaceRshift", - "**": "PyNumber_InPlacePower", - "//": "PyNumber_InPlaceFloorDivide", - } - def annotate(self, code): self.lhs.annotate(code) self.rhs.annotate(code) diff --git a/Cython/Compiler/ParseTreeTransforms.py b/Cython/Compiler/ParseTreeTransforms.py index 4cfb6c60..bb2f0f27 100644 --- a/Cython/Compiler/ParseTreeTransforms.py +++ b/Cython/Compiler/ParseTreeTransforms.py @@ -1243,8 +1243,9 @@ class ExpandInplaceOperators(CythonTransform): binop = binop_node(node.pos, operator = node.operator, operand1 = dup, - operand2 = rhs) - node = SingleAssignmentNode(node.pos, lhs=lhs, rhs=binop) #, inplace=True) + operand2 = rhs, + inplace=True) + node = SingleAssignmentNode(node.pos, lhs=lhs, rhs=binop) # Use LetRefNode to avoid side effects. let_ref_nodes.reverse() for t in let_ref_nodes: