diff options
author | bnewbold <bnewbold@robocracy.org> | 2016-12-02 00:26:06 -0800 |
---|---|---|
committer | bnewbold <bnewbold@robocracy.org> | 2016-12-02 00:26:06 -0800 |
commit | 3915bab43caed28664f5bb365d03cb9af296ff46 (patch) | |
tree | d06b946083d1bd396c805b7c87009c3835b6c72a | |
parent | a569e3d3118c7a132ec554996f5fb03c71045e90 (diff) | |
download | modelthing-3915bab43caed28664f5bb365d03cb9af296ff46.tar.gz modelthing-3915bab43caed28664f5bb365d03cb9af296ff46.zip |
fix get_constant_vars function type signature
-rw-r--r-- | src/modelica_ast.rs | 10 | ||||
-rw-r--r-- | src/transpile_js.rs | 6 | ||||
-rw-r--r-- | src/transpile_scheme.rs | 6 |
3 files changed, 14 insertions, 8 deletions
diff --git a/src/modelica_ast.rs b/src/modelica_ast.rs index 6903900..f97cd0a 100644 --- a/src/modelica_ast.rs +++ b/src/modelica_ast.rs @@ -3,7 +3,7 @@ use std::clone::Clone; use std::fmt::{Debug, Formatter, Error}; use std::collections::HashMap; -#[derive(PartialEq)] +#[derive(Clone, PartialEq)] pub struct ModelicaModel { pub name: String, pub components: Vec<Component>, @@ -68,12 +68,13 @@ pub enum BinOperator { impl ModelicaModel { - pub fn get_constant_vars(&self) -> HashMap<String,Expr> { + pub fn get_constant_vars(&self) -> HashMap<String,Option<Expr>> { let mut binds = HashMap::new(); + // XXX: actually implement this... for c in &self.components { match c.prefix { - Some(ComponentPrefix::Constant) => { binds.insert(c.name.clone(), Expr::Integer(123)); }, - Some(ComponentPrefix::Parameter) => { binds.insert(c.name.clone(), Expr::Float(4.56)); }, + Some(ComponentPrefix::Constant) => { binds.insert(c.name.clone(), Some(Expr::Integer(123))); }, + Some(ComponentPrefix::Parameter) => { binds.insert(c.name.clone(), Some(Expr::Float(4.56))); }, _ => (), } } @@ -127,6 +128,7 @@ fn intersect_strings(a: &Vec<String>, b: &Vec<String>) -> Vec<String> { impl Expr { // Order is undefined + // TODO: should return a HashSet, not a Vec pub fn identifiers(&self) -> Vec<String> { use self::Expr::*; match *self { diff --git a/src/transpile_js.rs b/src/transpile_js.rs index 1ec9a10..7c8932f 100644 --- a/src/transpile_js.rs +++ b/src/transpile_js.rs @@ -10,8 +10,10 @@ impl TranspileJS for ModelicaModel { fn repr_js(&self) -> Result<String, String> { let mut constants = vec![]; for (c, e) in self.get_constant_vars() { - constants.push(format!("var {} = {};", - c, try!(e.repr_js()))); + if let Some(v) = e { + constants.push(format!("var {} = {};", + c, try!(v.repr_js()))); + } } let mut binds = vec![]; let mut outputs = vec![]; diff --git a/src/transpile_scheme.rs b/src/transpile_scheme.rs index ce66d10..5a88cda 100644 --- a/src/transpile_scheme.rs +++ b/src/transpile_scheme.rs @@ -10,8 +10,10 @@ impl TranspileScheme for ModelicaModel { fn repr_scheme(&self) -> Result<String, String> { let mut constants = vec![]; for (c, e) in self.get_constant_vars() { - constants.push(format!("({} {})", - c, try!(e.repr_scheme()))); + if let Some(v) = e { + constants.push(format!("({} {})", + c, try!(v.repr_scheme()))); + } } let mut binds = vec![]; let mut outputs = vec![]; |