Re: [myhdl-list] Setting of enum values
Brought to you by:
jandecaluwe
From: Jan D. <ja...@ja...> - 2015-01-11 08:33:59
|
On 01/10/2015 10:55 AM, Henry Gomersall wrote: > On 10/01/15 08:50, Jan Decaluwe wrote: >> On 12/28/2014 06:44 PM, Henry Gomersall wrote: >>>> On 28/12/14 11:24, Henry Gomersall wrote: >>>>>> Looking at the code, it seems the enum value is set by the argument >>>>>> order, so I can't see how to do it trivially. >>>> >>>> It strikes me that the problem is that the class definition is inside >>>> the enum factory function. Is there a reason for this? >> Sure - the enum factory function is intended to create >> a brand new type, like in VHDL. > > Right, that makes sense in light of the view that enum should more than > just a symbolic representation of an int down to the HDL level. > > This is handled rather differently in the standard enum that allows > quite a bit more flexibility in the design - the uniqueness of the items > is enforced through the Enum metaclass. In MyHDL uniquness is enforced by the factory function. I have briefly looked at the Python enum, and I don't like it. It seems incredibably complicated with metaclasses and full of magic. Confusing also. To construct an enum, you have to assign integers to names. Those integers don't really have a meaning, but you can still use them to access items. Ugly. The class is "strongly recommended", but then they still provide an IntEnum that further blurs the distinction betweens integers and enum items. The whole blurring of integers with enum items comes from languages that unlike VHDL don't have a good enum model. The whole point of a enum is to have an abstract type where nothing matters but the item name. The MyHDL enum makes that very clear - no integers in sight. Therefore, I'll stick to MyHDL's enum, clean and to the point. -- Jan Decaluwe - Resources bvba - http://www.jandecaluwe.com Python as a HDL: http://www.myhdl.org VHDL development, the modern way: http://www.sigasi.com World-class digital design: http://www.easics.com |