From 9b5e5aa6d36a550bed84f85df8e1e46fcf9765e1 Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Tue, 24 Dec 2024 16:48:16 +0100 Subject: Add the .repeat control statement MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is a control statement which acts similarly as .proc/.macro/.scope, in which an inner block is allocated for it. Hence, all the previous work from 1f8a6becc7cd ("parser: Implement block bodies") and ec8b709fa24c ("Implement block bodies inside of the assembler") make this one out possible, as .repeat statements don't have an identifier that can be used for hashing. From the parser perspective this introduction raises two new things. First of all this control statement also needed a differentiation between the amount of required arguments, and the allowed ones, since there is a second optional argument to it. And second, even the identifier is not given, we have to generate one so to add a context for it. This was at first not needed, but introducing .repeat-only variables means that we have to have inner contexts which need to be named somehow so we can retrieve the context later when picking up the value for them again. This last thing brought the need for a new dependency: rand. This is used to generate a random string to identify the .repeat block. Signed-off-by: Miquel Sabaté Solà --- lib/xixanta/src/node.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'lib/xixanta/src/node.rs') diff --git a/lib/xixanta/src/node.rs b/lib/xixanta/src/node.rs index 6afb424..f919ade 100644 --- a/lib/xixanta/src/node.rs +++ b/lib/xixanta/src/node.rs @@ -138,6 +138,8 @@ pub enum ControlType { Word, Addr, IncBin, + StartRepeat, + EndRepeat, } impl fmt::Display for ControlType { @@ -156,6 +158,8 @@ impl fmt::Display for ControlType { ControlType::Word => write!(f, ".word/.dw"), ControlType::Addr => write!(f, ".addr"), ControlType::IncBin => write!(f, ".incbin"), + ControlType::StartRepeat => write!(f, ".repeat"), + ControlType::EndRepeat => write!(f, ".endrepeat"), } } } @@ -293,6 +297,9 @@ impl NodeType { NodeType::Control(ControlType::StartScope) => { Some(NodeType::Control(ControlType::EndScope)) } + NodeType::Control(ControlType::StartRepeat) => { + Some(NodeType::Control(ControlType::EndRepeat)) + } _ => None, } } @@ -353,10 +360,12 @@ impl PNode { match self.node_type { NodeType::Control(ControlType::StartMacro) | NodeType::Control(ControlType::StartProc) - | NodeType::Control(ControlType::StartScope) => NodeBodyType::Starts, + | NodeType::Control(ControlType::StartScope) + | NodeType::Control(ControlType::StartRepeat) => NodeBodyType::Starts, NodeType::Control(ControlType::EndMacro) | NodeType::Control(ControlType::EndProc) - | NodeType::Control(ControlType::EndScope) => NodeBodyType::Ends, + | NodeType::Control(ControlType::EndScope) + | NodeType::Control(ControlType::EndRepeat) => NodeBodyType::Ends, _ => NodeBodyType::None, } } -- cgit v1.2.3