# HG changeset patch # User Paul Boddie # Date 1716303769 -7200 # Node ID e16d60edc3676c0f54d3e309f1a346dc4e6fddf0 # Parent fb368817a23bbae69b093ef81df99f4ae993ddad# Parent e6010ccae0c0521094eb1803921305ceec028b6d Merged changes from the value-replacement branch. diff -r fb368817a23b -r e16d60edc367 common.py --- a/common.py Mon May 20 21:26:54 2024 +0200 +++ b/common.py Tue May 21 17:02:49 2024 +0200 @@ -381,6 +381,8 @@ target = compiler.ast.AssAttr(n.node.expr, n.node.attrname, "OP_ASSIGN") elif isinstance(n.node, compiler.ast.Name): target = compiler.ast.AssName(n.node.name, "OP_ASSIGN") + elif isinstance(n.node, compiler.ast.Subscript): + target = compiler.ast.Subscript(n.node.expr, "OP_ASSIGN", n.node.subs) else: target = n.node diff -r fb368817a23b -r e16d60edc367 templates/native/list.c --- a/templates/native/list.c Mon May 20 21:26:54 2024 +0200 +++ b/templates/native/list.c Tue May 21 17:02:49 2024 +0200 @@ -1,6 +1,6 @@ /* Native functions for list operations. -Copyright (C) 2016, 2017, 2021, 2023 Paul Boddie +Copyright (C) 2016, 2017, 2021, 2023, 2024 Paul Boddie This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -120,7 +120,7 @@ __int i = __TOINT(index); /* Set the element. */ - elements[i] = value; + __set_attr(&elements[i], value); return __builtins___none_None; } diff -r fb368817a23b -r e16d60edc367 tests/list.py --- a/tests/list.py Mon May 20 21:26:54 2024 +0200 +++ b/tests/list.py Tue May 21 17:02:49 2024 +0200 @@ -97,3 +97,11 @@ e.reverse() print e # [2, 1, 3] + +# Test augmented operations. + +e[0] += e[1] +print e # [3, 1, 3] + +e[0] += e[1] + e[2] +print e # [7, 1, 3] diff -r fb368817a23b -r e16d60edc367 tests/values.py --- a/tests/values.py Mon May 20 21:26:54 2024 +0200 +++ b/tests/values.py Tue May 21 17:02:49 2024 +0200 @@ -2,6 +2,28 @@ a = a - 1.0 return a +def test_assign(l, x): + l[0] = x + +def test_augmented(l, x): + l[0] += x + l[1] + x = 2.0 print test(x) # 1.0 print x # 2.0 + +l = [1, 2, 3] +test_assign(l, 4) +print l # [4, 2, 3] + +l2 = [1, 2, 3] +test_augmented(l2, 1) +print l2 # [4, 2, 3] + +l3 = [1.0, 2.0, 3.0] +test_assign(l3, 4.0) +print l3 # [4.0, 2.0, 3.0] + +l4 = [1.0, 2.0, 3.0] +test_augmented(l4, 1.0) +print l4 # [4.0, 2.0, 3.0]