Re: [myhdl-list] Can't compare Signal(enum)
Brought to you by:
jandecaluwe
From: Christopher F. <chr...@gm...> - 2014-07-28 15:27:06
|
On 7/28/2014 7:08 AM, Thomas Heller wrote: > I cannot compare signals containing enum instances; this looks like a > bug to me: > > c:\Users\thomas\ip>py -2.7-32 > Python 2.7.7 (default, Jun 1 2014, 14:17:13) [MSC v.1500 32 bit > (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. > >>> import myhdl > >>> > >>> state = myhdl.enum("foo", "bar") > >>> > >>> a = myhdl.Signal(state.foo) > >>> b = myhdl.Signal(state.bar) > >>> > >>> print a == b > Traceback (most recent call last): > File "<stdin>", line 1, in <module> > File "C:\Python27\lib\site-packages\myhdl\_Signal.py", line 479, in > __cmp__ > return cmp(self._val, other) > File "C:\Python27\lib\site-packages\myhdl\_enum.py", line 109, in > _notImplementedCompare > raise NotImplementedError > NotImplementedError > >>> > Yes, I would agree this is unexpected behavior. The problem is the use of the "cmp" function in the Signal class. The cmp(x, y) [1] function performs a x > y which is not implemented in the enum class (good reason). The use-case of a Signal(enum) == Signal(enum) probably has not been used, but I agree it is a valid case. import myhdl state = myhdl.enum("foo", "bar") a = myhdl.Signal(state.foo) b = myhdl.Signal(state.bar) print a == state.foo print a == state.bar print b == state.foo print b == state.bar print a == b Only the Signal(enum) == Signal(enum) fails because the Signal comparison calls. This should be added as an issue in the repo tracker [2]. Regards, Chris [1] https://docs.python.org/2/library/functions.html?highlight=cmp#cmp [2] https://bitbucket.org/jandecaluwe/myhdl/issues?status=new&status=open |