summaryrefslogtreecommitdiff
path: root/src/semantic/temp.rs
blob: abd7e8603709de989e0997046024cbf58e3a6b38 (plain)
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
pub struct Temp {
    counter: usize,
}

#[derive(Copy,Clone,Debug,Eq,PartialEq)]
pub struct TempName(usize);
#[derive(Copy,Clone,Debug,Eq,PartialEq)]
pub struct TempLabel(usize);

impl Temp {
    pub fn new() -> Temp {
        Temp { counter: 0 }
    }

    pub fn next_name(&mut self) -> TempName {
        let idx = self.counter;
        self.counter += 1;
        TempName(idx)
    }

    pub fn next_label(&mut self) -> TempLabel {
        let idx = self.counter;
        self.counter += 1;
        TempLabel(idx)
    }
}