#[derive(Debug, Copy, Clone)]
pub struct Patch(usize);
impl Patch {
pub fn new(address: usize) -> Self { Patch(address) }
pub fn address(&self) -> usize { self.0 }
}
#[derive(Debug)]
pub struct Label {
target: Option<usize>,
patches: Vec<Patch>,
}
impl Label {
pub fn new(target: Option<usize>) -> Self {
Label {target, patches: Vec::new()}
}
pub fn target(&self) -> Option<usize> { self.target }
pub fn is_defined(&self) -> bool {
self.target().is_some()
}
pub fn push(&mut self, patch: Patch) {
self.patches.push(patch);
}
pub fn drain(&mut self) -> impl Iterator<Item=Patch> + '_ {
self.patches.drain(..)
}
}
impl Default for Label {
fn default() -> Self { Label::new(None) }
}