Actualy use PyNumber_Inplace* operations.
authorRobert Bradshaw <robertwb@math.washington.edu>
Fri, 12 Nov 2010 09:10:37 +0000 (01:10 -0800)
committerRobert Bradshaw <robertwb@math.washington.edu>
Fri, 12 Nov 2010 09:10:37 +0000 (01:10 -0800)
Cython/Compiler/ExprNodes.py
Cython/Compiler/Nodes.py
Cython/Compiler/ParseTreeTransforms.py

index 0459938f07aec987369765b69277eef612338f22..e6ec468153d58eb8e3e3631c018f2712e48fc1aa 100755 (executable)
@@ -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)
 
 #-------------------------------------------------------------------
 #
index d6123ba85da15af4432b8e054ccffb4c5427ae91..3cfc336b35f17a0174ca61e0e837866c8621cfeb 100644 (file)
@@ -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)
index 4cfb6c60d974d72b793f15c6d32e8f18b1b6dbd1..bb2f0f27c43c935d5c1aba99dd4cef96af149470 100644 (file)
@@ -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: