Lichen

tests/contexts.py

338:61776a5a0e16
2016-12-07 Paul Boddie Associate constant name information with references so that structure members such as function instance default members can be generated statically, thus eliminating unnecessary structure initialisation in the translated code. Improved the determination of dynamic functions in the importer to consider only non-constant defaults.
     1 class C:     2     l = [2, 4, 6, 8, 10]     3     s = "test"     4     def __init__(self, x):     5         self.x = x     6         self.y = 3     7         self.z = "zebra libre"     8      9 c = C([1])    10 x = c.x    11 f = c.x.__len__    12 print c             # <__main__.C instance>    13 print x             # [1]    14 print f             # __builtins__.list.list.__len__    15 print f()           # 1    16     17 y = c.l    18 g = c.l.__len__    19 print y             # [2, 4, 6, 8, 10]    20 print g             # __builtins__.list.list.__len__    21 print g()           # 5    22     23 yy = C.l    24 gg = C.l.__len__    25 print yy            # [2, 4, 6, 8, 10]    26 print gg            # __builtins__.list.list.__len__    27 print gg()          # 5    28     29 z = c.s    30 h = c.s.__len__    31 print z             # test    32 print h             # __builtins__.str.basestring.__len__    33 print h()           # 4    34     35 zz = C.s    36 hh = C.s.__len__    37 print zz            # test    38 print hh            # __builtins__.str.basestring.__len__    39 print hh()          # 4    40     41 a = c.y    42 b = c.z    43 i = c.z.__len__    44 print a             # 3    45 print b             # zebra libre    46 print i             # __builtins__.str.basestring.__len__    47 print i()           # 11