From 03e8673b6f9bf1bf3c5a14d10f4c8bc40885b175 Mon Sep 17 00:00:00 2001 From: numzero Date: Sat, 19 Apr 2025 12:36:29 +0300 Subject: [PATCH] extract build_call --- src/twopass.rs | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) 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));