[myhdl-list] [PATCH] Remove redundant copy operators
Brought to you by:
jandecaluwe
From: Ben <ben...@gm...> - 2009-11-03 15:08:12
|
Hi there, First of all, hello to everyone, and thanks for this great initiative which is MyHDL, till now, I enjoyed using it. I ran into trouble though when I was looking for VHDL 'alias' ... I was trying to make my code more readable when dealing with ControlWords. The first solution I found is to make a always_comb process, but still, we have to use a .next, so we don't have strictly the 'alias' behavior. This solution is sort of driven by my "think hardware" mind, or should I say, education. The second solution I found, and there, MyHDL shows its supremacy, is to use Python as a tool, and not define my ControlWord as intbv, but to define my own class, say ctrlword that inherit from intbv, redefine "__getattr__", such that "ctrlword.subpart3" return the right slice from my intbv. THis also has the advantage that I keep complete compatibility (think conversion) with the intbv type. Clever isnt't it ? The only problem I got is that the intbv __copy__ function was forcing the return value as being an intbv, thus, removing all the information from my ctrlword. As both __copy__ and __deepcopy__ are behaving the same as the Python default one, I was able to remove them, without influencing the testsuite result. (By the way on my MacOSX, I have some test failing with regard to set and Set) Here is a patch that does what I described here. Best Regards Benoit # HG changeset patch # User Benoit Allard <ben...@gm...> # Date 1257160071 -3600 # Node ID bd6b60949b4e68023e41f49ce853c0058e02019b # Parent 2ff17ece613127b174cb7a6a9aa8ba765ffcbd01 Remove useless copy operators The default one are making the same, and even beter. Those one were preventing us to subclass the intbv class, as the copy were forcing the return type to intbv, removing information about our subclass. diff -r 2ff17ece6131 -r bd6b60949b4e myhdl/_intbv.py --- a/myhdl/_intbv.py Tue Oct 06 07:02:37 2009 -0500 +++ b/myhdl/_intbv.py Mon Nov 02 12:07:51 2009 +0100 @@ -90,12 +90,6 @@ def __hash__(self): raise TypeError("intbv objects are unhashable") - # copy methods - def __copy__(self): - return intbv(self) - def __deepcopy__(self, visit): - return intbv(self) - # iterator method def __iter__(self): if not self._nrbits: |