ergoscript_compiler/
script_env.rs

1//! Compilation environment
2
3use std::collections::HashMap;
4
5use ergotree_ir::mir::constant::Constant;
6
7/// Environment with values substituted for identifiers during compilation
8pub struct ScriptEnv(HashMap<String, Constant>);
9
10impl Default for ScriptEnv {
11    fn default() -> Self {
12        Self::new()
13    }
14}
15
16impl ScriptEnv {
17    /// Empty environment
18    pub fn new() -> Self {
19        ScriptEnv(HashMap::new())
20    }
21
22    /// Returns the value([`Constant`]) for the given identifier (if any)
23    pub fn get(&self, ident: &str) -> Option<&Constant> {
24        self.0.get(ident)
25    }
26}