extract build_call

This commit is contained in:
numzero 2025-04-19 12:36:29 +03:00
parent 38659d86aa
commit 03e8673b6f

View File

@ -131,6 +131,22 @@ fn build_expression(scope: &BuildContext<'_>, code: &ast::Expression) -> Express
todo!() 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 { fn build_in_scope(parent: &BuildContext<'_>, code: &ast::Function) -> Function {
let scope = BuildContext { let scope = BuildContext {
parent: Some(parent), parent: Some(parent),
@ -149,19 +165,8 @@ fn build_in_scope(parent: &BuildContext<'_>, code: &ast::Function) -> Function {
source: Box::new(build_expression(&scope, source)), source: Box::new(build_expression(&scope, source)),
}); });
} }
ast::Statement::Call(ast::Call { callee, args }) => { ast::Statement::Call(call) => {
body.push(Statement::Call(Call { body.push(Statement::Call(build_call(&scope, 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::Local { name, init } => { ast::Statement::Local { name, init } => {
let init = init.as_ref().map(|init| build_expression(&scope, &init)); let init = init.as_ref().map(|init| build_expression(&scope, &init));