diff options
| author | Miquel Sabaté Solà <mikisabate@gmail.com> | 2024-12-20 11:08:42 +0100 |
|---|---|---|
| committer | Miquel Sabaté Solà <mikisabate@gmail.com> | 2024-12-20 11:08:42 +0100 |
| commit | d1a67b53c0ba04325fa724286ab9008e6a193c5e (patch) | |
| tree | 263c610df99e59d76b1ec42dc380d23459c81115 /lib/xixanta | |
| parent | 35256904c49a961fbaebbd134539516725c53455 (diff) | |
| download | tools.nes-d1a67b53c0ba04325fa724286ab9008e6a193c5e.tar.gz tools.nes-d1a67b53c0ba04325fa724286ab9008e6a193c5e.zip | |
Expect macros to overwrite parameter values
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à <mikisabate@gmail.com>
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(); |
