aboutsummaryrefslogtreecommitdiff
path: root/lib/xixanta/src
diff options
context:
space:
mode:
authorMiquel Sabaté Solà <mssola@mssola.com>2026-10-13 21:33:50 +0200
committerMiquel Sabaté Solà <mssola@mssola.com>2026-10-13 21:33:50 +0200
commit2bec57991f7c7d6acf1ae5cb92e751b9ff08cc91 (patch)
tree5f0e1b099c9a8e5ef4670ae40d0c6d06c3edc75f /lib/xixanta/src
parent91fd8313ef36e9b909a5409466f7ed06b40f1579 (diff)
downloadtools.nes-2bec57991f7c7d6acf1ae5cb92e751b9ff08cc91.tar.gz
tools.nes-2bec57991f7c7d6acf1ae5cb92e751b9ff08cc91.zip
xixanta: add Context.full_name()
Signed-off-by: Miquel Sabaté Solà <mssola@mssola.com>
Diffstat (limited to 'lib/xixanta/src')
-rw-r--r--lib/xixanta/src/assembler.rs16
-rw-r--r--lib/xixanta/src/object.rs10
2 files changed, 13 insertions, 13 deletions
diff --git a/lib/xixanta/src/assembler.rs b/lib/xixanta/src/assembler.rs
index db53e77..7a2d50b 100644
--- a/lib/xixanta/src/assembler.rs
+++ b/lib/xixanta/src/assembler.rs
@@ -985,13 +985,8 @@ impl<'a> Assembler<'a> {
// this label. This will be used on the hinting of
// the end of the data that this address might be
// pointing at.
- let context_name = self.context.name();
- let name = node.value.value.clone();
- last_label = if context_name == GLOBAL_CONTEXT {
- name.clone()
- } else {
- format!("{context_name}::{}", name)
- };
+ let name = &node.value.value;
+ last_label = self.context.full_name(name);
offset = Some(o);
byte_seen = true;
}
@@ -1088,12 +1083,7 @@ impl<'a> Assembler<'a> {
// evaluate_control_statement() call the context
// will be the right one.
- let context_name = self.context.name();
- let full_name = if context_name == GLOBAL_CONTEXT {
- self.last_proc.clone()
- } else {
- format!("{context_name}::{}", self.last_proc)
- };
+ let full_name = self.context.full_name(&self.last_proc);
if let Some(last_address) = self.last_address {
self.address_ends.insert(full_name, last_address);
}
diff --git a/lib/xixanta/src/object.rs b/lib/xixanta/src/object.rs
index 5a90a3d..36dcd89 100644
--- a/lib/xixanta/src/object.rs
+++ b/lib/xixanta/src/object.rs
@@ -548,6 +548,16 @@ impl Context {
}
}
+ /// Returns the full name of the given variable 'name'. That is, it prepends
+ /// the name of the context unless the variable resides in the global
+ /// context.
+ pub fn full_name(&self, name: &str) -> String {
+ match self.stack.last() {
+ Some(context_name) => format!("{context_name}::{name}"),
+ None => name.to_string(),
+ }
+ }
+
/// Returns true if we are in the global scope.
pub fn is_global(&self) -> bool {
self.stack.is_empty()