aboutsummaryrefslogtreecommitdiff
path: root/lib/xixanta/src/node.rs
diff options
context:
space:
mode:
authorMiquel Sabaté Solà <mikisabate@gmail.com>2024-12-23 15:45:49 +0100
committerMiquel Sabaté Solà <mikisabate@gmail.com>2024-12-23 15:45:49 +0100
commit31ac0e214d43da3bb705c8f345f5afcb922cefac (patch)
tree23234809c26a0e0bce208436328ca5f991576047 /lib/xixanta/src/node.rs
parent4115d83eb537ffbd81e2fd8d12790a8fad769199 (diff)
downloadtools.nes-31ac0e214d43da3bb705c8f345f5afcb922cefac.tar.gz
tools.nes-31ac0e214d43da3bb705c8f345f5afcb922cefac.zip
Make more explicit segment/macros are only global
Force .segment and .macro statements to be on the global scope since this is how they are meant. Hence, if the programmer tries to do this, just error out. Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
Diffstat (limited to 'lib/xixanta/src/node.rs')
-rw-r--r--lib/xixanta/src/node.rs30
1 files changed, 29 insertions, 1 deletions
diff --git a/lib/xixanta/src/node.rs b/lib/xixanta/src/node.rs
index f6f3d09..9739c9d 100644
--- a/lib/xixanta/src/node.rs
+++ b/lib/xixanta/src/node.rs
@@ -140,6 +140,34 @@ pub enum ControlType {
IncBin,
}
+impl fmt::Display for ControlType {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ match self {
+ ControlType::Hibyte => write!(f, ".hibyte"),
+ ControlType::Lobyte => write!(f, ".lobyte"),
+ ControlType::StartMacro => write!(f, ".macro"),
+ ControlType::EndMacro => write!(f, ".endmacro"),
+ ControlType::StartProc => write!(f, ".proc"),
+ ControlType::EndProc => write!(f, ".endproc"),
+ ControlType::StartScope => write!(f, ".scope"),
+ ControlType::EndScope => write!(f, ".endscope"),
+ ControlType::Segment => write!(f, ".segment"),
+ ControlType::Byte => write!(f, ".byte/.db"),
+ ControlType::Word => write!(f, ".word/.dw"),
+ ControlType::Addr => write!(f, ".addr"),
+ ControlType::IncBin => write!(f, ".incbin"),
+ }
+ }
+}
+
+impl ControlType {
+ /// Returns true if the type of control statement requires it to be in the
+ /// global scope.
+ pub fn must_be_global(&self) -> bool {
+ matches!(self, ControlType::StartMacro | ControlType::Segment)
+ }
+}
+
/// The type of operation being used.
#[derive(Debug, Clone, PartialEq)]
pub enum OperationType {
@@ -213,7 +241,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(control_type) => write!(f, "control function ({})", control_type),
NodeType::Literal => write!(f, "literal"),
NodeType::Label => write!(f, "label"),
NodeType::Call => write!(f, "call"),