Don't use recursion in evaluate :(

This commit is contained in:
Emi Simpson 2023-03-10 08:53:39 -05:00
parent d94ff158f7
commit f5d999a3dd
Signed by: Emi
GPG Key ID: A12F2C2FFDC3D847
1 changed files with 4 additions and 5 deletions

View File

@ -28,15 +28,14 @@ def evaluate(expr: Expression) -> Expression:
>>> evaluate(Application((funktion, Int(0))))
1312
"""
if expr.is_value():
return expr
else:
while not expr.is_value():
match expr.step():
case Some(next):
return evaluate(next)
expr = next
# Loop
case None:
raise AssertionError('Evaluate called on a value which cannot step:', expr)
raise Exception('Unreachable')
return expr
def repl_expr(expr: Expression, bindings: ReplHole = ReplHole(BUILTINS_CONTEXT)):
expr_subst = subst_all(bindings.val_bindings, expr)