More macro WIP

This commit is contained in:
2022-04-07 17:45:34 -05:00
parent dec2d22b80
commit ac01eb527e
+51 -2
View File
@@ -61,6 +61,15 @@ enum LoopType {
Until, Until,
} }
impl From<Macro> for LoopType {
fn from(mac: Macro) -> Self {
match mac {
Macro::While => LoopType::While,
Macro::Until => LoopType::Until,
_ => unreachable!()
}
}
}
#[derive(Debug, Clone, PartialEq)] #[derive(Debug, Clone, PartialEq)]
enum ControlStructure { enum ControlStructure {
Target(String), Target(String),
@@ -130,8 +139,16 @@ where
return Err(AssembleError::MacroError(line_idx + 1)); return Err(AssembleError::MacroError(line_idx + 1));
} }
} }
Macro::While => {} Macro::While |
Macro::Until => {} Macro::Until => {
let label = gensym();
control_stack.push(ControlStructure::Loop(label.clone(), mac.into()));
all_lines.push(Line {
line: VASMLine::LabelDef(Label(label)),
line_num: line_idx + 1,
file: filename_stack.last().unwrap().clone(),
})
}
Macro::Do => {} Macro::Do => {}
Macro::End => {} Macro::End => {}
}, },
@@ -665,4 +682,36 @@ mod test {
]) ])
) )
} }
#[test]
fn test_preprocess_while() {
let include = |_name: String| Ok(vec![]);
let lines = vec!["#while"];
assert_eq!(
preprocess(lines, "blah".to_string(), &include),
Ok(vec![
Line {
line_num: 1,
file: "blah".to_string(),
line: VASMLine::LabelDef(Label("__gensym_1".to_string()))
}
])
)
}
#[test]
fn test_preprocess_until() {
let include = |_name: String| Ok(vec![]);
let lines = vec!["#until"];
assert_eq!(
preprocess(lines, "blah".to_string(), &include),
Ok(vec![
Line {
line_num: 1,
file: "blah".to_string(),
line: VASMLine::LabelDef(Label("__gensym_1".to_string()))
}
])
)
}
} }