selectable_int: support slicing by iterable
authorDmitry Selyutin <ghostmansd@gmail.com>
Tue, 30 Aug 2022 08:47:16 +0000 (11:47 +0300)
committerDmitry Selyutin <ghostmansd@gmail.com>
Tue, 30 Aug 2022 10:02:21 +0000 (13:02 +0300)
src/openpower/decoder/selectable_int.py

index 36d30689c5dfe55a8c2396bf512f2b34f41cb8cb..55f5e6c824a8cb8ce52d56403897972e3c34f3b8 100644 (file)
@@ -385,7 +385,13 @@ class SelectableInt:
             log("getitem", stop, start, self.bits, hex(self.value), value)
             return SelectableInt(value, bits)
         else:
-            raise ValueError(value)
+            bits = []
+            key = tuple(key)
+            for bit in key:
+                if not isinstance(bit, (int, SelectableInt)):
+                    raise ValueError(key)
+                bits.append(self[bit])
+            return selectconcat(*bits)
 
     def __setitem__(self, key, value):
         if isinstance(key, SelectableInt):