allow int in addition and subtraction
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Sat, 4 Apr 2020 16:15:17 +0000 (17:15 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Sat, 4 Apr 2020 16:15:17 +0000 (17:15 +0100)
src/soc/decoder/selectable_int.py

index b8998b89a7c32059fdb44436b24ecfe79c8ebfb5..1dd415117f5ffd1f0ed14e8ae32c4b05d13253d3 100644 (file)
@@ -9,10 +9,14 @@ class SelectableInt:
         self.bits = bits
 
     def __add__(self, b):
+        if isinstance(b, int):
+            b = SelectableInt(b, self.bits)
         assert b.bits == self.bits
         return SelectableInt(self.value + b.value, self.bits)
 
     def __sub__(self, b):
+        if isinstance(b, int):
+            b = SelectableInt(b, self.bits)
         assert b.bits == self.bits
         return SelectableInt(self.value - b.value, self.bits)