micropython

tests/attributes3.py

223:09ae448806d1
2009-05-24 Paul Boddie Added a StoreAddressContext instruction for class attribute initialisation. Fixed the mechanism behind LoadAttrIndexContextCond and LoadAddressContextCond since it failed to provide the appropriate instance context for instance accesses. Added a LoadFunction instruction in order to distinguish between constants which have no context information and those which do.
     1 #!/usr/bin/env python     2      3 class C:     4     def g(self):     5         return self.f # C.f with context self     6     def f(self): pass     7      8     def test(self):     9         self.f()    10         self.g()    11     12 class D:    13     f = C.f    14     def g(self):    15         return self.f # D.f with context preserved    16     17     def test(self):    18         self.f(2)    19         self.g()    20     21 class E(C):    22     def g(self):    23         return self.f # C.f with context self    24     25     def test(self):    26         self.f()    27         self.g()    28     29 C.f    30 D.f    31 E.f    32     33 c = C()    34 d = D()    35 e = E()    36     37 x = c.f # bound C.f   == c.g()    38 y = d.f # unbound C.f == d.g()    39 z = e.f # bound E.f   == e.g()    40     41 # vim: tabstop=4 expandtab shiftwidth=4