2021-11-28 | Paul Boddie | raw annotate files changeset graph | 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 |
1 class C: 2 def f(self): 3 return 1 4 5 def g(self): 6 return self.f() 7 8 class D(C): 9 pass 10 11 def f(): 12 return 2 13 14 c = C() 15 d = D() 16 17 # Invoke a method that calls the default version of f. 18 19 print c.g() # 1 20 print d.g() # 1 21 22 # Replace f in C and invoke the method again. For C, f will have changed, 23 # but for D, f will retain its original value. 24 25 C.f = f 26 27 print c.g() # 2 28 print d.g() # 1