Skip to content

Commit

Permalink
✨ feat: Add NOT for double, float
Browse files Browse the repository at this point in the history
  • Loading branch information
caoccao committed Nov 2, 2024
1 parent d06d51b commit 6dd8d3e
Show file tree
Hide file tree
Showing 3 changed files with 237 additions and 12 deletions.
60 changes: 60 additions & 0 deletions scripts/ts/test/test.logical.operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,14 @@ class Test {
return a != b;
}

public logicalNot_EQEQ_DD_Z(a: double, b: double): boolean {
return !(a === b);
}

public logicalNot_EQEQ_FF_Z(a: float, b: float): boolean {
return !(a === b);
}

public logicalNot_EQEQ_II_Z(a: int, b: int): boolean {
return !(a === b);
}
Expand All @@ -158,6 +166,14 @@ class Test {
return !(a === b);
}

public logicalNot_EQ_DD_Z(a: double, b: double): boolean {
return !(a == b);
}

public logicalNot_EQ_FF_Z(a: float, b: float): boolean {
return !(a == b);
}

public logicalNot_EQ_II_Z(a: int, b: int): boolean {
return !(a == b);
}
Expand All @@ -166,6 +182,14 @@ class Test {
return !(a == b);
}

public logicalNot_GE_DD_Z(a: double, b: double): boolean {
return !(a >= b);
}

public logicalNot_GE_FF_Z(a: float, b: float): boolean {
return !(a >= b);
}

public logicalNot_GE_II_Z(a: int, b: int): boolean {
return !(a >= b);
}
Expand All @@ -174,6 +198,14 @@ class Test {
return !(a >= b);
}

public logicalNot_GT_DD_Z(a: double, b: double): boolean {
return !(a > b);
}

public logicalNot_GT_FF_Z(a: float, b: float): boolean {
return !(a > b);
}

public logicalNot_GT_II_Z(a: int, b: int): boolean {
return !(a > b);
}
Expand All @@ -182,6 +214,14 @@ class Test {
return !(a > b);
}

public logicalNot_LE_DD_Z(a: double, b: double): boolean {
return !(a <= b);
}

public logicalNot_LE_FF_Z(a: float, b: float): boolean {
return !(a <= b);
}

public logicalNot_LE_II_Z(a: int, b: int): boolean {
return !(a <= b);
}
Expand All @@ -190,6 +230,14 @@ class Test {
return !(a <= b);
}

public logicalNot_LT_DD_Z(a: double, b: double): boolean {
return !(a < b);
}

public logicalNot_LT_FF_Z(a: float, b: float): boolean {
return !(a < b);
}

public logicalNot_LT_II_Z(a: int, b: int): boolean {
return !(a < b);
}
Expand Down Expand Up @@ -234,15 +282,27 @@ console.log(new Test().logicalNotEQ_DD_Z(1, 2));
console.log(new Test().logicalNotEQ_FF_Z(1, 2));
console.log(new Test().logicalNotEQ_II_Z(1, 2));
console.log(new Test().logicalNotEQ_IL_Z(1, 2));
console.log(new Test().logicalNot_EQEQ_DD_Z(1, 2));
console.log(new Test().logicalNot_EQEQ_FF_Z(1, 2));
console.log(new Test().logicalNot_EQEQ_II_Z(1, 2));
console.log(new Test().logicalNot_EQEQ_IL_Z(1, 2));
console.log(new Test().logicalNot_EQ_DD_Z(1, 2));
console.log(new Test().logicalNot_EQ_FF_Z(1, 2));
console.log(new Test().logicalNot_EQ_II_Z(1, 2));
console.log(new Test().logicalNot_EQ_IL_Z(1, 2));
console.log(new Test().logicalNot_GE_DD_Z(1, 2));
console.log(new Test().logicalNot_GE_FF_Z(1, 2));
console.log(new Test().logicalNot_GE_II_Z(1, 2));
console.log(new Test().logicalNot_GE_IL_Z(1, 2));
console.log(new Test().logicalNot_GT_DD_Z(1, 2));
console.log(new Test().logicalNot_GT_FF_Z(1, 2));
console.log(new Test().logicalNot_GT_II_Z(1, 2));
console.log(new Test().logicalNot_GT_IL_Z(1, 2));
console.log(new Test().logicalNot_LT_DD_Z(1, 2));
console.log(new Test().logicalNot_LT_FF_Z(1, 2));
console.log(new Test().logicalNot_LT_II_Z(1, 2));
console.log(new Test().logicalNot_LT_IL_Z(1, 2));
console.log(new Test().logicalNot_LE_DD_Z(1, 2));
console.log(new Test().logicalNot_LE_FF_Z(1, 2));
console.log(new Test().logicalNot_LE_II_Z(1, 2));
console.log(new Test().logicalNot_LE_IL_Z(1, 2));
Original file line number Diff line number Diff line change
Expand Up @@ -169,29 +169,29 @@ public static StackManipulation getLogical(
switch (binaryOp) {
case Gt:
opcodeCompare1 = Opcodes.FCMPL;
opcodeCompare2 = Opcodes.IFLE;
opcodeCompare2 = logicalNot ? Opcodes.IFGT : Opcodes.IFLE;
break;
case GtEq:
opcodeCompare1 = Opcodes.FCMPL;
opcodeCompare2 = Opcodes.IFLT;
opcodeCompare2 = logicalNot ? Opcodes.IFGE : Opcodes.IFLT;
break;
case Lt:
opcodeCompare1 = Opcodes.FCMPG;
opcodeCompare2 = Opcodes.IFGE;
opcodeCompare2 = logicalNot ? Opcodes.IFLT : Opcodes.IFGE;
break;
case LtEq:
opcodeCompare1 = Opcodes.FCMPG;
opcodeCompare2 = Opcodes.IFGT;
opcodeCompare2 = logicalNot ? Opcodes.IFLE : Opcodes.IFGT;
break;
case EqEq:
case EqEqEq:
opcodeCompare1 = Opcodes.FCMPL;
opcodeCompare2 = Opcodes.IFNE;
opcodeCompare2 = logicalNot ? Opcodes.IFEQ : Opcodes.IFNE;
break;
case NotEq:
case NotEqEq:
opcodeCompare1 = Opcodes.FCMPL;
opcodeCompare2 = Opcodes.IFEQ;
opcodeCompare2 = logicalNot ? Opcodes.IFNE : Opcodes.IFEQ;
break;
default:
throw new Ts2JavaException(
Expand All @@ -211,29 +211,29 @@ public static StackManipulation getLogical(
switch (binaryOp) {
case Gt:
opcodeCompare1 = Opcodes.DCMPL;
opcodeCompare2 = Opcodes.IFLE;
opcodeCompare2 = logicalNot ? Opcodes.IFGT : Opcodes.IFLE;
break;
case GtEq:
opcodeCompare1 = Opcodes.DCMPL;
opcodeCompare2 = Opcodes.IFLT;
opcodeCompare2 = logicalNot ? Opcodes.IFGE : Opcodes.IFLT;
break;
case Lt:
opcodeCompare1 = Opcodes.DCMPG;
opcodeCompare2 = Opcodes.IFGE;
opcodeCompare2 = logicalNot ? Opcodes.IFLT : Opcodes.IFGE;
break;
case LtEq:
opcodeCompare1 = Opcodes.DCMPG;
opcodeCompare2 = Opcodes.IFGT;
opcodeCompare2 = logicalNot ? Opcodes.IFLE : Opcodes.IFGT;
break;
case EqEq:
case EqEqEq:
opcodeCompare1 = Opcodes.DCMPL;
opcodeCompare2 = Opcodes.IFNE;
opcodeCompare2 = logicalNot ? Opcodes.IFEQ : Opcodes.IFNE;
break;
case NotEq:
case NotEqEq:
opcodeCompare1 = Opcodes.DCMPL;
opcodeCompare2 = Opcodes.IFEQ;
opcodeCompare2 = logicalNot ? Opcodes.IFNE : Opcodes.IFEQ;
break;
default:
throw new Ts2JavaException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,36 @@ public void testLogicalNotEQ_IL_Z() throws Exception {
assertFalse((boolean) method.invoke(object, 1, 1L));
}

@Test
public void testLogicalNot_EQEQ_DD_Z() throws Exception {
Method method = clazz.getMethod("logicalNot_EQEQ_DD_Z", double.class, double.class);
assertNotNull(method);
assertEquals(boolean.class, method.getReturnType());
assertEquals(2, method.getParameterCount());
assertEquals(double.class, method.getParameters()[0].getType());
assertEquals(double.class, method.getParameters()[1].getType());
Object object = clazz.getConstructor().newInstance();
assertTrue((boolean) method.invoke(object, 1D, 2D));
assertTrue((boolean) method.invoke(object, 2D, 1D));
assertFalse((boolean) method.invoke(object, 1D, 1D));
assertFalse((boolean) method.invoke(object, 1.23D, 1.23D));
}

@Test
public void testLogicalNot_EQEQ_FF_Z() throws Exception {
Method method = clazz.getMethod("logicalNot_EQEQ_FF_Z", float.class, float.class);
assertNotNull(method);
assertEquals(boolean.class, method.getReturnType());
assertEquals(2, method.getParameterCount());
assertEquals(float.class, method.getParameters()[0].getType());
assertEquals(float.class, method.getParameters()[1].getType());
Object object = clazz.getConstructor().newInstance();
assertTrue((boolean) method.invoke(object, 1F, 2F));
assertTrue((boolean) method.invoke(object, 2F, 1F));
assertFalse((boolean) method.invoke(object, 1F, 1F));
assertFalse((boolean) method.invoke(object, 1.23F, 1.23F));
}

@Test
public void testLogicalNot_EQEQ_II_Z() throws Exception {
Method method = clazz.getMethod("logicalNot_EQEQ_II_Z", int.class, int.class);
Expand Down Expand Up @@ -793,6 +823,36 @@ public void testLogicalNot_EQEQ_IL_Z() throws Exception {
assertFalse((boolean) method.invoke(object, 1, 1L));
}

@Test
public void testLogicalNot_EQ_DD_Z() throws Exception {
Method method = clazz.getMethod("logicalNot_EQ_DD_Z", double.class, double.class);
assertNotNull(method);
assertEquals(boolean.class, method.getReturnType());
assertEquals(2, method.getParameterCount());
assertEquals(double.class, method.getParameters()[0].getType());
assertEquals(double.class, method.getParameters()[1].getType());
Object object = clazz.getConstructor().newInstance();
assertTrue((boolean) method.invoke(object, 1D, 2D));
assertTrue((boolean) method.invoke(object, 2D, 1D));
assertFalse((boolean) method.invoke(object, 1D, 1D));
assertFalse((boolean) method.invoke(object, 1.23D, 1.23D));
}

@Test
public void testLogicalNot_EQ_FF_Z() throws Exception {
Method method = clazz.getMethod("logicalNot_EQ_FF_Z", float.class, float.class);
assertNotNull(method);
assertEquals(boolean.class, method.getReturnType());
assertEquals(2, method.getParameterCount());
assertEquals(float.class, method.getParameters()[0].getType());
assertEquals(float.class, method.getParameters()[1].getType());
Object object = clazz.getConstructor().newInstance();
assertTrue((boolean) method.invoke(object, 1F, 2F));
assertTrue((boolean) method.invoke(object, 2F, 1F));
assertFalse((boolean) method.invoke(object, 1F, 1F));
assertFalse((boolean) method.invoke(object, 1.23F, 1.23F));
}

@Test
public void testLogicalNot_EQ_II_Z() throws Exception {
assertTrue(logicalNot_EQ_II_Z(1, 2));
Expand Down Expand Up @@ -822,6 +882,36 @@ public void testLogicalNot_EQ_IL_Z() throws Exception {
assertFalse((boolean) method.invoke(object, 1, 1L));
}

@Test
public void testLogicalNot_GE_DD_Z() throws Exception {
Method method = clazz.getMethod("logicalNot_GE_DD_Z", double.class, double.class);
assertNotNull(method);
assertEquals(boolean.class, method.getReturnType());
assertEquals(2, method.getParameterCount());
assertEquals(double.class, method.getParameters()[0].getType());
assertEquals(double.class, method.getParameters()[1].getType());
Object object = clazz.getConstructor().newInstance();
assertTrue((boolean) method.invoke(object, 1D, 2D));
assertFalse((boolean) method.invoke(object, 2D, 1D));
assertFalse((boolean) method.invoke(object, 1D, 1D));
assertFalse((boolean) method.invoke(object, 1.23D, 1.23D));
}

@Test
public void testLogicalNot_GE_FF_Z() throws Exception {
Method method = clazz.getMethod("logicalNot_GE_FF_Z", float.class, float.class);
assertNotNull(method);
assertEquals(boolean.class, method.getReturnType());
assertEquals(2, method.getParameterCount());
assertEquals(float.class, method.getParameters()[0].getType());
assertEquals(float.class, method.getParameters()[1].getType());
Object object = clazz.getConstructor().newInstance();
assertTrue((boolean) method.invoke(object, 1F, 2F));
assertFalse((boolean) method.invoke(object, 2F, 1F));
assertFalse((boolean) method.invoke(object, 1F, 1F));
assertFalse((boolean) method.invoke(object, 1.23F, 1.23F));
}

@Test
public void testLogicalNot_GE_II_Z() throws Exception {
Method method = clazz.getMethod("logicalNot_GE_II_Z", int.class, int.class);
Expand Down Expand Up @@ -850,6 +940,21 @@ public void testLogicalNot_GE_IL_Z() throws Exception {
assertFalse((boolean) method.invoke(object, 1, 1L));
}

@Test
public void testLogicalNot_GT_DD_Z() throws Exception {
Method method = clazz.getMethod("logicalNot_GT_DD_Z", double.class, double.class);
assertNotNull(method);
assertEquals(boolean.class, method.getReturnType());
assertEquals(2, method.getParameterCount());
assertEquals(double.class, method.getParameters()[0].getType());
assertEquals(double.class, method.getParameters()[1].getType());
Object object = clazz.getConstructor().newInstance();
assertTrue((boolean) method.invoke(object, 1D, 2D));
assertFalse((boolean) method.invoke(object, 2D, 1D));
assertTrue((boolean) method.invoke(object, 1D, 1D));
assertTrue((boolean) method.invoke(object, 1.23D, 1.23D));
}

@Test
public void testLogicalNot_GT_II_Z() throws Exception {
Method method = clazz.getMethod("logicalNot_GT_II_Z", int.class, int.class);
Expand Down Expand Up @@ -878,6 +983,36 @@ public void testLogicalNot_GT_IL_Z() throws Exception {
assertTrue((boolean) method.invoke(object, 1, 1L));
}

@Test
public void testLogicalNot_LE_DD_Z() throws Exception {
Method method = clazz.getMethod("logicalNot_LE_DD_Z", double.class, double.class);
assertNotNull(method);
assertEquals(boolean.class, method.getReturnType());
assertEquals(2, method.getParameterCount());
assertEquals(double.class, method.getParameters()[0].getType());
assertEquals(double.class, method.getParameters()[1].getType());
Object object = clazz.getConstructor().newInstance();
assertFalse((boolean) method.invoke(object, 1D, 2D));
assertTrue((boolean) method.invoke(object, 2D, 1D));
assertFalse((boolean) method.invoke(object, 1D, 1D));
assertFalse((boolean) method.invoke(object, 1.23D, 1.23D));
}

@Test
public void testLogicalNot_LE_FF_Z() throws Exception {
Method method = clazz.getMethod("logicalNot_LE_FF_Z", float.class, float.class);
assertNotNull(method);
assertEquals(boolean.class, method.getReturnType());
assertEquals(2, method.getParameterCount());
assertEquals(float.class, method.getParameters()[0].getType());
assertEquals(float.class, method.getParameters()[1].getType());
Object object = clazz.getConstructor().newInstance();
assertFalse((boolean) method.invoke(object, 1F, 2F));
assertTrue((boolean) method.invoke(object, 2F, 1F));
assertFalse((boolean) method.invoke(object, 1F, 1F));
assertFalse((boolean) method.invoke(object, 1.23F, 1.23F));
}

@Test
public void testLogicalNot_LE_II_Z() throws Exception {
Method method = clazz.getMethod("logicalNot_LE_II_Z", int.class, int.class);
Expand Down Expand Up @@ -906,6 +1041,36 @@ public void testLogicalNot_LE_IL_Z() throws Exception {
assertFalse((boolean) method.invoke(object, 1, 1L));
}

@Test
public void testLogicalNot_LT_DD_Z() throws Exception {
Method method = clazz.getMethod("logicalNot_LT_DD_Z", double.class, double.class);
assertNotNull(method);
assertEquals(boolean.class, method.getReturnType());
assertEquals(2, method.getParameterCount());
assertEquals(double.class, method.getParameters()[0].getType());
assertEquals(double.class, method.getParameters()[1].getType());
Object object = clazz.getConstructor().newInstance();
assertFalse((boolean) method.invoke(object, 1D, 2D));
assertTrue((boolean) method.invoke(object, 2D, 1D));
assertTrue((boolean) method.invoke(object, 1D, 1D));
assertTrue((boolean) method.invoke(object, 1.23D, 1.23D));
}

@Test
public void testLogicalNot_LT_FF_Z() throws Exception {
Method method = clazz.getMethod("logicalNot_LT_FF_Z", float.class, float.class);
assertNotNull(method);
assertEquals(boolean.class, method.getReturnType());
assertEquals(2, method.getParameterCount());
assertEquals(float.class, method.getParameters()[0].getType());
assertEquals(float.class, method.getParameters()[1].getType());
Object object = clazz.getConstructor().newInstance();
assertFalse((boolean) method.invoke(object, 1F, 2F));
assertTrue((boolean) method.invoke(object, 2F, 1F));
assertTrue((boolean) method.invoke(object, 1F, 1F));
assertTrue((boolean) method.invoke(object, 1.23F, 1.23F));
}

@Test
public void testLogicalNot_LT_II_Z() throws Exception {
Method method = clazz.getMethod("logicalNot_LT_II_Z", int.class, int.class);
Expand Down

0 comments on commit 6dd8d3e

Please sign in to comment.