leonardt / fault

A Python package for testing hardware (part of the magma ecosystem)
BSD 3-Clause "New" or "Revised" License
41 stars 13 forks source link

Control actions should produce Tester based on current subclass #266

Closed leonardt closed 4 years ago

leonardt commented 4 years ago

Before, using a control structure such as tester._if would produce a StagedTester instance. This is problematic when using a SynchronousTester, since the produced tester doesn't inherit the expected methods (e.g. advance_cycle).

Also fix unrelated magma error from missing m.enable cast (regression introduced in latest magma release)

leonardt commented 4 years ago

Yes, I had to muck around with various not so great solutions. I was thinking having class variables would be the way to go, but you can't define class variable that references the class (since it doesn't exist yet) so that was a dead end. The easy way would just be to call a factory method inside init, but that would be bad for performance since we'd have to do it every time an object is created, although cacheing could avoid some of this. I ended up with this which is essentially monkey patching (danger!!) after class definition (since you need a reference to the class to create the children), but at least we can wrap it cleanly inside the decorator pattern and avoids runtime cost by only having to do it at definition time.