From 3915bab43caed28664f5bb365d03cb9af296ff46 Mon Sep 17 00:00:00 2001 From: bnewbold Date: Fri, 2 Dec 2016 00:26:06 -0800 Subject: fix get_constant_vars function type signature --- src/modelica_ast.rs | 10 ++++++---- src/transpile_js.rs | 6 ++++-- 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, @@ -68,12 +68,13 @@ pub enum BinOperator { impl ModelicaModel { - pub fn get_constant_vars(&self) -> HashMap { + pub fn get_constant_vars(&self) -> HashMap> { 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, b: &Vec) -> Vec { impl Expr { // Order is undefined + // TODO: should return a HashSet, not a Vec pub fn identifiers(&self) -> Vec { 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 { 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 { 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![]; -- cgit v1.2.3