blob: 2bb3f5bf5052e690aabf962cbe3eba87b01d7ed2 (
plain) (
tree)
|
|
use crate::*;
use semantic::*;
use std::collections::HashMap;
pub struct Environment {
pub scopes: Vec<Scope>,
}
impl Environment {
pub fn get_integer(&self, name: &str) -> Result<usize, ()> {
for scope in self.scopes.iter().rev() {
if let Ok(value) = scope.get_integer(name, &self) {
return Ok(value);
}
}
return Err(());
}
pub fn get_block(&self, name: &str) -> Result<usize, ()> {
for scope in self.scopes.iter().rev() {
if let Ok(value) = scope.get_block(name, &self) {
return Ok(value);
}
}
return Err(());
}
}
pub struct Scope {
pub definitions: HashMap<String, Definition>,
}
impl Scope {
pub fn get_integer(&self, _name: &str, _environment: &Environment) -> Result<usize, ()> {
todo!()
// use semantic::IntegerDefinition as IntDef;
// if let Some(Definition { variant, ..}) = self.definitions.get(name) {
// if let IntegerDefinition::Integer(integer) = definition {
// match integer {
// IntDef::Literal(value) => return Ok(*value),
// IntDef::ConstantExpression(expr) => match expr.evaluate(environment) {
// Ok(_) | Err(_) => todo!(),
// },
// };
// }
// }
// return Err(());
}
pub fn get_block(&self, _name: &str, _environment: &Environment) -> Result<usize, ()> {
todo!()
}
}
|