Skip to content

Commit

Permalink
ORA-664 implementatio for the math power block
Browse files Browse the repository at this point in the history
  • Loading branch information
cvejoski committed Sep 22, 2015
1 parent 707f84e commit 7080d38
Show file tree
Hide file tree
Showing 15 changed files with 53 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,12 @@ public Void visitBinary(Binary<Void> binary) {
}

@Override
public Void visitFunc(MathPowerFunct<Void> func) {
public Void visitMathPowerFunct(MathPowerFunct<Void> mathPowerFunct) {
this.sb.append("createBinaryExpr(" + mathPowerFunct.getFunctName() + ", ");
mathPowerFunct.getParam().get(0).visit(this);
this.sb.append(", ");
mathPowerFunct.getParam().get(1).visit(this);
this.sb.append(")");
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -441,20 +441,6 @@ public Void visitExprList(ExprList<Void> exprList) {
return null;
}

@Override
public Void visitFunc(MathPowerFunct<Void> funct) {
// switch ( funct.getFunctName() ) {
// case PRINT:
// this.sb.append("System.out.println(");
// funct.getParam().get(0).visit(this);
// this.sb.append(")");
// break;
// default:
// break;
// }
return null;
}

@Override
public Void visitActionStmt(ActionStmt<Void> actionStmt) {
actionStmt.getAction().visit(this);
Expand Down Expand Up @@ -1184,59 +1170,69 @@ public Void visitMathRandomIntFunct(MathRandomIntFunct<Void> mathRandomIntFunct)
public Void visitMathSingleFunct(MathSingleFunct<Void> mathSingleFunct) {
switch ( mathSingleFunct.getFunctName() ) {
case ROOT:
this.sb.append("Math.sqrt(");
this.sb.append("((float) Math.sqrt(");
break;
case ABS:
this.sb.append("Math.abs(");
this.sb.append("((float) Math.abs(");
break;
case LN:
this.sb.append("Math.log(");
this.sb.append("((float) Math.log(");
break;
case LOG10:
this.sb.append("Math.log10(");
this.sb.append("((float) Math.log10(");
break;
case EXP:
this.sb.append("Math.exp(");
this.sb.append("((float) Math.exp(");
break;
case POW10:
this.sb.append("Math.pow(10, ");
this.sb.append("((float) Math.pow(10, ");
break;
case SIN:
this.sb.append("Math.sin(");
this.sb.append("((float) Math.sin(");
break;
case COS:
this.sb.append("Math.cos(");
this.sb.append("((float) Math.cos(");
break;
case TAN:
this.sb.append("Math.tan(");
this.sb.append("((float) Math.tan(");
break;
case ASIN:
this.sb.append("Math.asin(");
this.sb.append("((float) Math.asin(");
break;
case ATAN:
this.sb.append("Math.atan(");
this.sb.append("((float) Math.atan(");
break;
case ACOS:
this.sb.append("Math.acos(");
this.sb.append("((float) Math.acos(");
break;
case ROUND:
this.sb.append("Math.round(");
this.sb.append("((float) Math.round(");
break;
case ROUNDUP:
this.sb.append("Math.ceil(");
this.sb.append("((float) Math.ceil(");
break;
case ROUNDDOWN:
this.sb.append("Math.floor(");
this.sb.append("((float) Math.floor(");
break;
default:
break;
}
mathSingleFunct.getParam().get(0).visit(this);
this.sb.append(")");
this.sb.append("))");

return null;
}

@Override
public Void visitMathPowerFunct(MathPowerFunct<Void> mathPowerFunct) {
this.sb.append("((float) Math.pow(");
mathPowerFunct.getParam().get(0).visit(this);
this.sb.append(", ");
mathPowerFunct.getParam().get(1).visit(this);
this.sb.append("))");
return null;
}

@Override
public Void visitTextJoinFunct(TextJoinFunct<Void> textJoinFunct) {
boolean isFirst = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ public Void visitExprList(ExprList<Void> exprList) {
}

@Override
public Void visitFunc(MathPowerFunct<Void> funct) {
public Void visitMathPowerFunct(MathPowerFunct<Void> mathPowerFunct) {
// switch ( funct.getFunctName() ) {
// case PRINT:
// this.sb.append("System.out.println(");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public V visitBinary(Binary<V> binary) {
}

@Override
public V visitFunc(MathPowerFunct<V> func) {
public V visitMathPowerFunct(MathPowerFunct<V> func) {
return defaultResult();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ public Void visitExprList(ExprList<Void> exprList) {
}

@Override
public Void visitFunc(MathPowerFunct<Void> funct) {
public Void visitMathPowerFunct(MathPowerFunct<Void> funct) {
// switch ( funct.getFunctName() ) {
// case PRINT:
// this.sb.append("System.out.println(");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public Assoc getAssoc() {

@Override
protected V accept(AstVisitor<V> visitor) {
return visitor.visitFunc(this);
return visitor.visitMathPowerFunct(this);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ public Void visitBinary(Binary<Void> binary) {
}

@Override
public Void visitFunc(MathPowerFunct<Void> func) {
for ( Expr<Void> expr : func.getParam() ) {
public Void visitMathPowerFunct(MathPowerFunct<Void> mathPowerFunct) {
for ( Expr<Void> expr : mathPowerFunct.getParam() ) {
expr.visit(this);
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public T visitBinary(Binary<T> binary) {
}

@Override
public T visitFunc(MathPowerFunct<T> func) {
public T visitMathPowerFunct(MathPowerFunct<T> func) {
extractInfos(func);
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ public BlocklyType visitBinary(Binary<BlocklyType> binary) {
}

@Override
public BlocklyType visitFunc(MathPowerFunct<BlocklyType> func) {
public BlocklyType visitMathPowerFunct(MathPowerFunct<BlocklyType> func) {
List<BlocklyType> paramTypes = typecheckList(func.getParam());
Sig signature = TypeTransformations.getFunctionSignature(func.getFunctName().name());
BlocklyType resultType = signature.typeCheck(func, paramTypes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public Void visitBinary(Binary<Void> binary) {
}

@Override
public Void visitFunc(MathPowerFunct<Void> func) {
public Void visitMathPowerFunct(MathPowerFunct<Void> func) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public interface AstVisitor<V> {
*
* @param funct to be visited
*/
public V visitFunc(MathPowerFunct<V> func);
public V visitMathPowerFunct(MathPowerFunct<V> mathPowerFunct);

/**
* visit a {@link ActionExpr}.
Expand Down Expand Up @@ -627,28 +627,28 @@ public interface AstVisitor<V> {
* @param methodStmt to be visited
*/
public V visitMethodCall(MethodCall<V> methodCall);

/**
* visit a {@link BluetoothRecieveAction}.
*
* @param bluetoothReceiveActionbluetoothReceiveAction to be visited
*/
public V visitBluetoothReceiveAction(BluetoothReceiveAction<V> bluetoothReceiveAction);

/**
* visit a {@link BluetoothConnectAction}.
*
* @param bluetoothConnectAction to be visited
*/
public V visitBluetoothConnectAction(BluetoothConnectAction<V> bluetoothConnectAction);

/**
* visit a {@link BluetoothSendAction}.
*
* @param bluetoothSendAction to be visited
*/
public V visitBluetoothSendAction(BluetoothSendAction<V> bluetoothSendAction);

/**
* visit a {@link BluetoothWaitForConnectionAction}.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
public class MathRoundTest {
@Test
public void Test() throws Exception {
String a = "Math.round(0)Math.ceil(0)Math.floor(0)";
String a = "((float)Math.round(0))((float)Math.ceil(0))((float)Math.floor(0))";

Helper.assertCodeIsOk(a, "/syntax/math/math_round.xml");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@
public class MathSingleTest {
@Test
public void Test() throws Exception {
String a = "Math.sqrt(0)Math.abs(0)-0Math.log(0)Math.log10(0)Math.exp(0)Math.pow(10,0)";
String a = "((float)Math.sqrt(0))((float)Math.abs(0))-0((float)Math.log(0))((float)Math.log10(0))((float)Math.exp(0))((float)Math.pow(10,0))";

Helper.assertCodeIsOk(a, "/syntax/math/math_single.xml");
}

@Test
public void Test1() throws Exception {
String a = "hal.setVolume(Math.sqrt(0));";
String a = "hal.setVolume(((float)Math.sqrt(0)));";

Helper.assertCodeIsOk(a, "/syntax/math/math_single1.xml");
}

@Test
public void Test2() throws Exception {
String a = "item=Math.sqrt(0);";
String a = "item=((float)Math.sqrt(0));";

Helper.assertCodeIsOk(a, "/syntax/math/math_single2.xml");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
public class MathTrigTest {
@Test
public void Test() throws Exception {
String a = "Math.sin(0)Math.cos(0)Math.tan(0)Math.asin(0)Math.acos(0)Math.atan(0)";
String a = "((float)Math.sin(0))((float)Math.cos(0))((float)Math.tan(0))((float)Math.asin(0))((float)Math.acos(0))((float)Math.atan(0))";

Helper.assertCodeIsOk(a, "/syntax/math/math_trig.xml");
}

@Test
public void Test1() throws Exception {
String a = "if(0==Math.sin(0)){hal.regulatedDrive(ActorPort.A,ActorPort.B,false,DriveDirection.FOREWARD,Math.acos(0));}";
String a = "if(0==((float)Math.sin(0))){hal.regulatedDrive(ActorPort.A,ActorPort.B,false,DriveDirection.FOREWARD,((float)Math.acos(0)));}";

Helper.assertCodeIsOk(a, "/syntax/math/math_trig1.xml");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ function evalBinary(op, left, right) {
val = valLeft / valRight;
break;
case POWER:
val = valLeft ^ valRight;
val = Math.pow(valLeft, valRight);
break;
case LT:
val = valLeft < valRight;
Expand Down

0 comments on commit 7080d38

Please sign in to comment.