Skip to content

Commit

Permalink
Expect macros to overwrite parameter values
Browse files Browse the repository at this point in the history
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à <[email protected]>
  • Loading branch information
mssola committed Dec 20, 2024
1 parent 3525690 commit d1a67b5
Showing 1 changed file with 8 additions and 32 deletions.
40 changes: 8 additions & 32 deletions lib/xixanta/src/assembler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
}
}

Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit d1a67b5

Please sign in to comment.