2021-11-28 | Paul Boddie | file changeset files shortlog | Introduced support for values that can be allocated on a special thread-local stack, copied around and overwritten/mutated, demonstrating the concept using integer and floating-point numbers. Various complications arise with special attributes (such as __data__) due to the way references are tagged to indicate mutable values, and attribute slots must be cleared in locals, objects and fragments before values are stored since target slots are tested for mutable values. | tagged-address-values |
paul@816 | 1 | class MixIn: |
paul@816 | 2 | def f(self): |
paul@816 | 3 | return self.g() |
paul@816 | 4 | def f2(self): |
paul@816 | 5 | return self.g2() |
paul@816 | 6 | |
paul@816 | 7 | class Concrete(MixIn): |
paul@816 | 8 | def g(self): |
paul@816 | 9 | return 13579 |
paul@816 | 10 | def g2(self): |
paul@816 | 11 | return 13579 |
paul@816 | 12 | |
paul@816 | 13 | class Cement(MixIn): |
paul@816 | 14 | def g2(self): |
paul@816 | 15 | return 24680 |
paul@816 | 16 | |
paul@816 | 17 | m = MixIn() |
paul@816 | 18 | |
paul@816 | 19 | try: |
paul@816 | 20 | print m.f() |
paul@816 | 21 | except TypeError: |
paul@816 | 22 | print "m.f: cannot obtain attribute" |
paul@816 | 23 | |
paul@816 | 24 | c = Concrete() |
paul@816 | 25 | print c.f() # 13579 |
paul@816 | 26 | |
paul@816 | 27 | try: |
paul@816 | 28 | print m.f2() |
paul@816 | 29 | except TypeError: |
paul@816 | 30 | print "m.f2: cannot obtain attribute" |
paul@816 | 31 | |
paul@816 | 32 | c2 = Cement() |
paul@816 | 33 | print c2.f2() # 24680 |