c64_assembler/builder/
function.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
use crate::{Function, Instructions};

#[derive(Default, Clone)]
pub struct FunctionBuilder {
    function: Function,
}

impl FunctionBuilder {
    pub fn name(&mut self, name: &str) -> &mut Self {
        self.function.name = name.to_string();
        self
    }

    pub fn doc(&mut self, documentation: &[&str]) -> &mut Self {
        for d in documentation {
            self.function.documentation.push(d.to_string());
        }
        self
    }

    pub fn instructions(&mut self, instructions: Instructions) -> &mut Self {
        self.function.instructions = instructions;
        self
    }

    pub fn build(&self) -> Function {
        self.function.clone()
    }
}