1.1 --- a/docs/syspython.txt Thu Oct 31 16:51:59 2013 +0100
1.2 +++ b/docs/syspython.txt Thu Oct 31 17:18:31 2013 +0100
1.3 @@ -178,6 +178,21 @@
1.4 storelocal(a, b)
1.5 storeattr(module, g, f)
1.6
1.7 +Assignments
1.8 +-----------
1.9 +
1.10 +Since assignments can rebind names used in the value expression, the evaluated
1.11 +expression must be captured and referenced when setting the targets. This is
1.12 +done using the special $expr variable, and so the swap assignment...
1.13 +
1.14 + a, b = b, a
1.15 +
1.16 +...would be written (more or less) as...
1.17 +
1.18 + $expr = (b, a)
1.19 + storelocal(a, apply(operator.getitem, $expr, 0))
1.20 + storelocal(b, apply(operator.getitem, $expr, 1))
1.21 +
1.22 Names and Attributes
1.23 --------------------
1.24
2.1 --- a/micropython/syspython.py Thu Oct 31 16:51:59 2013 +0100
2.2 +++ b/micropython/syspython.py Thu Oct 31 17:18:31 2013 +0100
2.3 @@ -135,7 +135,10 @@
2.4
2.5 def visitAssign(self, node):
2.6 expr = self.dispatch(node.expr)
2.7 - return compiler.ast.Stmt([self.dispatch(n, expr) for n in node.nodes])
2.8 + return compiler.ast.Stmt(
2.9 + [compiler.ast.Assign([compiler.ast.AssName("$expr", "OP_ASSIGN")], expr)] +
2.10 + [self.dispatch(n, compiler.ast.Name("$expr")) for n in node.nodes]
2.11 + )
2.12
2.13 def visitAugAssign(self, node):
2.14