diff --git a/src/rt/mod.rs b/src/rt/mod.rs index eab90ef..600f069 100644 --- a/src/rt/mod.rs +++ b/src/rt/mod.rs @@ -88,9 +88,15 @@ impl Node { }, &stmt.body, ), - Node::CallExpr(_, expr) => expr.func.eval(scope)?.as_fn(|func, capture| { - exec_fn(scope, capture, &func.body, &func.params, &expr.params) - })?, + Node::CallExpr(_, expr) => { + // we don't execute the function within the callback because + // (1) that would block the mutex for way longer than necessary and + // (2) recursive function calls would cause a deadlock (ask me how i know) + let (func, mut capture) = expr.func.eval(scope)?.as_fn(|func, capture| { + (func.clone(), capture.clone()) + })?; + exec_fn(scope, &mut capture, &func.body, &func.params, &expr.params) + }, Node::ArrayExpr(pos, expr) => expr.array.eval(scope)?.as_array(|array| { expr.index.eval(scope)?.as_int(|index| { if *index >= 0 && *index < array.len() as i128 {