diff options
| author | Miquel Sabaté Solà <mikisabate@gmail.com> | 2024-07-17 16:06:34 +0200 |
|---|---|---|
| committer | Miquel Sabaté Solà <mikisabate@gmail.com> | 2024-12-12 07:40:53 +0100 |
| commit | 5b1f387d451b3ff136464dcbc71f0c2310a57d01 (patch) | |
| tree | 5131731d044823d66c5938cf4870f09f7ed19fec /lib/xixanta/src/mapping.rs | |
| parent | 376dcb684ce779a7051bbc9a95359114e94cae5e (diff) | |
| download | tools.nes-5b1f387d451b.tar.gz tools.nes-5b1f387d451b.zip | |
Add basic support for macros
Macros can now be described with the '.macro' control statement, but no
parameters can be given and it's overall pretty brittle.
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
Diffstat (limited to 'lib/xixanta/src/mapping.rs')
| -rw-r--r-- | lib/xixanta/src/mapping.rs | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/lib/xixanta/src/mapping.rs b/lib/xixanta/src/mapping.rs index d2f1410..231883f 100644 --- a/lib/xixanta/src/mapping.rs +++ b/lib/xixanta/src/mapping.rs @@ -5,6 +5,12 @@ use crate::errors::ParseError; type Result<T> = std::result::Result<T, ParseError>; lazy_static! { + pub static ref EMPTY: Vec<Segment> = vec![Segment { + name: String::from("CODE"), + start: 0x0000, + size: 0xFFFF, + fill: None, + }]; pub static ref NROM: Vec<Segment> = vec![ Segment { name: String::from("HEADER"), @@ -46,6 +52,8 @@ pub struct Mapping { pub segments: Vec<Segment>, pub nodes: HashMap<String, Vec<Node>>, pub current: String, + pub macros: HashMap<String, Vec<Node>>, + pub current_macro: Option<String>, } impl Mapping { @@ -63,11 +71,21 @@ impl Mapping { segments, nodes, current: current_segment.to_string(), + macros: HashMap::new(), + current_macro: None, } } pub fn reset(&mut self) { - // TODO + self.nodes = HashMap::new(); + for segment in self.segments.iter() { + self.nodes.insert(segment.name.clone(), vec![]); + } + + self.current = self.segments.first().unwrap().name.clone(); + + self.macros = HashMap::new(); + self.current_macro = None; } pub fn switch(&mut self, id: &PString) -> Result<()> { @@ -90,6 +108,9 @@ impl Mapping { } pub fn push(&mut self, node: Node) { - self.nodes.get_mut(&self.current).unwrap().push(node); + match &self.current_macro { + Some(m) => self.macros.get_mut(m).unwrap().push(node), + None => self.nodes.get_mut(&self.current).unwrap().push(node), + } } } |
