diff --git a/AlgebraicDataflowArchitectureModel/msrc/Acceleration.java b/AlgebraicDataflowArchitectureModel/msrc/Acceleration.java new file mode 100644 index 0000000..c99c0dc --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/msrc/Acceleration.java @@ -0,0 +1,37 @@ +import java.util.*; + +public class Acceleration { + private Map.Entry force; + private double mass; + private Velocity velocity; + private Onground onground; + private Map.Entry value; + public void updateForce(Map.Entry force) { + this.force = force; + Map.Entry temp_l4; + if(this.onground.getValue()) { + temp_l4 = new AbstractMap.SimpleEntry<>((force.getKey()/mass), 0.0); + } else { + temp_l4 = new AbstractMap.SimpleEntry<>((force.getKey()/mass), (force.getValue()/mass)); + } + acceleration = temp_l4; + velocity.updateAcceleration(value); + } + public void updateMass(double mass) { + this.mass = mass; + Map.Entry temp_l5; + if(this.onground.getValue()) { + temp_l5 = new AbstractMap.SimpleEntry<>((force.getKey()/mass), 0.0); + } else { + temp_l5 = new AbstractMap.SimpleEntry<>((force.getKey()/mass), (force.getValue()/mass)); + } + acceleration = temp_l5; + velocity.updateAcceleration(value); + } + public Acceleration(Velocity velocity, Onground onground) { + this.onground = onground; + } + public Map.Entry getValue() { + return value; + } +} \ No newline at end of file diff --git a/AlgebraicDataflowArchitectureModel/msrc/Clear.java b/AlgebraicDataflowArchitectureModel/msrc/Clear.java new file mode 100644 index 0000000..a7225a7 --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/msrc/Clear.java @@ -0,0 +1,17 @@ +import java.util.*; + +public class Clear { + private Position position; + public Clear(Position position) { + this.position = position; + } + public boolean getValue() { + boolean temp_l0; + if((this.position.getValue().getKey()>100.0)) { + temp_l0 = true; + } else { + temp_l0 = false; + } + return temp_l0; + } +} \ No newline at end of file diff --git a/AlgebraicDataflowArchitectureModel/msrc/Force.java b/AlgebraicDataflowArchitectureModel/msrc/Force.java new file mode 100644 index 0000000..68e30ef --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/msrc/Force.java @@ -0,0 +1,16 @@ +import java.util.*; + +public class Force { + private Acceleration acceleration; + private Map.Entry value; + public Force(Acceleration acceleration) { + this.acceleration = acceleration; + } + public void gravity(double y) { + this.force = new AbstractMap.SimpleEntry<>(0.0, y); + acceleration.updateForce(value); + } + public Map.Entry getValue() { + return value; + } +} \ No newline at end of file diff --git a/AlgebraicDataflowArchitectureModel/msrc/Gameover.java b/AlgebraicDataflowArchitectureModel/msrc/Gameover.java new file mode 100644 index 0000000..7b07745 --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/msrc/Gameover.java @@ -0,0 +1,17 @@ +import java.util.*; + +public class Gameover { + private Position position; + public Gameover(Position position) { + this.position = position; + } + public boolean getValue() { + boolean temp_l6; + if((this.position.getValue().getValue()<-(1.0))) { + temp_l6 = true; + } else { + temp_l6 = false; + } + return temp_l6; + } +} \ No newline at end of file diff --git a/AlgebraicDataflowArchitectureModel/msrc/Ground.java b/AlgebraicDataflowArchitectureModel/msrc/Ground.java new file mode 100644 index 0000000..249ad73 --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/msrc/Ground.java @@ -0,0 +1,8 @@ +import java.util.*; + +public class Ground { + private boolean value; + public boolean getValue() { + return value; + } +} \ No newline at end of file diff --git a/AlgebraicDataflowArchitectureModel/msrc/JumpGame.java b/AlgebraicDataflowArchitectureModel/msrc/JumpGame.java new file mode 100644 index 0000000..65a9c29 --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/msrc/JumpGame.java @@ -0,0 +1,61 @@ +import java.util.*; + +public class JumpGame { + private Time time = new Time(); + private Ground ground = new Ground(); + private Position position = new Position(ground); + private Gameover gameover = new Gameover(position); + private Onground onground = new Onground(ground,position); + private Velocity velocity = new Velocity(position,onground); + private Clear clear = new Clear(position); + private Move move = new Move(velocity); + private Acceleration acceleration = new Acceleration(velocity,onground); + private Mass mass = new Mass(acceleration); + private Force force = new Force(acceleration); + public void gravity(double y) { + this.force.gravity(y); + this.time.gravity(y); + } + public void moveY(double y) { + this.move.moveY(y); + } + public void moveX(double x) { + this.move.moveX(x); + } + public void setMass(double x) { + this.mass.setMass(x); + } + public Map.Entry getAcceleration() { + return acceleration.getAcceleration(); + } + public Map.Entry getMove() { + return move.getMove(); + } + public double getMass() { + return mass.getMass(); + } + public boolean getClear() { + return clear.getClear(); + } + public boolean getGround() { + return ground.getGround(); + } + public Map.Entry getForce() { + return force.getForce(); + } + public Map.Entry getVelocity() { + return velocity.getVelocity(); + } + public Map.Entry getPosition() { + return position.getPosition(); + } + public boolean getOnground() { + return onground.getOnground(); + } + public double getTime() { + return time.getTime(); + } + public boolean getGameover() { + return gameover.getGameover(); + } +} \ No newline at end of file diff --git a/AlgebraicDataflowArchitectureModel/msrc/Mass.java b/AlgebraicDataflowArchitectureModel/msrc/Mass.java new file mode 100644 index 0000000..8ba2a79 --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/msrc/Mass.java @@ -0,0 +1,16 @@ +import java.util.*; + +public class Mass { + private Acceleration acceleration; + private double value; + public Mass(Acceleration acceleration) { + this.acceleration = acceleration; + } + public void setMass(double x) { + this.mass = x; + acceleration.updateMass(value); + } + public double getValue() { + return value; + } +} \ No newline at end of file diff --git a/AlgebraicDataflowArchitectureModel/msrc/Move.java b/AlgebraicDataflowArchitectureModel/msrc/Move.java new file mode 100644 index 0000000..0670524 --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/msrc/Move.java @@ -0,0 +1,19 @@ +import java.util.*; + +public class Move { + private Velocity velocity; + private Map.Entry value; + public Move(Velocity velocity) { + this.velocity = velocity; + } + public void moveY(double y) { + this.move = new AbstractMap.SimpleEntry<>(this.value.getKey(), y); + velocity.updateMove(value); + } + public void moveX(double x) { + this.move = new AbstractMap.SimpleEntry<>(x, this.value.getValue()); + } + public Map.Entry getValue() { + return value; + } +} \ No newline at end of file diff --git a/AlgebraicDataflowArchitectureModel/msrc/Onground.java b/AlgebraicDataflowArchitectureModel/msrc/Onground.java new file mode 100644 index 0000000..66ce751 --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/msrc/Onground.java @@ -0,0 +1,13 @@ +import java.util.*; + +public class Onground { + private Ground ground; + private Position position; + public Onground(Ground ground, Position position) { + this.ground = ground; + this.position = position; + } + public boolean getValue() { + return ((this.ground.getValue()==true)&&(this.position.getValue().getValue()<=0.0)); + } +} \ No newline at end of file diff --git a/AlgebraicDataflowArchitectureModel/msrc/Pair.java b/AlgebraicDataflowArchitectureModel/msrc/Pair.java new file mode 100644 index 0000000..6ee4e75 --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/msrc/Pair.java @@ -0,0 +1,12 @@ +import java.util.*; + +public class Pair { + private double first; + private double second; + public double getFirst() { + return first; + } + public double getSecond() { + return second; + } +} \ No newline at end of file diff --git a/AlgebraicDataflowArchitectureModel/msrc/Position.java b/AlgebraicDataflowArchitectureModel/msrc/Position.java new file mode 100644 index 0000000..6d4133e --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/msrc/Position.java @@ -0,0 +1,21 @@ +import java.util.*; + +public class Position { + private Ground ground; + private Map.Entry value; + public void updateVelocity(Map.Entry velocity) { + Map.Entry temp_l3; + if(((this.ground.getValue()==true)&&((this.value.getValue()+(0.01*velocity.getValue()))<0.0))) { + temp_l3 = new AbstractMap.SimpleEntry<>((this.value.getKey()+(0.01*velocity.getKey())), 0.0); + } else { + temp_l3 = new AbstractMap.SimpleEntry<>((this.value.getKey()+(0.01*velocity.getKey())), (this.value.getValue()+(0.01*velocity.getValue()))); + } + position = temp_l3; + } + public Position(Ground ground) { + this.ground = ground; + } + public Map.Entry getValue() { + return value; + } +} \ No newline at end of file diff --git a/AlgebraicDataflowArchitectureModel/msrc/Time.java b/AlgebraicDataflowArchitectureModel/msrc/Time.java new file mode 100644 index 0000000..e7f6777 --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/msrc/Time.java @@ -0,0 +1,11 @@ +import java.util.*; + +public class Time { + private double value; + public void gravity(double y) { + this.time = (this.value+0.01); + } + public double getValue() { + return value; + } +} \ No newline at end of file diff --git a/AlgebraicDataflowArchitectureModel/msrc/Velocity.java b/AlgebraicDataflowArchitectureModel/msrc/Velocity.java new file mode 100644 index 0000000..5543b75 --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/msrc/Velocity.java @@ -0,0 +1,37 @@ +import java.util.*; + +public class Velocity { + private Map.Entry acceleration; + private Map.Entry move; + private Position position; + private Onground onground; + private Map.Entry value; + public void updateAcceleration(Map.Entry acceleration) { + this.acceleration = acceleration; + Map.Entry temp_l1; + if((this.onground.getValue()&&(this.value.getValue()<0.0))) { + temp_l1 = new AbstractMap.SimpleEntry<>((this.value.getKey()+(0.01*acceleration.getKey())), 0.0); + } else { + temp_l1 = new AbstractMap.SimpleEntry<>((this.value.getKey()+(0.01*acceleration.getKey())), (this.value.getValue()+(0.01*acceleration.getValue()))); + } + velocity = temp_l1; + position.updateVelocity(value); + } + public void updateMove(Map.Entry move) { + this.move = move; + Map.Entry temp_l2; + if((this.onground.getValue()&&(move.getValue()>=0.0))) { + temp_l2 = move; + } else { + temp_l2 = this.value; + } + velocity = temp_l2; + position.updateVelocity(value); + } + public Velocity(Position position, Onground onground) { + this.onground = onground; + } + public Map.Entry getValue() { + return value; + } +} \ No newline at end of file diff --git a/AlgebraicDataflowArchitectureModel/src/algorithms/JavaCodeGenerator.java b/AlgebraicDataflowArchitectureModel/src/algorithms/JavaCodeGenerator.java index c84b252..eea3398 100644 --- a/AlgebraicDataflowArchitectureModel/src/algorithms/JavaCodeGenerator.java +++ b/AlgebraicDataflowArchitectureModel/src/algorithms/JavaCodeGenerator.java @@ -231,11 +231,11 @@ String initializer = "new " + rn.getIdentifierTemplate().getResourceStateType().getImplementationTypeName() + "()"; Type stateType = rn.getIdentifierTemplate().getResourceStateType(); if (!DataConstraintModel.typeList.isAncestorOf(stateType)) initializer = null; - type.addField(new FieldDeclaration(stateType, rn.getIdentifierTemplate().getResourceName(), initializer)); + type.addField(new FieldDeclaration(stateType, "value", initializer)); } // Declare the getter method to obtain the state in the type of each resource. - type.addMethod(new MethodDeclaration("get" + type.getTypeName(), + type.addMethod(new MethodDeclaration("getValue", rn.getIdentifierTemplate().getResourceStateType())); // Add compilation unit for each resource. @@ -423,7 +423,7 @@ @Override public Expression getCurrentStateAccessorFor(IdentifierTemplate target, IdentifierTemplate from) { if (target.equals(from)) { - return new Field(target.getResourceName(), + return new Field("value", target.getResourceStateType() != null ? target.getResourceStateType() : DataConstraintModel.typeInt); } @@ -446,16 +446,14 @@ : DataConstraintModel.typeInt); } // for reference channel member - Term getter = new Term(new Symbol("get" + target.getResourceName().substring(0, 1).toUpperCase() - + target.getResourceName().substring(1), 1, Symbol.Type.METHOD)); + Term getter = new Term(new Symbol("getValue", 1, Symbol.Type.METHOD)); getter.addChild(new Field(target.getResourceName(), target.getResourceStateType())); return getter; } @Override public Expression getNextStateAccessorFor(IdentifierTemplate target, IdentifierTemplate from) { - Term getter = new Term(new Symbol("get" + target.getResourceName().substring(0, 1).toUpperCase() - + target.getResourceName().substring(1), 1, Symbol.Type.METHOD)); + Term getter = new Term(new Symbol("getValue", 1, Symbol.Type.METHOD)); getter.addChild(new Field(target.getResourceName(), target.getResourceStateType())); return getter; } diff --git a/AlgebraicDataflowArchitectureModel/src/algorithms/JavaMethodBodyGenerator.java b/AlgebraicDataflowArchitectureModel/src/algorithms/JavaMethodBodyGenerator.java index 6662ab9..6691254 100644 --- a/AlgebraicDataflowArchitectureModel/src/algorithms/JavaMethodBodyGenerator.java +++ b/AlgebraicDataflowArchitectureModel/src/algorithms/JavaMethodBodyGenerator.java @@ -83,7 +83,7 @@ if (updateExp instanceof Term && ((Term) updateExp).getSymbol().isImplWithSideEffect()) { updateStatement = sideEffects[0]; } else { - updateStatement = sideEffects[0] + dstResourceName + " = " + curState + ";"; + updateStatement = sideEffects[0] + "value = " + curState + ";"; } if (update.getBody() == null || !update.getBody().getStatements().contains(updateStatement)) { update.addFirstStatement(updateStatement); @@ -100,15 +100,15 @@ if (((StoreAttribute) dst.getAttribute()).isStored()) { // returns the current state stored in a field. if (getter.getBody() == null || getter.getBody().getStatements().size() == 0) { - getter.addStatement("return " + dstResourceName + ";"); + getter.addStatement("return value;"); } } // src side (for a chain of update method invocations) for (MethodDeclaration srcUpdate: getUpdateMethods(srcType)) { - srcUpdate.addStatement(dstResourceName + ".update" + srcType.getTypeName() + "(" + srcResourceName + ");"); + srcUpdate.addStatement(dstResourceName + ".update" + srcType.getTypeName() + "(value);"); } MethodDeclaration srcInput = getInputMethod(srcType, src, model); - if (srcInput != null) srcInput.addStatement(dstResourceName + ".update" + srcType.getTypeName() + "(" + srcResourceName + ");"); + if (srcInput != null) srcInput.addStatement(dstResourceName + ".update" + srcType.getTypeName() + "(value);"); } else { // for pull (or push/pull) data transfer MethodDeclaration getter = getGetterMethod(dstType); @@ -155,7 +155,7 @@ // getter method MethodDeclaration getter = getGetterMethod(type); if (getter.getBody() == null || getter.getBody().getStatements().size() == 0) { - getter.addStatement("return " + resource.getIdentifierTemplate().getResourceName() + ";"); + getter.addStatement("return value;"); } // methods for input events Map.Entry> ioChannelAndMembers = getIOChannelAndMembers(resource, model);