mirror of
https://github.com/enjoy-digital/litex.git
synced 2025-01-04 09:52:26 -05:00
Signal.__getitem__: raise TypeError and IndexError when appropriate
This commit is contained in:
parent
b3d69913cd
commit
6036fffef2
1 changed files with 6 additions and 3 deletions
|
@ -81,17 +81,20 @@ class Value(HUID):
|
||||||
def __getitem__(self, key):
|
def __getitem__(self, key):
|
||||||
from migen.fhdl.bitcontainer import flen
|
from migen.fhdl.bitcontainer import flen
|
||||||
|
|
||||||
|
n = flen(self)
|
||||||
if isinstance(key, int):
|
if isinstance(key, int):
|
||||||
|
if key >= n:
|
||||||
|
raise IndexError
|
||||||
if key < 0:
|
if key < 0:
|
||||||
key += flen(self)
|
key += n
|
||||||
return _Slice(self, key, key+1)
|
return _Slice(self, key, key+1)
|
||||||
elif isinstance(key, slice):
|
elif isinstance(key, slice):
|
||||||
start, stop, step = key.indices(flen(self))
|
start, stop, step = key.indices(n)
|
||||||
if step != 1:
|
if step != 1:
|
||||||
return Cat(self[i] for i in range(start, stop, step))
|
return Cat(self[i] for i in range(start, stop, step))
|
||||||
return _Slice(self, start, stop)
|
return _Slice(self, start, stop)
|
||||||
else:
|
else:
|
||||||
raise KeyError
|
raise TypeError
|
||||||
|
|
||||||
def eq(self, r):
|
def eq(self, r):
|
||||||
"""Assignment
|
"""Assignment
|
||||||
|
|
Loading…
Reference in a new issue