diff options
Diffstat (limited to 'lib/xixanta')
| -rw-r--r-- | lib/xixanta/src/assembler.rs | 40 |
1 files changed, 8 insertions, 32 deletions
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)?; } } @@ -2689,37 +2696,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()); asm.mappings[0].segments[0].bundles = minimal_header(); |
