aboutsummaryrefslogtreecommitdiffstats
path: root/src/modelica_ast.rs
diff options
context:
space:
mode:
authorbnewbold <bnewbold@robocracy.org>2016-11-02 19:06:23 -0700
committerbnewbold <bnewbold@robocracy.org>2016-11-02 19:06:23 -0700
commitece67d35847ec89cbf4d3d13236ce5bb1d51b716 (patch)
tree9bb1e7eedb1792a652648d0319bb417935b267a4 /src/modelica_ast.rs
parenta0ade9fdd10ed246bc228f74662ef2264d67f4e3 (diff)
downloadmodelthing-ece67d35847ec89cbf4d3d13236ce5bb1d51b716.tar.gz
modelthing-ece67d35847ec89cbf4d3d13236ce5bb1d51b716.zip
skeletal scheme transpilation
Diffstat (limited to 'src/modelica_ast.rs')
-rw-r--r--src/modelica_ast.rs38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/modelica_ast.rs b/src/modelica_ast.rs
index 68eafaf..9e25b1b 100644
--- a/src/modelica_ast.rs
+++ b/src/modelica_ast.rs
@@ -1,5 +1,6 @@
use std::fmt::{Debug, Formatter, Error};
+use std::collections::HashMap;
#[derive(PartialEq)]
pub struct ModelicaModel {
@@ -59,6 +60,43 @@ pub enum BinOperator {
Subtract,
}
+//// Helpers
+
+impl ModelicaModel {
+
+ pub fn get_constant_vars(&self) -> HashMap<String,Expr> {
+ let mut binds = HashMap::new();
+ 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)); },
+ _ => (),
+ }
+ }
+ binds
+ }
+
+ pub fn get_free_vars(&self) -> Vec<String> {
+ // Start with components, and remove constants and parameters
+ let vars = self.components.iter().filter(|v| match v.prefix {
+ Some(ComponentPrefix::Constant) | Some(ComponentPrefix::Parameter) => false,
+ _ => true,
+ });
+
+ // Remove LHS (bound) vars
+ let mut outputs = vec![];
+ for eq in self.equations.iter() {
+ // TODO:
+ if let Expr::Ident(ref symb) = eq.lhs {
+ outputs.push(symb.to_string());
+ }
+ }
+ let vars = vars.filter(|v| !outputs.contains(&v.name));
+
+ vars.map(|c| c.name.clone()).collect()
+ }
+}
+
//// Debug Implementations
impl Debug for ModelicaModel {