augmented assignment

I 'finished' the new augmented assignment patch yesterday, following the suggestions made by Guido about using INPLACE_* bytecodes rather than special GETSET_* opcodes. I ended up with 13 new opcodes: INPLACE_* opcodes for the 11 binary operation opcodes, DUP_TOPX which duplicates a number of stack items instead of just the topmost item, and ROT_FOUR. I thought I didn't need ROT_FOUR if we had DUP_TOPX but I hadn't realized assignment needs the new value at the bottom of the 'stack', and the objects that are used in the assignment above that. So ROT_FOUR is necessary in the case of slice-assignment: a[b:c] += i LOAD a [a] LOAD b [a, b] LOAD c [a, b, c] DUP_TOPX 3 [a, b, c, a, b, c] SLICE+3 [a, b, c, a[b:c]] LOAD i [a, b, c, a[b:c], i] INPLACE_ADD [a, b, c, result] ROT_FOUR [result, a, b, c] STORE_SLICE+3 [] When (and if) the *SLICE opcodes are removed, ROT_FOUR can, too :) The patch is 'done' in my opinion, except for two tiny things: - PyNumber_InPlacePower() takes just two arguments, not three. Three argument power() does such 'orrible things to coerce all the arguments, and you can't do augmented-assignment-three-argument-power anyway. If it's added it would be for the API only, and I'm not sure if it's worth it :P - I still don't like the '_ab_' names :) I think __inplace_add__ or __iadd__ is better, but that's just me. The PEP is also 'done'. Feedback is more than welcome, including spelling fixes and the like. I've attached the PEP to this mail, for convenience. -- Thomas Wouters <thomas@xs4all.net> Hi! I'm a .signature virus! copy me into your .signature file to help me spread!
participants (1)
-
Thomas Wouters