From: whitequark Date: Tue, 25 Jun 2019 21:52:03 +0000 (+0000) Subject: compat.fhdl.structure: simplify handling of default case. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=4049531e6abc7753992341e4644138749f98d7a0;p=nmigen.git compat.fhdl.structure: simplify handling of default case. --- diff --git a/nmigen/compat/fhdl/structure.py b/nmigen/compat/fhdl/structure.py index 0a58d74..4a99195 100644 --- a/nmigen/compat/fhdl/structure.py +++ b/nmigen/compat/fhdl/structure.py @@ -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