10 months ago | Paul Boddie | file changeset files shortlog | Permit the replacement of floating-point values in locally-referenced objects. To achieve this, a result target parameter has been introduced in callable signatures alongside the existing context parameter so that references to objects can be propagated to operations that are able to replace the value of such objects. Result target objects are currently supported only for locals and intermediate results in functions and methods, with assignments to locals or the storage of intermediate results involving the copying of any given floating-point objects instead of merely referencing them. Such distinct copies may then be used as result targets when locals or intermediate result locations are subsequently reused. Value replacement avoids the allocation of temporary objects that can quickly dominate execution time in programs repeatedly performing large numbers of floating-point calculations. | value-replacement |
paul@2 | 1 | def f(): |
paul@2 | 2 | l = [1, 2, 3] |
paul@2 | 3 | x = l |
paul@2 | 4 | a, b, c = l |
paul@2 | 5 | d, e, f = [1, 2, 3] |
paul@243 | 6 | print a, b, c # 1, 2, 3 |
paul@243 | 7 | print d, e, f # 1, 2, 3 |
paul@243 | 8 | print x # [1, 2, 3] |
paul@2 | 9 | |
paul@2 | 10 | def g(x): |
paul@2 | 11 | l = [1, 2, 3] |
paul@2 | 12 | m = [4, l, 6] |
paul@2 | 13 | if x: |
paul@2 | 14 | n = l |
paul@2 | 15 | else: |
paul@2 | 16 | n = m |
paul@173 | 17 | print n |
paul@2 | 18 | |
paul@560 | 19 | def h(): |
paul@560 | 20 | return 7, 8, 9 |
paul@560 | 21 | |
paul@561 | 22 | def i(): |
paul@561 | 23 | a, b, c = h() |
paul@561 | 24 | print a, b, c |
paul@561 | 25 | |
paul@561 | 26 | # Test assignment operations within functions. |
paul@561 | 27 | |
paul@197 | 28 | f() |
paul@243 | 29 | g(0) # [4, [1, 2, 3], 6] |
paul@243 | 30 | g(1) # [1, 2, 3] |
paul@197 | 31 | |
paul@561 | 32 | # Test aliasing, assignment of list elements and direct assignment of elements. |
paul@561 | 33 | |
paul@2 | 34 | l = [1, 2, 3] |
paul@2 | 35 | x = l |
paul@2 | 36 | a, b, c = l |
paul@2 | 37 | d, e, f = [1, 2, 3] |
paul@560 | 38 | |
paul@560 | 39 | print a, b, c # 1 2 3 |
paul@560 | 40 | print d, e, f # 1 2 3 |
paul@243 | 41 | print x # [1, 2, 3] |
paul@560 | 42 | |
paul@561 | 43 | # Test embedding of sequences in sequences. |
paul@561 | 44 | |
paul@2 | 45 | m = [4, l, 6] |
paul@561 | 46 | |
paul@561 | 47 | # Test sequence truth value interpretation. |
paul@561 | 48 | |
paul@2 | 49 | if x: |
paul@2 | 50 | n = l |
paul@2 | 51 | else: |
paul@2 | 52 | n = m |
paul@560 | 53 | |
paul@243 | 54 | print n # [1, 2, 3] |
paul@560 | 55 | |
paul@561 | 56 | # Test temporary variable usage at module level. |
paul@561 | 57 | |
paul@560 | 58 | a, b, c = h() |
paul@560 | 59 | print a, b, c # 7 8 9 |
paul@561 | 60 | |
paul@561 | 61 | # Test temporary variable usage in functions. |
paul@561 | 62 | |
paul@561 | 63 | i() # 7 8 9 |
paul@561 | 64 | |
paul@561 | 65 | # Test temporary variable usage in classes. |
paul@561 | 66 | |
paul@561 | 67 | class C: |
paul@561 | 68 | a, b, c = h() |
paul@561 | 69 | print a, b, c # 7 8 9 |