9 months ago | Paul Boddie | raw annotate files changeset graph | Permit the replacement of floating-point values in locally-referenced objects. To achieve this, a result target parameter has been introduced in callable signatures alongside the existing context parameter so that references to objects can be propagated to operations that are able to replace the value of such objects. Result target objects are currently supported only for locals and intermediate results in functions and methods, with assignments to locals or the storage of intermediate results involving the copying of any given floating-point objects instead of merely referencing them. Such distinct copies may then be used as result targets when locals or intermediate result locations are subsequently reused. Value replacement avoids the allocation of temporary objects that can quickly dominate execution time in programs repeatedly performing large numbers of floating-point calculations. | value-replacement |
1 class SignalState: 2 Red = 1 3 Amber = 2 4 Green = 3 5 AmberAgain = 4 6 Off = None 7 8 class Signal: 9 def __init__(self): 10 self.disable() 11 12 def enable(self): 13 self.state = SignalState.Red 14 15 def disable(self): 16 self.state = SignalState.Off 17 18 def next(self): 19 if self.state == SignalState.Red: 20 self.state = SignalState.Amber 21 elif self.state == SignalState.Amber: 22 self.state = SignalState.Green 23 elif self.state == SignalState.Green: 24 self.state = SignalState.AmberAgain 25 elif self.state == SignalState.AmberAgain: 26 self.state = SignalState.Red 27 else: 28 self.state = SignalState.Off 29 30 s = Signal() 31 print s.state # None 32 s.next() 33 print s.state # None 34 s.enable() 35 print s.state # 1 36 s.next() 37 print s.state # 2 38 s.next() 39 print s.state # 3 40 s.next() 41 print s.state # 4 42 s.next() 43 print s.state # 1