parent
fcbc8bd46f
commit
c7984463c7
|
@ -117,9 +117,9 @@ class Shape:
|
||||||
elif isinstance(obj, range):
|
elif isinstance(obj, range):
|
||||||
if len(obj) == 0:
|
if len(obj) == 0:
|
||||||
return Shape(0, obj.start < 0)
|
return Shape(0, obj.start < 0)
|
||||||
signed = obj.start < 0 or (obj.stop - obj.step) < 0
|
signed = obj[0] < 0 or obj[-1] < 0
|
||||||
width = max(bits_for(obj.start, signed),
|
width = max(bits_for(obj[0], signed),
|
||||||
bits_for(obj.stop - obj.step, signed))
|
bits_for(obj[-1], signed))
|
||||||
return Shape(width, signed)
|
return Shape(width, signed)
|
||||||
elif isinstance(obj, type) and issubclass(obj, Enum):
|
elif isinstance(obj, type) and issubclass(obj, Enum):
|
||||||
# For compatibility with third party enumerations, handle them as if they were
|
# For compatibility with third party enumerations, handle them as if they were
|
||||||
|
|
|
@ -117,6 +117,9 @@ class ShapeTestCase(FHDLTestCase):
|
||||||
s7 = Shape.cast(range(-1, -1))
|
s7 = Shape.cast(range(-1, -1))
|
||||||
self.assertEqual(s7.width, 0)
|
self.assertEqual(s7.width, 0)
|
||||||
self.assertEqual(s7.signed, True)
|
self.assertEqual(s7.signed, True)
|
||||||
|
s8 = Shape.cast(range(0, 10, 3))
|
||||||
|
self.assertEqual(s8.width, 4)
|
||||||
|
self.assertEqual(s8.signed, False)
|
||||||
|
|
||||||
def test_cast_enum(self):
|
def test_cast_enum(self):
|
||||||
s1 = Shape.cast(UnsignedEnum)
|
s1 = Shape.cast(UnsignedEnum)
|
||||||
|
|
Loading…
Reference in a new issue