aboutsummaryrefslogtreecommitdiff
path: root/lib/xixanta
diff options
context:
space:
mode:
Diffstat (limited to 'lib/xixanta')
-rw-r--r--lib/xixanta/src/assembler.rs37
1 files changed, 37 insertions, 0 deletions
diff --git a/lib/xixanta/src/assembler.rs b/lib/xixanta/src/assembler.rs
index ba06abe..dec8aa3 100644
--- a/lib/xixanta/src/assembler.rs
+++ b/lib/xixanta/src/assembler.rs
@@ -176,6 +176,19 @@ impl Assembler {
// right now as we don't know the segment size where it belongs
// yet.
NodeType::Label => {
+ // There's no good reason to declare a named label inside of
+ // a macro. If that's the case, just error out.
+ if macro_seen > 0 && !node.value.is_empty() {
+ errors.push(Error::Eval(EvalError {
+ line: node.value.line,
+ message: format!(
+ "using a named label ('{}') inside of a macro definition",
+ node.value.value
+ ),
+ global: false,
+ }));
+ continue;
+ }
if let Err(err) = self.define_variable(&node.value) {
errors.push(Error::Context(err));
}
@@ -3113,6 +3126,30 @@ WRITE_PPU_DATA $20B9, $04
);
}
+ #[test]
+ fn error_on_named_label_inside_macro() {
+ let mut asm = Assembler::new(empty());
+ asm.mappings[0].segments[0].bundles = minimal_header();
+ asm.mappings[0].offset = 6;
+ asm.current_mapping = 1;
+ let res = &asm
+ .assemble(
+ std::env::current_dir().unwrap().to_path_buf(),
+ r#".macro MACRO
+@label:
+ jmp @label
+.endmacro
+"#
+ .as_bytes(),
+ )
+ .unwrap_err();
+
+ assert_eq!(
+ res.first().unwrap().to_string(),
+ "using a named label ('@label') inside of a macro definition (line 2)"
+ );
+ }
+
// Segments
#[test]