use std::collections::HashMap;
use crate::schema::Schema;
use crate::types::DataType;
use crate::value::Value;
pub struct Environment {
pub schema: Schema,
pub globals: HashMap<String, Value>,
pub globals_types: HashMap<String, DataType>,
pub scopes: HashMap<String, DataType>,
}
impl Environment {
pub fn new(schema: Schema) -> Self {
Self {
schema,
globals: HashMap::default(),
globals_types: HashMap::default(),
scopes: HashMap::default(),
}
}
pub fn define(&mut self, str: String, data_type: DataType) {
self.scopes.insert(str, data_type);
}
pub fn define_global(&mut self, str: String, data_type: DataType) {
self.globals_types.insert(str, data_type);
}
pub fn contains(&self, str: &String) -> bool {
self.scopes.contains_key(str) || self.globals_types.contains_key(str)
}
pub fn resolve_type(&self, str: &String) -> Option<&DataType> {
if str.starts_with('@') {
return self.globals_types.get(str);
}
return self.scopes.get(str);
}
pub fn clear_session(&mut self) {
self.scopes.clear()
}
}