2018-07-12 | Paul Boddie | file changeset files shortlog | Support trailing data after attributes in objects, employed by float instances to store their double-precision numeric data which needs more space than single attributes on some systems. In order to initialise such instances statically, specific object types must be indicated instead of the generic __obj type. This then requires casting to __ref of direct references to objects. Added an underflow error. Added initial testing of floating point numbers. | trailing-data |
paul@792 | 1 | class SignalState: |
paul@792 | 2 | Red = 1 |
paul@792 | 3 | Amber = 2 |
paul@792 | 4 | Green = 3 |
paul@792 | 5 | AmberAgain = 4 |
paul@792 | 6 | Off = None |
paul@792 | 7 | |
paul@792 | 8 | class Signal: |
paul@792 | 9 | def __init__(self): |
paul@792 | 10 | self.disable() |
paul@792 | 11 | |
paul@792 | 12 | def enable(self): |
paul@792 | 13 | self.state = SignalState.Red |
paul@792 | 14 | |
paul@792 | 15 | def disable(self): |
paul@792 | 16 | self.state = SignalState.Off |
paul@792 | 17 | |
paul@792 | 18 | def next(self): |
paul@792 | 19 | if self.state == SignalState.Red: |
paul@792 | 20 | self.state = SignalState.Amber |
paul@792 | 21 | elif self.state == SignalState.Amber: |
paul@792 | 22 | self.state = SignalState.Green |
paul@792 | 23 | elif self.state == SignalState.Green: |
paul@792 | 24 | self.state = SignalState.AmberAgain |
paul@792 | 25 | elif self.state == SignalState.AmberAgain: |
paul@792 | 26 | self.state = SignalState.Red |
paul@792 | 27 | else: |
paul@792 | 28 | self.state = SignalState.Off |
paul@792 | 29 | |
paul@792 | 30 | s = Signal() |
paul@792 | 31 | print s.state # None |
paul@792 | 32 | s.next() |
paul@792 | 33 | print s.state # None |
paul@792 | 34 | s.enable() |
paul@792 | 35 | print s.state # 1 |
paul@792 | 36 | s.next() |
paul@792 | 37 | print s.state # 2 |
paul@792 | 38 | s.next() |
paul@792 | 39 | print s.state # 3 |
paul@792 | 40 | s.next() |
paul@792 | 41 | print s.state # 4 |
paul@792 | 42 | s.next() |
paul@792 | 43 | print s.state # 1 |