From d1a67b53c0ba04325fa724286ab9008e6a193c5e Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Fri, 20 Dec 2024 11:08:42 +0100 Subject: Expect macros to overwrite parameter values MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is normal when calling the same macro multiple times and in which parameter values need to be updated on each case. Signed-off-by: Miquel Sabaté Solà --- lib/xixanta/src/assembler.rs | 40 ++++++++-------------------------------- 1 file changed, 8 insertions(+), 32 deletions(-) (limited to 'lib') diff --git a/lib/xixanta/src/assembler.rs b/lib/xixanta/src/assembler.rs index 888e122..6b35f1d 100644 --- a/lib/xixanta/src/assembler.rs +++ b/lib/xixanta/src/assembler.rs @@ -487,8 +487,15 @@ impl Assembler { segment: self.current_segment, object_type: ObjectType::Value, }; + + // Note that we overwrite the variable value from previous + // calls, just in case a macro is applied multiple times and we + // need to get the latest value. + // + // TODO: whenever warnings are available, warn on shadowing + // outer variables. self.context - .set_variable(margs.next().unwrap(), &obj, false)?; + .set_variable(margs.next().unwrap(), &obj, true)?; } } @@ -2688,37 +2695,6 @@ MACRO(1) ); } - #[test] - fn macro_shadow_argument() { - let mut asm = Assembler::new(EMPTY.to_vec()); - 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#" -Var = 3 -lda #42 - -.macro MACRO(Var) - lda #Va -.endmacro - -lda #1 -MACRO(1) -"# - .as_bytes(), - ) - .unwrap_err(); - - assert_eq!( - res.first().unwrap().to_string(), - "Evaluation error (line 5): 'Var' already defined in the global scope: \ - you cannot re-assign names." - ); - } - #[test] fn macro_multiple_arguments() { let mut asm = Assembler::new(EMPTY.to_vec()); -- cgit v1.2.3