aboutsummaryrefslogtreecommitdiff
path: root/lib/xixanta/src/context.rs
diff options
context:
space:
mode:
authorMiquel Sabaté Solà <mikisabate@gmail.com>2024-09-26 15:53:57 +0200
committerMiquel Sabaté Solà <mikisabate@gmail.com>2024-12-12 07:41:30 +0100
commit184c39579227c0add80a61d489c242120001d6b6 (patch)
tree48737e0e00b5fb655090a1c9a4fc216dcf278cc0 /lib/xixanta/src/context.rs
parent54e1239fcccb2383e5caa88844a7229b5441c31e (diff)
downloadtools.nes-184c39579227.tar.gz
tools.nes-184c39579227.zip
Re-work the parser from scratch
The initial implementation was incredibly naive on how complex an assembler can actually be. Because of this, it never bothered to define and produce a proper AST, and hence it was overall extremely fragile on (not so) corner cases. This commit re-writes everything from scratch for the parser, and it should really be the last fundamental change to the parser other than minor additions/features here and there. Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
Diffstat (limited to 'lib/xixanta/src/context.rs')
-rw-r--r--lib/xixanta/src/context.rs36
1 files changed, 22 insertions, 14 deletions
diff --git a/lib/xixanta/src/context.rs b/lib/xixanta/src/context.rs
index 32f9de9..2ac6da8 100644
--- a/lib/xixanta/src/context.rs
+++ b/lib/xixanta/src/context.rs
@@ -1,12 +1,13 @@
-use crate::instruction::PString;
+use crate::instruction::Bundle;
+use crate::parser::PNode;
use std::collections::HashMap;
const GLOBAL_CONTEXT: &str = "Global";
#[derive(Debug)]
pub struct PValue {
- pub node: PString,
- pub value: usize,
+ pub node: PNode,
+ pub value: Bundle,
pub label: bool,
}
@@ -30,10 +31,6 @@ impl Context {
}
}
- pub fn global(&mut self) {
- self.stack = vec![];
- }
-
pub fn find(&self, name: &str) -> Option<&HashMap<String, PValue>> {
self.map.get(name)
}
@@ -52,6 +49,17 @@ impl Context {
}
}
+ pub fn is_global(&self) -> bool {
+ self.stack.is_empty()
+ }
+
+ pub fn name(&self) -> &str {
+ match self.stack.last() {
+ Some(name) => name,
+ None => GLOBAL_CONTEXT,
+ }
+ }
+
pub fn push(&mut self, identifier: &String) {
let name = match self.stack.last() {
Some(n) => n.to_owned() + &String::from("::") + identifier,
@@ -62,14 +70,14 @@ impl Context {
self.map.entry(name).or_default();
}
- pub fn push_stack(&mut self, identifier: &String) {
- let name = match self.stack.last() {
- Some(n) => n.to_owned() + &String::from("::") + identifier,
- None => identifier.to_string(),
- };
+ // pub fn push_stack(&mut self, identifier: &String) {
+ // let name = match self.stack.last() {
+ // Some(n) => n.to_owned() + &String::from("::") + identifier,
+ // None => identifier.to_string(),
+ // };
- self.stack.push(name.clone());
- }
+ // self.stack.push(name.clone());
+ // }
pub fn pop(&mut self) -> bool {
if self.stack.is_empty() {