aboutsummaryrefslogtreecommitdiff
path: root/lib/xixanta/src/object.rs
diff options
context:
space:
mode:
authorMiquel Sabaté Solà <mikisabate@gmail.com>2025-08-18 17:06:47 +0200
committerMiquel Sabaté Solà <mikisabate@gmail.com>2025-08-18 17:06:47 +0200
commitfe811ed479363da1fbca171fd0b16adeba5f6476 (patch)
tree287b33223e9fb7d9c321edbe724710ce6b7848ea /lib/xixanta/src/object.rs
parentfb0f163ba1f870158410a3851740101ecdc9d3ff (diff)
downloadtools.nes-fe811ed479363da1fbca171fd0b16adeba5f6476.tar.gz
tools.nes-fe811ed479363da1fbca171fd0b16adeba5f6476.zip
Provide a node to the Object struct
This allows the `evaluate_variable` to pull from it in the crunching stage so to evaluate the original node in cases like macro expansion, where the connection between the macro argument and the original caller might have been lost. Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
Diffstat (limited to 'lib/xixanta/src/object.rs')
-rw-r--r--lib/xixanta/src/object.rs16
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/xixanta/src/object.rs b/lib/xixanta/src/object.rs
index db7c51e..373d06c 100644
--- a/lib/xixanta/src/object.rs
+++ b/lib/xixanta/src/object.rs
@@ -48,6 +48,16 @@ impl Bundle {
}
}
+ /// Returns true of this bundle has a zero value on its `bytes` attribute
+ /// while also taking into account the size of the bundle.
+ pub fn is_zero(&self) -> bool {
+ match self.size {
+ 1 => self.bytes[0] == 0,
+ 2 => self.bytes[0] == 0 && self.bytes[1] == 0,
+ _ => self.bytes[0] == 0 && self.bytes[1] == 0 && self.bytes[2] == 0,
+ }
+ }
+
/// Create a bundle tailored for filling purposes.
pub fn fill(value: u8) -> Self {
Self {
@@ -105,6 +115,11 @@ pub struct Object {
/// Bundle representing the actual value.
pub bundle: Bundle,
+ /// Node which marks the source of the computed `bundle` attribute. This is
+ /// only provided in cases like macro calls where at the crunching stage we
+ /// might need to fetch previous context for the current `bundle` value.
+ pub node: Option<PNode>,
+
/// The mapping index where the object was found. Note that this index
/// doesn't mean much on the table, but it has to mean something by the
/// caller.
@@ -124,6 +139,7 @@ impl Object {
pub fn new(mapping: usize, segment: usize, object_type: ObjectType) -> Self {
Self {
bundle: Bundle::default(),
+ node: None,
mapping,
segment,
object_type,