Assembler passes up to label placement

This commit is contained in:
2022-03-27 23:10:08 -05:00
parent 987df5fb45
commit 0dcb5dd3a5
6 changed files with 496 additions and 59 deletions
+15 -1
View File
@@ -25,7 +25,7 @@ pub enum Node<'a> {
Expr(Box<Node<'a>>, Vec<(Operator, Node<'a>)>),
}
#[derive(Debug, PartialEq, Clone)]
#[derive(Debug, PartialEq, Copy, Clone)]
pub struct Label<'a>(pub &'a str);
impl<'a> Display for Label<'a> {
@@ -43,3 +43,17 @@ pub enum VASMLine<'a> {
Equ(Label<'a>, Node<'a>),
LabelDef(Label<'a>),
}
impl<'a> VASMLine<'a> {
pub fn label(&self) -> Option<Label<'a>> {
match self {
VASMLine::Instruction(Some(lbl), _, _)
| VASMLine::Db(Some(lbl), _)
| VASMLine::StringDb(Some(lbl), _)
| VASMLine::Org(Some(lbl), _)
| VASMLine::Equ(lbl, _)
| VASMLine::LabelDef(lbl) => Some(*lbl),
_ => None,
}
}
}