sim._pyrtl: don't blow parser stack on older Pythons.

Python pre-3.9 can't handle parentheses nested this deeply.

* https://github.com/amaranth-lang/amaranth/pull/681 -- motivating
  example.
* https://github.com/amaranth-lang/amaranth/pull/827 -- what added
  enough extra parentheses to make this only break now.
* https://peps.python.org/pep-0617/ -- new parser as of 3.9.
This commit is contained in:
Charlotte 2023-06-29 11:15:31 +10:00 committed by Catherine
parent fd4e25df42
commit 60c2a1b4b8

View file

@ -83,7 +83,11 @@ class _ValueCompiler(ValueVisitor, _Compiler):
"simulate in reasonable time"
.format(src, len(value)))
return super().on_value(value)
v = super().on_value(value)
if isinstance(v, str) and len(v) > 1000:
# Avoid parser stack overflow on older Pythons.
return self.emitter.def_var("intermediate", v)
return v
def on_ClockSignal(self, value):
raise NotImplementedError # :nocov: