Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: m-labs/nmigen
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 4c582ef609bc
Choose a base ref
...
head repository: m-labs/nmigen
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 1976310bf0ed
Choose a head ref
  • 1 commit
  • 2 files changed
  • 1 contributor

Commits on Sep 22, 2019

  1. hdl.rec: fix using Enum subclass as shape if direction is specified.

    Also improves error messages.
    
    Fixes #224.
    whitequark committed Sep 22, 2019
    Copy the full SHA
    1976310 View commit details
Showing with 7 additions and 5 deletions.
  1. +4 −4 nmigen/hdl/rec.py
  2. +3 −1 nmigen/test/test_hdl_rec.py
8 changes: 4 additions & 4 deletions nmigen/hdl/rec.py
Original file line number Diff line number Diff line change
@@ -35,8 +35,6 @@ def __init__(self, fields):
if len(field) == 2:
name, shape = field
direction = DIR_NONE
if isinstance(shape, type) and issubclass(shape, Enum):
shape = _enum_shape(shape)
if isinstance(shape, list):
shape = Layout.wrap(shape)
else:
@@ -48,9 +46,11 @@ def __init__(self, fields):
if not isinstance(name, str):
raise TypeError("Field {!r} has invalid name: should be a string"
.format(field))
if isinstance(shape, type) and issubclass(shape, Enum):
shape = _enum_shape(shape)
if not isinstance(shape, (int, tuple, Layout)):
raise TypeError("Field {!r} has invalid shape: should be an int, tuple, or list "
"of fields of a nested record"
raise TypeError("Field {!r} has invalid shape: should be an int, tuple, Enum, or "
"list of fields of a nested record"
.format(field))
if name in self.fields:
raise NameError("Field {!r} has a name that is already present in the layout"
4 changes: 3 additions & 1 deletion nmigen/test/test_hdl_rec.py
Original file line number Diff line number Diff line change
@@ -36,8 +36,10 @@ def test_fields(self):
def test_enum_field(self):
layout = Layout.wrap([
("enum", UnsignedEnum),
("enum_dir", UnsignedEnum, DIR_FANOUT),
])
self.assertEqual(layout["enum"], ((2, False), DIR_NONE))
self.assertEqual(layout["enum_dir"], ((2, False), DIR_FANOUT))

def test_slice_tuple(self):
layout = Layout.wrap([
@@ -75,7 +77,7 @@ def test_wrong_direction(self):

def test_wrong_shape(self):
with self.assertRaises(TypeError,
msg="Field ('a', 'x') has invalid shape: should be an int, tuple, or "
msg="Field ('a', 'x') has invalid shape: should be an int, tuple, Enum, or "
"list of fields of a nested record"):
Layout.wrap([("a", "x")])