aboutsummaryrefslogtreecommitdiff
path: root/lib/xixanta/src/assembler.rs
diff options
context:
space:
mode:
authorMiquel Sabaté Solà <mikisabate@gmail.com>2024-12-20 10:52:27 +0100
committerMiquel Sabaté Solà <mikisabate@gmail.com>2024-12-20 10:52:27 +0100
commit35256904c49a961fbaebbd134539516725c53455 (patch)
treea58244ae645274683fc85f6eb18a2ff0812b23dc /lib/xixanta/src/assembler.rs
parentef8c89a71899249c8146da76692494e95e6cbd88 (diff)
downloadtools.nes-35256904c49a961fbaebbd134539516725c53455.tar.gz
tools.nes-35256904c49a961fbaebbd134539516725c53455.zip
Find variable values on parent scopes
If a given variable cannot be found on the current scope, attempt to go up the context hierarchy to find it. Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
Diffstat (limited to 'lib/xixanta/src/assembler.rs')
-rw-r--r--lib/xixanta/src/assembler.rs34
1 files changed, 34 insertions, 0 deletions
diff --git a/lib/xixanta/src/assembler.rs b/lib/xixanta/src/assembler.rs
index 4e33d66..888e122 100644
--- a/lib/xixanta/src/assembler.rs
+++ b/lib/xixanta/src/assembler.rs
@@ -1775,6 +1775,40 @@ adc Variable
}
#[test]
+ fn reference_outer_variables() {
+ 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#"
+foo:
+ rts
+
+.proc inner
+ jsr foo
+.endproc
+"#
+ .as_bytes(),
+ )
+ .unwrap()[0x10..];
+
+ assert_eq!(res.len(), 2);
+
+ // foo: rts
+ assert_eq!(res[0].size, 1);
+ assert_eq!(res[0].bytes[0], 0x60);
+
+ // inner: jsr foo
+ assert_eq!(res[1].size, 3);
+ assert_eq!(res[1].bytes[0], 0x20);
+ assert_eq!(res[1].bytes[1], 0x00);
+ assert_eq!(res[1].bytes[2], 0x80);
+ }
+
+ #[test]
fn bad_variable_but_valid_identifier_in_instruction() {
assert_eval_error(
"adc Variable",