mirror of
https://github.com/tiffany352/rink-rs
synced 2024-09-20 22:21:57 +00:00
Handle dependency resolution of substances
This commit is contained in:
parent
6fba23c587
commit
305874a0d0
1 changed files with 13 additions and 1 deletions
14
src/load.rs
14
src/load.rs
|
@ -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)
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue