use crate::asm::asm_instruction::{ AsmInstruction, InvokePlatformStatic, LoadConstant, Operand, Push, }; use crate::ir::assemble_context::AssembleContext; use crate::ir::ir_constant::IrConstant; use crate::ir::ir_expression::IrExpression; #[derive(Debug)] pub struct IrCall { name: String, arguments: Vec, } impl IrCall { pub fn new(name: &str, arguments: Vec) -> Self { Self { name: name.into(), arguments, } } pub fn assemble(&self, context: &mut AssembleContext) -> Vec { let mut instructions = vec![]; for argument in &self.arguments { match argument { IrExpression::Call(ir_call) => { instructions.append(&mut ir_call.assemble(context)); } IrExpression::Constant(ir_constant) => { match ir_constant { IrConstant::String(string_constant) => { instructions.push(AsmInstruction::LoadConstant(LoadConstant::new( string_constant.name(), 0, ))); } } instructions.push(AsmInstruction::Push(Push::new(Operand::Register(0)))) } IrExpression::IntegerLiteral(i) => { instructions.push(AsmInstruction::Push(Push::new(Operand::IntegerLiteral(*i)))); } IrExpression::Variable(ir_variable) => instructions.push(AsmInstruction::Push( Push::new(Operand::Register(ir_variable.register())), )), } } instructions.push(AsmInstruction::InvokePlatformStatic( InvokePlatformStatic::new(&self.name, todo!()), )); instructions } }