Commit 7553a7f1 authored by Robert Bradshaw's avatar Robert Bradshaw

Actualy use PyNumber_Inplace* operations.

parent 0c71ed61
...@@ -5407,7 +5407,7 @@ class BinopNode(ExprNode): ...@@ -5407,7 +5407,7 @@ class BinopNode(ExprNode):
#print "BinopNode.generate_result_code:", self.operand1, self.operand2 ### #print "BinopNode.generate_result_code:", self.operand1, self.operand2 ###
if self.operand1.type.is_pyobject: if self.operand1.type.is_pyobject:
function = self.py_operation_function() function = self.py_operation_function()
if function == "PyNumber_Power": if self.operator == '**':
extra_args = ", Py_None" extra_args = ", Py_None"
else: else:
extra_args = "" extra_args = ""
...@@ -5510,7 +5510,10 @@ class NumBinopNode(BinopNode): ...@@ -5510,7 +5510,10 @@ class NumBinopNode(BinopNode):
BinopNode.is_py_operation_types(self, type1, type2)) BinopNode.is_py_operation_types(self, type1, type2))
def py_operation_function(self): 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 = { py_functions = {
"|": "PyNumber_Or", "|": "PyNumber_Or",
...@@ -5527,7 +5530,6 @@ class NumBinopNode(BinopNode): ...@@ -5527,7 +5530,6 @@ class NumBinopNode(BinopNode):
"**": "PyNumber_Power" "**": "PyNumber_Power"
} }
class IntBinopNode(NumBinopNode): class IntBinopNode(NumBinopNode):
# Binary operation taking integer arguments. # Binary operation taking integer arguments.
...@@ -6642,13 +6644,14 @@ binop_node_classes = { ...@@ -6642,13 +6644,14 @@ binop_node_classes = {
"**": PowNode "**": PowNode
} }
def binop_node(pos, operator, operand1, operand2): def binop_node(pos, operator, operand1, operand2, inplace=False):
# Construct binop node of appropriate class for # Construct binop node of appropriate class for
# given operator. # given operator.
return binop_node_classes[operator](pos, return binop_node_classes[operator](pos,
operator = operator, operator = operator,
operand1 = operand1, operand1 = operand1,
operand2 = operand2) operand2 = operand2,
inplace = inplace)
#------------------------------------------------------------------- #-------------------------------------------------------------------
# #
......
...@@ -3552,21 +3552,6 @@ class InPlaceAssignmentNode(AssignmentNode): ...@@ -3552,21 +3552,6 @@ class InPlaceAssignmentNode(AssignmentNode):
self.rhs.generate_disposal_code(code) self.rhs.generate_disposal_code(code)
self.rhs.free_temps(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): def annotate(self, code):
self.lhs.annotate(code) self.lhs.annotate(code)
self.rhs.annotate(code) self.rhs.annotate(code)
......
...@@ -1243,8 +1243,9 @@ class ExpandInplaceOperators(CythonTransform): ...@@ -1243,8 +1243,9 @@ class ExpandInplaceOperators(CythonTransform):
binop = binop_node(node.pos, binop = binop_node(node.pos,
operator = node.operator, operator = node.operator,
operand1 = dup, operand1 = dup,
operand2 = rhs) operand2 = rhs,
node = SingleAssignmentNode(node.pos, lhs=lhs, rhs=binop) #, inplace=True) inplace=True)
node = SingleAssignmentNode(node.pos, lhs=lhs, rhs=binop)
# Use LetRefNode to avoid side effects. # Use LetRefNode to avoid side effects.
let_ref_nodes.reverse() let_ref_nodes.reverse()
for t in let_ref_nodes: for t in let_ref_nodes:
......
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