Skip to content

Commit

Permalink
Move recursion check up
Browse files Browse the repository at this point in the history
  • Loading branch information
kvnxiao committed Jul 19, 2023
1 parent 3619008 commit 46d8801
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions kalk/src/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,10 @@ pub(crate) fn eval_fn_call_expr(
expressions: &[Expr],
unit: Option<&String>,
) -> Result<KalkValue, KalkError> {
if context.recursion_depth > context.max_recursion_depth {
return Err(KalkError::StackOverflow);
}

if identifier.prime_count > 0 {
context.is_approximation = true;
}
Expand Down Expand Up @@ -515,11 +519,6 @@ pub(crate) fn eval_fn_call_expr(

match stmt_definition {
Some(Stmt::FnDecl(_, arguments, fn_body)) => {
if context.recursion_depth > context.max_recursion_depth {
return Err(KalkError::StackOverflow);
}


if arguments.len() != expressions.len() {
return Err(KalkError::IncorrectAmountOfArguments(
arguments.len(),
Expand Down

0 comments on commit 46d8801

Please sign in to comment.