compat.fhdl.structure: simplify handling of default case.
authorwhitequark <whitequark@whitequark.org>
Tue, 25 Jun 2019 21:52:03 +0000 (21:52 +0000)
committerwhitequark <whitequark@whitequark.org>
Tue, 25 Jun 2019 22:01:14 +0000 (22:01 +0000)
nmigen/compat/fhdl/structure.py

index 0a58d743aec80e16f3178040ddd1b8063adc7806..4a99195a24321abe32d676b1b68dc2d02a7a38fa 100644 (file)
@@ -92,8 +92,7 @@ class Case(ast.Switch):
                 k = k.value
             new_cases.append((k, v))
         if default is not None:
-            k = "-" * len(ast.Value.wrap(test))
-            new_cases.append((k, default))
+            new_cases.append((None, default))
         super().__init__(test, OrderedDict(new_cases))
 
     @deprecated("instead of `Case(...).makedefault()`, use an explicit default case: "
@@ -106,12 +105,12 @@ class Case(ast.Switch):
                         or choice > key):
                     key = choice
         elif isinstance(key, str) and key == "default":
-            key = "-" * len(self.test)
+            key = None
         else:
             key = "{:0{}b}".format(wrap(key).value, len(self.test))
         stmts = self.cases[key]
         del self.cases[key]
-        self.cases["-" * len(self.test)] = stmts
+        self.cases[None] = stmts
         return self