Handle dependency resolution of substances

This commit is contained in:
Tiffany Bennett 2016-09-27 22:25:11 -04:00
parent 6fba23c587
commit 305874a0d0

View file

@ -118,7 +118,8 @@ impl Context {
self.eval(left);
self.eval(right);
},
Expr::Neg(ref expr) | Expr::Plus(ref expr) | Expr::Suffix(_, ref expr) =>
Expr::Neg(ref expr) | Expr::Plus(ref expr) |
Expr::Suffix(_, ref expr) | Expr::Of(_, ref expr) =>
self.eval(expr),
Expr::Mul(ref exprs) | Expr::Call(_, ref exprs) => for expr in exprs {
self.eval(expr);
@ -142,6 +143,12 @@ impl Context {
Def::Canonicalization(ref e) => {
self.lookup(&Rc::new(e.clone()));
},
Def::Substance(ref props) => {
for prop in props {
self.eval(&prop.input);
self.eval(&prop.output);
}
},
_ => (),
}
}
@ -238,6 +245,11 @@ impl Context {
self.definitions.insert(name.clone(), expr.clone());
self.units.insert(name.clone(), v);
},
Ok(Value::Substance(sub)) => {
if self.substances.insert(name.clone(), sub).is_some() {
println!("Warning: Conflicting substances for {}", name);
}
},
Ok(_) => println!("Unit {} is not a number", name),
Err(e) => println!("Unit {} is malformed: {}", name, e)
},