Bit slicing without upper bound looses length information
Brought to you by:
jandecaluwe
I have been playing around with MyHDL the last couple of days. There are some things I find rather weird. One of these is the following:
In [1]: import myhdl
In [2]: a = myhdl.intbv(0)[10:]
In [3]: len(a)
Out[3]: 10
In [4]: len(a[:3])
Out[4]: 0
This seems weird, especially as using an open range (instead of an explicit 0) works fine too.
I attached a patch, which makes this work as I expected it:
len(a[:3]) == 7
Slicing refers to bits of the underlying integer value, regardless of bounds. It is then logical that an open upper bound means "all" the bits (an infinite number). len() == 0 means "undefined". "None" might be better but I think this was convenient at some point.
Last edit: Jan Decaluwe 2013-09-15