aboutsummaryrefslogtreecommitdiff
path: root/lib/xixanta/src/node.rs
diff options
context:
space:
mode:
authorMiquel Sabaté Solà <mikisabate@gmail.com>2024-12-19 15:38:26 +0100
committerMiquel Sabaté Solà <mikisabate@gmail.com>2024-12-19 23:12:30 +0100
commitead34058aff63aa6b58c7378e7975d5285feca24 (patch)
tree009e4fd3145bb1d77e736688ca40dab328952257 /lib/xixanta/src/node.rs
parentfee47f49f1451a078236802f6292fb8fd70fb782 (diff)
downloadtools.nes-ead34058aff63aa6b58c7378e7975d5285feca24.tar.gz
tools.nes-ead34058aff63aa6b58c7378e7975d5285feca24.zip
parser: Add support for operators
This includes support for both binary and unary operators. Not all of them as listed by ca65 have been moved in. Let's do that whenever it make sense on each case. Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
Diffstat (limited to 'lib/xixanta/src/node.rs')
-rw-r--r--lib/xixanta/src/node.rs39
1 files changed, 39 insertions, 0 deletions
diff --git a/lib/xixanta/src/node.rs b/lib/xixanta/src/node.rs
index abc38a1..f6f3d09 100644
--- a/lib/xixanta/src/node.rs
+++ b/lib/xixanta/src/node.rs
@@ -140,6 +140,25 @@ pub enum ControlType {
IncBin,
}
+/// The type of operation being used.
+#[derive(Debug, Clone, PartialEq)]
+pub enum OperationType {
+ Add,
+ Sub,
+ Mul,
+ Div,
+ Lshift,
+ Rshift,
+ And,
+ Or,
+ Xor,
+ UnaryPositive,
+ UnaryNegative,
+ BitwiseNot,
+ LoByte,
+ HiByte,
+}
+
/// The PNode type.
#[derive(Debug, Clone, PartialEq)]
pub enum NodeType {
@@ -181,6 +200,10 @@ pub enum NodeType {
/// A macro call. Note that a Value might also encode this, but when a Call
/// has been detected, then there is no doubt on it.
Call,
+
+ /// A operation expression. If the operation has two sides, then the left
+ /// and right arms contain the operands, otherwise only the right one.
+ Operation(OperationType),
}
impl fmt::Display for NodeType {
@@ -194,6 +217,22 @@ impl fmt::Display for NodeType {
NodeType::Literal => write!(f, "literal"),
NodeType::Label => write!(f, "label"),
NodeType::Call => write!(f, "call"),
+ NodeType::Operation(op) => match op {
+ OperationType::Add => write!(f, "addition"),
+ OperationType::Sub => write!(f, "subtraction"),
+ OperationType::Mul => write!(f, "multiplication"),
+ OperationType::Div => write!(f, "division"),
+ OperationType::Lshift => write!(f, "left shift"),
+ OperationType::Rshift => write!(f, "right shift"),
+ OperationType::And => write!(f, "bitwise and"),
+ OperationType::Or => write!(f, "bitwise or"),
+ OperationType::Xor => write!(f, "bitwise xor"),
+ OperationType::UnaryPositive => write!(f, "unary positive"),
+ OperationType::UnaryNegative => write!(f, "unary negative"),
+ OperationType::BitwiseNot => write!(f, "bitwise not"),
+ OperationType::LoByte => write!(f, "low byte"),
+ OperationType::HiByte => write!(f, "high byte"),
+ },
}
}
}