cel_rs/
context.rs

1use std::{collections::HashMap, rc::Rc};
2
3use crate::{eval::Bag, Value};
4
5#[derive(Default)]
6pub struct Context {
7    par: Option<Rc<Context>>,
8    vars: HashMap<&'static str, Value>
9}
10
11impl Bag for Context {
12    fn unpack(self) -> Value {
13        todo!()
14    }
15}
16
17impl Context {
18    pub fn add_variable(mut self, name: &'static str, val: Value) -> Self {
19        self.vars.insert(name, val);
20        self
21    }
22
23    pub fn resolve(&self, name: &String) -> Option<Value> {
24        // TODO: this is probably expensive to do.
25        self.vars.get(name.as_str()).map(|f| f.to_owned())
26    }
27    pub fn parent(&self) -> Option<Rc<Context>> {
28       self.par.clone()
29    }
30}