Don't use recursion in evaluate :(
This commit is contained in:
parent
d94ff158f7
commit
f5d999a3dd
|
@ -28,15 +28,14 @@ def evaluate(expr: Expression) -> Expression:
|
||||||
>>> evaluate(Application((funktion, Int(0))))
|
>>> evaluate(Application((funktion, Int(0))))
|
||||||
1312
|
1312
|
||||||
"""
|
"""
|
||||||
if expr.is_value():
|
while not expr.is_value():
|
||||||
return expr
|
|
||||||
else:
|
|
||||||
match expr.step():
|
match expr.step():
|
||||||
case Some(next):
|
case Some(next):
|
||||||
return evaluate(next)
|
expr = next
|
||||||
|
# Loop
|
||||||
case None:
|
case None:
|
||||||
raise AssertionError('Evaluate called on a value which cannot step:', expr)
|
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)):
|
def repl_expr(expr: Expression, bindings: ReplHole = ReplHole(BUILTINS_CONTEXT)):
|
||||||
expr_subst = subst_all(bindings.val_bindings, expr)
|
expr_subst = subst_all(bindings.val_bindings, expr)
|
||||||
|
|
Loading…
Reference in a new issue