Re: Setting of enum values

Marcel Hellwig <[email protected]> Thu, 21 Jan 2016 12:15:19 +0100
Newsgroups gmane.comp.python.myhdl
Message-ID <[email protected]>
On 21.01.2016 09:47, Thomas Heller wrote:
> [...]
> I had the same problem and currently only see these two possibilities:
> 
> 1. Import each constant and assign it in the myhdl code, like this:
> 
> from cpumode import CpuMode
> cpumode_User = CpuMode.User
> ...

ugly as hell :D but yeah, it kind of works...

> 
> 2. Define the constants as module level constants
> and use 'from mymodule import *' in the myhdl code.

I decided myself to this design. Would be nice though to have some kind
of namespace seperation.


On 21.01.2016 01:33, Jan Coombs wrote:
> Agreed, it is a complex one, and I accept the reasons for not
> pursuing this



I have an Idea and would like to know your thoughts about this:

> from myhdl import enum
> 
> procmode = enum(('User', 0b10001, ('System', 0b11111), (...), ...)


so giving them tuples (or a dict) with predefined values? This means
that you can pass constant values and names to it. You can check the
nrbits and everything else while creating the enum. I find this is an
quite elegant solution. What do you thinK?


Greetings,
Marcel

------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=267308311&iu=/4140

_______________________________________________
myhdl-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/myhdl-list
signature.asc (application/pgp-signature, 819 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iQIcBAEBCgAGBQJWoL3HAAoJEIROXYQnkAHpUsIQAIcrBs30teN/0g6hRR5vwwkZ
pYrXXt01ZVOhKIe6FChzI35CIddG3mNavrGBpL4UPPH5cYD5XdEn0XklPBbrXUof
J+cZGFY15S6q/h6Uti4r2StqastzXEQhFjWzSEmk8vZrqaIQ2/xCUlZt4d4l1nbO
bVeP5GClUVbbalmRQrjDNczqal1joedGBL7LUdlh/gJLohZmn98h7C7giA4JRbFI
4ndyaDp2ZLtvj3rmlN0eq2oD1qSenf0ITCNR+0WxJG5ZNDPKsxX6lzHGvVcprvsI
egLqUPrI6+Qj9/F4+ox0uobsCVp2Qjkt1oVFkK6JosxvzJYn4+sSmuCXza58RuYF
Pr4rDDx49Za6uHMC3Q/sfGWhx9CnS7JUHCNJLLokJU7nh8JkEk4jGwSxWSL6VPte
ed62mbwBxSHD+e/CVanGSYlkViBOVy3toCARmqgnbR0X6MRPNc4X8ciCO08wqUgP
NqBR0gNp2B0Q5N5CdpdiWf5m6VEQXiiuwg1Mpslvx7KygS06T9jriaAHOAp8H7kR
VXSDiyWrxA/oUEZUgn+REY9i3Lnu3W/TIGm85rI0Rh20JWW8ZoWFiuPrWAwxxAW4
tqLFUotvcPCc5cjiuaqd2tp+0tJxgLm3+enM1WFwyNVBAG/lmKIJfOeWlFd9/plw
jwVRwcwLUmOnq44vWNA5
=rHi7
-----END PGP SIGNATURE-----