-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
123 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,30 @@ | ||
use std::{collections::HashMap, rc::Rc}; | ||
|
||
use crate::{eval::Bag, Value}; | ||
|
||
#[derive(Default)] | ||
pub struct Context { | ||
|
||
par: Option<Rc<Context>>, | ||
vars: HashMap<&'static str, Value> | ||
} | ||
|
||
impl Default for Context { | ||
fn default() -> Self { | ||
let ctx = Context {}; | ||
ctx | ||
impl Bag for Context { | ||
fn unpack(self) -> Value { | ||
todo!() | ||
} | ||
} | ||
|
||
impl Context { | ||
pub fn add_variable(mut self, name: &'static str, val: Value) -> Self { | ||
self.vars.insert(name, val); | ||
self | ||
} | ||
|
||
pub fn resolve(&self, name: &String) -> Option<Value> { | ||
// TODO: this is probably expensive to do. | ||
self.vars.get(name.as_str()).map(|f| f.to_owned()) | ||
} | ||
pub fn parent(&self) -> Option<Rc<Context>> { | ||
self.par.clone() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters