diff options
| author | Miquel Sabaté Solà <mikisabate@gmail.com> | 2024-12-24 15:36:47 +0100 |
|---|---|---|
| committer | Miquel Sabaté Solà <mikisabate@gmail.com> | 2024-12-24 15:36:47 +0100 |
| commit | 58d60e0d290ec50d7cda76e6509676f85e547c26 (patch) | |
| tree | d435b11879ea21a47acfe4237fdcfd8d0c33cc66 /lib/xixanta | |
| parent | e341a34572ac35dd913172aaf84865166adb1a3c (diff) | |
| download | tools.nes-58d60e0d290ec50d7cda76e6509676f85e547c26.tar.gz tools.nes-58d60e0d290ec50d7cda76e6509676f85e547c26.zip | |
Forbid creating named labels inside of macros
This is just prone to errors and it is confusing all around. Just
prohibit developers doing that.
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
Diffstat (limited to 'lib/xixanta')
| -rw-r--r-- | lib/xixanta/src/assembler.rs | 37 |
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] |
