Interpreter - Environment::default() implemented manually
This commit is contained in:
parent
6a227c96ee
commit
113fffb872
1 changed files with 12 additions and 1 deletions
|
@ -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 {
|
||||||
|
|
Loading…
Reference in a new issue