1.1 --- a/common.py Mon May 20 21:26:54 2024 +0200
1.2 +++ b/common.py Tue May 21 17:02:49 2024 +0200
1.3 @@ -381,6 +381,8 @@
1.4 target = compiler.ast.AssAttr(n.node.expr, n.node.attrname, "OP_ASSIGN")
1.5 elif isinstance(n.node, compiler.ast.Name):
1.6 target = compiler.ast.AssName(n.node.name, "OP_ASSIGN")
1.7 + elif isinstance(n.node, compiler.ast.Subscript):
1.8 + target = compiler.ast.Subscript(n.node.expr, "OP_ASSIGN", n.node.subs)
1.9 else:
1.10 target = n.node
1.11
2.1 --- a/templates/native/list.c Mon May 20 21:26:54 2024 +0200
2.2 +++ b/templates/native/list.c Tue May 21 17:02:49 2024 +0200
2.3 @@ -1,6 +1,6 @@
2.4 /* Native functions for list operations.
2.5
2.6 -Copyright (C) 2016, 2017, 2021, 2023 Paul Boddie <paul@boddie.org.uk>
2.7 +Copyright (C) 2016, 2017, 2021, 2023, 2024 Paul Boddie <paul@boddie.org.uk>
2.8
2.9 This program is free software; you can redistribute it and/or modify it under
2.10 the terms of the GNU General Public License as published by the Free Software
2.11 @@ -120,7 +120,7 @@
2.12 __int i = __TOINT(index);
2.13
2.14 /* Set the element. */
2.15 - elements[i] = value;
2.16 + __set_attr(&elements[i], value);
2.17 return __builtins___none_None;
2.18 }
2.19
3.1 --- a/tests/list.py Mon May 20 21:26:54 2024 +0200
3.2 +++ b/tests/list.py Tue May 21 17:02:49 2024 +0200
3.3 @@ -97,3 +97,11 @@
3.4
3.5 e.reverse()
3.6 print e # [2, 1, 3]
3.7 +
3.8 +# Test augmented operations.
3.9 +
3.10 +e[0] += e[1]
3.11 +print e # [3, 1, 3]
3.12 +
3.13 +e[0] += e[1] + e[2]
3.14 +print e # [7, 1, 3]
4.1 --- a/tests/values.py Mon May 20 21:26:54 2024 +0200
4.2 +++ b/tests/values.py Tue May 21 17:02:49 2024 +0200
4.3 @@ -2,6 +2,28 @@
4.4 a = a - 1.0
4.5 return a
4.6
4.7 +def test_assign(l, x):
4.8 + l[0] = x
4.9 +
4.10 +def test_augmented(l, x):
4.11 + l[0] += x + l[1]
4.12 +
4.13 x = 2.0
4.14 print test(x) # 1.0
4.15 print x # 2.0
4.16 +
4.17 +l = [1, 2, 3]
4.18 +test_assign(l, 4)
4.19 +print l # [4, 2, 3]
4.20 +
4.21 +l2 = [1, 2, 3]
4.22 +test_augmented(l2, 1)
4.23 +print l2 # [4, 2, 3]
4.24 +
4.25 +l3 = [1.0, 2.0, 3.0]
4.26 +test_assign(l3, 4.0)
4.27 +print l3 # [4.0, 2.0, 3.0]
4.28 +
4.29 +l4 = [1.0, 2.0, 3.0]
4.30 +test_augmented(l4, 1.0)
4.31 +print l4 # [4.0, 2.0, 3.0]