use crate::instruction::Instruction; use std::fmt::Display; use std::rc::Rc; pub struct Function { name: Rc, parameter_count: usize, stack_size: isize, instructions: Vec, } impl Function { pub fn new( name: Rc, parameter_count: usize, stack_size: isize, instructions: Vec, ) -> Self { Self { name, parameter_count, stack_size, instructions, } } pub fn name(&self) -> &str { &self.name } pub fn name_owned(&self) -> Rc { self.name.clone() } pub fn parameter_count(&self) -> usize { self.parameter_count } pub fn stack_size(&self) -> isize { self.stack_size } pub fn instructions(&self) -> &Vec { &self.instructions } } impl Display for Function { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { writeln!(f, "fn {}", self.name)?; for instruction in &self.instructions { writeln!(f, " {}", instruction)?; } Ok(()) } }