シミュレーションで四則演算ができるようにした.
1 parent 912d6b9 commit d3acd584a507b287de92dcd52003d7793b4c5ad9
Naoya Nitta authored on 2 Aug
Showing 4 changed files
View
49
AlgebraicDataflowArchitectureModel/src/models/algebra/Symbol.java
package models.algebra;
 
import java.util.List;
 
public class Symbol {
protected String name;
protected String implName;
protected Symbol[] inverses = null;
protected models.algebra.Type[] signature = null;
protected int[] implParamOrder = null;
protected IImplGenerator generator = null;
protected ICalculator calculator = null;
public Symbol(String name) {
this.name = name;
this.implName = name;
this.implOperatorType = Type.GENERATIVE_WITH_SIDE_EFFECT;
}
}
public Symbol(String name, int arity, ICalculator calculator) {
this.name = name;
this.arity = arity;
this.calculator = calculator;
}
public Symbol(String name, int arity, Type operatorType, ICalculator calculator) {
this.name = name;
this.arity = arity;
this.operatorType = operatorType;
this.calculator = calculator;
}
public Symbol(String name, int arity, Type operatorType, IImplGenerator generator, ICalculator calculator) {
this.name = name;
this.arity = arity;
this.operatorType = operatorType;
this.generator = generator;
this.implOperatorType = Type.GENERATIVE;
this.calculator = calculator;
}
public Symbol(String name, int arity, Type operatorType, String implName, Type implOperatorType, ICalculator calculator) {
this.name = name;
this.implName = implName;
this.arity = arity;
this.operatorType = operatorType;
this.implOperatorType = implOperatorType;
this.calculator = calculator;
}
public void setArity(int arity) {
this.arity = arity;
}
 
return generator.generate(type, childrenTypes, childrenImpl, childrenSideEffects, sideEffect);
}
return null;
}
public boolean isCalculatable() {
return (calculator != null);
}
public Constant calculate(List<Constant> args) {
if (calculator != null) {
return calculator.calculate(args);
}
return null;
}
 
public boolean equals(Object another) {
if (!(another instanceof Symbol)) return false;
return name.equals(((Symbol) another).name) && arity == ((Symbol) another).arity;
* @return the generated implementation
*/
public String generate(models.algebra.Type type, models.algebra.Type[] childrenTypes, String children[], String[] childrenSideEffects, String[] sideEffect);
}
public interface ICalculator {
public Constant calculate(List<Constant> args);
}
}
View
12
AlgebraicDataflowArchitectureModel/src/models/algebra/Term.java
return newTerm;
} else {
return new Term(newSymbol, newChildren);
}
} else if (symbol.isCalculatable()) {
List<Constant> newChildren = new ArrayList<>();
for (Expression child: children) {
if (child instanceof Term) {
child = ((Term) child).reduce();
}
if (!(child instanceof Constant)) {
return this;
}
newChildren.add((Constant) child);
}
return symbol.calculate(newChildren);
} else {
// Calculate inverse map
List<Expression> newChildren = new ArrayList<>();
boolean bReduced = false;
View
AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/DataConstraintModel.java
View
AlgebraicDataflowArchitectureModel/src/simulator/SystemState.java