cas_compiler/expr/
call.rs1use cas_error::Error;
2use cas_parser::parser::ast::call::Call;
3use crate::{Compile, Compiler, InstructionKind};
4
5impl Compile for Call {
6 fn compile(&self, compiler: &mut Compiler) -> Result<(), Error> {
7 self.args.iter().try_for_each(|arg| arg.compile(compiler))?;
8
9 let symbol_id = compiler.resolve_symbol(&self.name)?;
12 compiler.add_instr_with_spans(
13 InstructionKind::LoadVar(symbol_id),
14 vec![self.name.span.clone()],
15 );
16
17 let spans = self.outer_span()
18 .into_iter()
19 .chain(self.args.iter().map(|arg| arg.span()))
20 .collect();
21
22 if self.derivatives > 0 {
23 compiler.add_instr_with_spans(
25 InstructionKind::CallDerivative(self.derivatives, self.args.len()),
26 spans,
27 );
28 } else {
29 compiler.add_instr_with_spans(InstructionKind::Call(self.args.len()), spans);
31 }
32
33 Ok(())
34 }
35}