diff --git a/migen/fhdl/structure.py b/migen/fhdl/structure.py index 8052fdffb..350670fc5 100644 --- a/migen/fhdl/structure.py +++ b/migen/fhdl/structure.py @@ -89,10 +89,16 @@ class Value(HUID): def __getitem__(self, key): if isinstance(key, int): + if (key < 0): + key += len(self) return _Slice(self, key, key+1) elif isinstance(key, slice): start = key.start or 0 stop = key.stop or len(self) + if (start < 0): + start += len(self) + if (stop < 0): + stop += len(self) if stop > len(self): stop = len(self) if key.step != None: