From d2d6d90acf2e9a8ccb4cbcec619d2a0d49cd462a Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Tue, 29 Oct 2024 14:49:44 +0100 Subject: Don't rely on the identifier for control identity MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead, use a new enum type to identify the control statements that we actually support. This way the assembler is more easily aware on the control that it's dealing with, and can be more sure on certain aspects of the implementation on control support. Signed-off-by: Miquel Sabaté Solà --- lib/xixanta/src/node.rs | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) (limited to 'lib/xixanta/src/node.rs') diff --git a/lib/xixanta/src/node.rs b/lib/xixanta/src/node.rs index a28d625..c787394 100644 --- a/lib/xixanta/src/node.rs +++ b/lib/xixanta/src/node.rs @@ -82,6 +82,24 @@ impl PString { } } +/// The type of control function being used. Use this enum in order to detect +/// which control function was detected instead of the node value. +#[derive(Debug, Clone, PartialEq)] +pub enum ControlType { + Hibyte, + Lobyte, + StartMacro, + EndMacro, + StartProc, + EndProc, + StartScope, + EndScope, + Segment, + Byte, + Word, + Addr, +} + /// The PNode type. #[derive(Debug, Clone, PartialEq)] pub enum NodeType { @@ -106,10 +124,12 @@ pub enum NodeType { Assignment, /// A control statement (e.g. ".proc foo"). The `value` string contains the - /// name of the function, the `left` an optional identifier (e.g. the "foo" - /// on ".proc foo"), and the `args` contain any possible arguments that have - /// been passed to this control statement. - Control, + /// name of the function as it was provided (use the `ControlType` value of + /// the enum to detect which function was exactly provided), the `left` an + /// optional identifier (e.g. the "foo" on ".proc foo"), and the `args` + /// contain any possible arguments that have been passed to this control + /// statement. + Control(ControlType), /// A literal expression, that is, something that starts with '#', '%' or /// '$'. The `left` node contains the inner expression. @@ -130,7 +150,7 @@ impl fmt::Display for NodeType { NodeType::Instruction => write!(f, "instruction"), NodeType::Indirection => write!(f, "indirection"), NodeType::Assignment => write!(f, "assignment"), - NodeType::Control => write!(f, "control function"), + NodeType::Control(_) => write!(f, "control function"), NodeType::Literal => write!(f, "literal"), NodeType::Label => write!(f, "label"), NodeType::Call => write!(f, "call"), -- cgit v1.2.3