diff --git a/src/twopass.rs b/src/twopass.rs index 9d7e093..bf6692c 100644 --- a/src/twopass.rs +++ b/src/twopass.rs @@ -131,6 +131,22 @@ fn build_expression(scope: &BuildContext<'_>, code: &ast::Expression) -> Express todo!() } +fn build_call(scope: &BuildContext<'_>, code: &ast::Call) -> Call { + Call { + callee: Box::new(build_expression( + &scope, + &ast::Expression::Variable(ast::Location::Variable { + name: code.callee.clone(), + }), + )), + args: code + .args + .iter() + .map(|arg| build_expression(&scope, arg)) + .collect(), + } +} + fn build_in_scope(parent: &BuildContext<'_>, code: &ast::Function) -> Function { let scope = BuildContext { parent: Some(parent), @@ -149,19 +165,8 @@ fn build_in_scope(parent: &BuildContext<'_>, code: &ast::Function) -> Function { source: Box::new(build_expression(&scope, source)), }); } - ast::Statement::Call(ast::Call { callee, args }) => { - body.push(Statement::Call(Call { - callee: Box::new(build_expression( - &scope, - &ast::Expression::Variable(ast::Location::Variable { - name: callee.clone(), - }), - )), - args: args - .iter() - .map(|arg| build_expression(&scope, arg)) - .collect(), - })); + ast::Statement::Call(call) => { + body.push(Statement::Call(build_call(&scope, call))); } ast::Statement::Local { name, init } => { let init = init.as_ref().map(|init| build_expression(&scope, &init));