use super::{ Instruction, Address }; impl Instruction { fn new_subleq(a: &Address, b: &Address, c: &Address) -> Instruction { Instruction { name: "subleq".to_string(), args: vec![a.clone(), b.clone(), c.clone()], } } pub(crate) fn collapse(&mut self, next: usize) -> Vec { self.name = self.name.to_lowercase(); static Z: Address = Address::Memory(0); match &*self.name { "subleq" => vec![self.clone()], "jmp" => vec![ Instruction::new_subleq(&Z, &Z, &self.args[0]), ], "add" => vec![ Instruction::new_subleq(&self.args[0], &Z, &Address::Instruction(next + 1)), Instruction::new_subleq(&Z, &self.args[1], &Address::Instruction(next + 2)), Instruction::new_subleq(&Z, &Z, &Address::Instruction(next + 3)), ], _ => panic!("Unknown instruction {}!", self.name), } } }