Interpreter - Environment::default() implemented manually

This commit is contained in:
Emmanuel BENOîT 2023-01-02 17:55:05 +01:00
parent 6a227c96ee
commit 113fffb872

View file

@ -11,12 +11,23 @@ pub type EnvironmentRef = Rc<RefCell<Environment>>;
pub type Variable = Option<Value>; pub type Variable = Option<Value>;
/// The execution environment. /// The execution environment.
#[derive(Debug, Default)] #[derive(Debug)]
pub struct Environment { pub struct Environment {
enclosing: Option<EnvironmentRef>, enclosing: Option<EnvironmentRef>,
values: HashMap<String, Variable>, values: HashMap<String, Variable>,
} }
impl Default for Environment {
/// Create the default global environment. This includes native functions.
fn default() -> Self {
let env = Self {
enclosing: None,
values: HashMap::new(),
};
env
}
}
impl Environment { impl Environment {
/// Create an environment enclosed in another. /// Create an environment enclosed in another.
pub fn create_child(parent: &EnvironmentRef) -> EnvironmentRef { pub fn create_child(parent: &EnvironmentRef) -> EnvironmentRef {