From ead34058aff63aa6b58c7378e7975d5285feca24 Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Thu, 19 Dec 2024 15:38:26 +0100 Subject: parser: Add support for operators MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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à --- lib/xixanta/src/node.rs | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'lib/xixanta/src/node.rs') 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"), + }, } } } -- cgit v1.2.3