diff options
| author | Miquel Sabaté Solà <mikisabate@gmail.com> | 2024-07-16 11:12:26 +0200 |
|---|---|---|
| committer | Miquel Sabaté Solà <mikisabate@gmail.com> | 2024-12-12 07:32:52 +0100 |
| commit | 7822c00e8689c99ded0a360026f4e7ace1f2c87f (patch) | |
| tree | e2bc22aeea0a172ee7aee5e4a2a4b603a495b9b8 /lib/xixanta/src/context.rs | |
| parent | c6c9aa4e5f3e5a01fcb9ccabf6dbd2f6da277650 (diff) | |
| download | tools.nes-7822c00e8689c99ded0a360026f4e7ace1f2c87f.tar.gz tools.nes-7822c00e8689c99ded0a360026f4e7ace1f2c87f.zip | |
Add support for branching
This is a bare bones implementation of it, and there's a lot of nuance
that it's being missed, but at least the fundamentals have been
implemented already.
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
Diffstat (limited to 'lib/xixanta/src/context.rs')
| -rw-r--r-- | lib/xixanta/src/context.rs | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/lib/xixanta/src/context.rs b/lib/xixanta/src/context.rs index 62ec7e0..aade200 100644 --- a/lib/xixanta/src/context.rs +++ b/lib/xixanta/src/context.rs @@ -4,9 +4,16 @@ use std::collections::HashMap; const GLOBAL_CONTEXT: &str = "Global"; #[derive(Debug)] +pub struct PValue { + pub node: PString, + pub value: usize, + pub label: bool, +} + +#[derive(Debug)] pub struct Context { stack: Vec<String>, - map: HashMap<String, HashMap<String, PString>>, + map: HashMap<String, HashMap<String, PValue>>, } impl Default for Context { @@ -27,18 +34,18 @@ impl Context { self.stack = vec![]; } - pub fn find(&self, name: &str) -> Option<&HashMap<String, PString>> { + pub fn find(&self, name: &str) -> Option<&HashMap<String, PValue>> { self.map.get(name) } - pub fn current(&self) -> Option<&HashMap<String, PString>> { + pub fn current(&self) -> Option<&HashMap<String, PValue>> { match self.stack.last() { Some(name) => self.map.get(name), None => self.map.get(GLOBAL_CONTEXT), } } - pub fn current_mut(&mut self) -> Option<&mut HashMap<String, PString>> { + pub fn current_mut(&mut self) -> Option<&mut HashMap<String, PValue>> { match self.stack.last() { Some(name) => self.map.get_mut(name), None => self.map.get_mut(GLOBAL_CONTEXT), |
