Lichen

tests/nested_calls.py

1036:e8ff2a117367
5 months ago Paul Boddie Fixed accessor temporary storage reservation for lambdas and eliminated redundant temporary storage reservation in attribute accesses.
     1 class C:     2     def __init__(self, x):     3         self.x = x     4      5     def value(self):     6         return self.x     7      8     def length(self):     9         return self.double(self.value())    10     11     def double(self, x):    12         return x * 2    13     14 c = C(3)    15 print c.length()                        # 6    16     17 # Explicit function for addition purposes.    18     19 def combine(x, y, z):    20     return x + y + z    21     22 class Tree:    23     def __init__(self, item, left=None, right=None):    24         self.item = item    25         self.left = left    26         self.right = right    27     28     def count(self):    29         if self.left and self.right:    30             # Test calls in parameter lists needing separate temporary storage.    31             return combine(self.item, self.left.count(), self.right.count())    32         else:    33             return self.item    34     35 tree = \    36     Tree(10000,    37         Tree(2000,    38             Tree(300),    39             Tree(40)    40             ),    41         Tree(5))    42     43 print tree.count()                      # 12345