Website Summary Files Commits Branches @commit @diff @stats
path: root / assembler / src / parser / instruction.rs
blob: 8c8e8aa10aabcb6680a362f3f99426cca2341629 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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) -> Vec<Instruction> {
        self.name = self.name.to_lowercase();
        static Z: Address = Address::Memory(0);

        match &*self.name {
            "subleq" | "add" | "mult" => vec![self.clone()],
            "jmp" => vec![
                Instruction::new_subleq(&Z, &Z, &self.args[0]),
            ],
            _ => panic!("Unknown instruction {}!", self.name),
        }
    }
}