Re: [myhdl-list] Setting of enum values
Brought to you by:
jandecaluwe
From: Henry G. <he...@ca...> - 2015-01-10 10:41:13
|
On 10/01/15 08:53, Jan Decaluwe wrote: > On 01/07/2015 01:23 PM, Henry Gomersall wrote: > >> >Further to this, why not just extend the existing python Enum: > MyHDL's enum was needed and implemented long before a > python Enum proposal emerged. > > It may be useful to review the python Enum and reuse > if possible. I have not done that. > > However - MyHDL's enum is intended to be modeled > after VHDL, not C or C++ which blur the distinction > between abstract enum types and integers. There is an argument to be made (which I'm trying to make :) ) that enums should be handled and enforced at the MyHDL level, and converted to whatever types make sense at the HDL level. Requiring that MyHDL enums map to VHDL enums rather limits their scope (isn't the point of MyHDL to surpass the existing languages?). The python enum has two parts: i) The genuine symbolic enum class Enum, which distinctly removes the blurring between ints and enums, and is analogous to the VHDL enum (though it does allow explicit numbering of the symbols). ii) The IntEnum class which makes the relationship with ints quite explicit. I think there is room and use cases for both types in MyHDL: * Interfacing with libraries that have certain enumerations defined would naturally fit with an IntEnum (even if it's only at the level of a sane, well-constrained namespace). This would map to an intbv at conversion. * Defining new e.g. states would do well to use a proper Enum. This could map to VHDL enum if the numbering made sense (or was ignored). Some of the benefit of IntEnum can _almost_ be had in 0.9 - with values mapping to constants, the only problem there being the conversion issue of integer attributes on an object being transcribed with the dot notation included - the same issue that is discussed in MEP 107 for interfaces. The other issue is that it is up to the user to specify the bit vector length for the values. There is clearly a nod to different encoding schemes in the enum class as it stands (with the encoding kw arg). Cheers, Henry |