Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lwhile interpreter exceeds RecursionLimit #22

Open
waynee95 opened this issue Jul 14, 2023 · 1 comment
Open

Lwhile interpreter exceeds RecursionLimit #22

waynee95 opened this issue Jul 14, 2023 · 1 comment

Comments

@waynee95
Copy link

Might not be that big of an issue but running InterpLwhile().interp(prog) on a program that has nested loops seems to cause a RecursionLimit exception rather quickly.

class InterpLwhile(InterpLif):

  def interp_stmt(self, s, env, cont):
    match s:
      case While(test, body, []):
        if self.interp_exp(test, env):
            self.interp_stmts(body + [s] + cont, env)
        else:
          return self.interp_stmts(cont, env)
      case _:
        return super().interp_stmt(s, env, cont)

if __name__ == '__main__':

  prog="""
x = 50
while x > 0:
    y = 2
    while y != 0:
        y = y - 1
    x = x - 1
print(x)
"""

  InterpLwhile().interp(parse(prog))

The above example does not work without using sys.setrecursionlimit(...).

@taimoon
Copy link

taimoon commented Sep 10, 2023

To avoid recursion limit, this particular block has to be rewrite using python iterative construct, or enable tail-call optimization.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants