1.1 --- a/simplify.py Sat Jul 15 00:46:12 2006 +0200
1.2 +++ b/simplify.py Sat Jul 15 00:47:24 2006 +0200
1.3 @@ -270,7 +270,9 @@
1.4 # Assignments.
1.5
1.6 augassign_methods = {
1.7 - "+=" : "__iadd__", "-=" : "__isub__", "*=" : "__imul__", "/=" : "__idiv__"
1.8 + "+=" : "__iadd__", "-=" : "__isub__", "*=" : "__imul__", "/=" : "__idiv__",
1.9 + "%=" : "__imod__", "**=" : "__ipow__", "<<=" : "__ilshift__", ">>=" : "__irshift__",
1.10 + "&=" : "__iand__", "^=" : "__ixor__", "|=" : "__ior__"
1.11 }
1.12
1.13 def visitAugAssign(self, augassign):
1.14 @@ -288,11 +290,11 @@
1.15 store = StoreName(expr=LoadTemp(), name=name.name)
1.16 result.code = [get_incremented, store, ReleaseTemp()]
1.17
1.18 - # Complicated augmented assignment: expr.attr += expr
1.19 + # Complicated augmented assignment: lvalue.attr += expr
1.20
1.21 elif isinstance(augassign.node, compiler.ast.Getattr):
1.22
1.23 - # <expr> -> <expr>.attr.__xxx__(
1.24 + # <lvalue> -> setattr(<lvalue>, getattr(<lvalue>, "attr").__xxx__(expr))
1.25
1.26 getattr = augassign.node
1.27 store_expr = StoreTemp(index="expr", expr=self.dispatch(getattr.expr))
1.28 @@ -303,9 +305,12 @@
1.29 store = StoreAttr(expr=LoadTemp(), lvalue=LoadTemp(index="expr"), name=getattr.attrname)
1.30 result.code = [store_expr, get_incremented, store, ReleaseTemp(index="expr"), ReleaseTemp()]
1.31
1.32 - # Complicated augassign using slices and subscripts.
1.33 + # Complicated augassign using slices: lvalue[lower:upper] += expr
1.34
1.35 elif isinstance(augassign.node, compiler.ast.Slice):
1.36 +
1.37 + # <lvalue>, <lower>, <upper> -> <lvalue>.__setslice__(<lower>, <upper>, <lvalue>.__getslice__(<lower>, <upper>).__xxx__(expr))
1.38 +
1.39 slice = augassign.node
1.40 store_expr = StoreTemp(index="expr", expr=self.dispatch(slice.expr))
1.41 store_lower = StoreTemp(index="lower", expr=self.dispatch_or_none(slice.lower))
1.42 @@ -314,7 +319,7 @@
1.43 get_incremented = StoreTemp(
1.44 expr=Invoke(expr=LoadAttr(expr=node_slice, name=self.augassign_methods[augassign.op]), args=[expr])
1.45 )
1.46 - store = self._visitSlice(LoadTemp(index="expr"), LoadTemp(index="lower"), LoadTemp(index="upper"), "OP_ASSIGN", expr)
1.47 + store = self._visitSlice(LoadTemp(index="expr"), LoadTemp(index="lower"), LoadTemp(index="upper"), "OP_ASSIGN", LoadTemp())
1.48 result.code = [store_expr, store_lower, store_upper, get_incremented, store,
1.49 ReleaseTemp(index="expr"), ReleaseTemp(index="lower"), ReleaseTemp(index="upper"), ReleaseTemp()]
1.50