Skip to content

Commit

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

public logicalNot_EQEQ_IL_Z(a: int, b: long): boolean {
return !(a === b);
}

public logicalNot_EQ_II_Z(a: int, b: int): boolean {
return !(a == b);
}

public logicalNot_EQ_IL_Z(a: int, b: long): boolean {
return !(a == b);
}

public logicalNot_GE_II_Z(a: int, b: int): boolean {
return !(a >= b);
}

public logicalNot_GE_IL_Z(a: int, b: long): boolean {
return !(a >= b);
}

public logicalNot_GT_II_Z(a: int, b: int): boolean {
return !(a > b);
}

public logicalNot_GT_IL_Z(a: int, b: long): boolean {
return !(a > b);
}

public logicalNot_LE_II_Z(a: int, b: int): boolean {
return !(a <= b);
}

public logicalNot_LE_IL_Z(a: int, b: long): boolean {
return !(a <= b);
}

public logicalNot_LT_II_Z(a: int, b: int): boolean {
return !(a < b);
}

public logicalNot_LT_IL_Z(a: int, b: long): boolean {
return !(a < b);
}
}

console.log(new Test().logicalEQEQ_DD_Z(1, 2));
Expand Down Expand Up @@ -211,8 +235,14 @@ 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_II_Z(1, 2));
console.log(new Test().logicalNot_EQEQ_IL_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_II_Z(1, 2));
console.log(new Test().logicalNot_GE_IL_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_II_Z(1, 2));
console.log(new Test().logicalNot_LT_IL_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 @@ -132,24 +132,24 @@ public static StackManipulation getLogical(
int opcodeCompare;
switch (binaryOp) {
case Gt:
opcodeCompare = Opcodes.IFLE;
opcodeCompare = logicalNot ? Opcodes.IFGT : Opcodes.IFLE;
break;
case GtEq:
opcodeCompare = Opcodes.IFLT;
opcodeCompare = logicalNot ? Opcodes.IFGE : Opcodes.IFLT;
break;
case Lt:
opcodeCompare = Opcodes.IFGE;
opcodeCompare = logicalNot ? Opcodes.IFLT : Opcodes.IFGE;
break;
case LtEq:
opcodeCompare = Opcodes.IFGT;
opcodeCompare = logicalNot ? Opcodes.IFLE : Opcodes.IFGT;
break;
case EqEq:
case EqEqEq:
opcodeCompare = Opcodes.IFNE;
opcodeCompare = logicalNot ? Opcodes.IFEQ : Opcodes.IFNE;
break;
case NotEq:
case NotEqEq:
opcodeCompare = Opcodes.IFEQ;
opcodeCompare = logicalNot ? Opcodes.IFNE : Opcodes.IFEQ;
break;
default:
throw new Ts2JavaException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,20 @@ public void testLogicalNot_EQEQ_II_Z() throws Exception {
assertFalse((boolean) method.invoke(object, 1, 1));
}

@Test
public void testLogicalNot_EQEQ_IL_Z() throws Exception {
Method method = clazz.getMethod("logicalNot_EQEQ_IL_Z", int.class, long.class);
assertNotNull(method);
assertEquals(boolean.class, method.getReturnType());
assertEquals(2, method.getParameterCount());
assertEquals(int.class, method.getParameters()[0].getType());
assertEquals(long.class, method.getParameters()[1].getType());
Object object = clazz.getConstructor().newInstance();
assertTrue((boolean) method.invoke(object, 1, 2L));
assertTrue((boolean) method.invoke(object, 2, 1L));
assertFalse((boolean) method.invoke(object, 1, 1L));
}

@Test
public void testLogicalNot_EQ_II_Z() throws Exception {
assertTrue(logicalNot_EQ_II_Z(1, 2));
Expand All @@ -794,6 +808,20 @@ public void testLogicalNot_EQ_II_Z() throws Exception {
assertFalse((boolean) method.invoke(object, 1, 1));
}

@Test
public void testLogicalNot_EQ_IL_Z() throws Exception {
Method method = clazz.getMethod("logicalNot_EQ_IL_Z", int.class, long.class);
assertNotNull(method);
assertEquals(boolean.class, method.getReturnType());
assertEquals(2, method.getParameterCount());
assertEquals(int.class, method.getParameters()[0].getType());
assertEquals(long.class, method.getParameters()[1].getType());
Object object = clazz.getConstructor().newInstance();
assertTrue((boolean) method.invoke(object, 1, 2L));
assertTrue((boolean) method.invoke(object, 2, 1L));
assertFalse((boolean) method.invoke(object, 1, 1L));
}

@Test
public void testLogicalNot_GE_II_Z() throws Exception {
Method method = clazz.getMethod("logicalNot_GE_II_Z", int.class, int.class);
Expand All @@ -808,6 +836,20 @@ public void testLogicalNot_GE_II_Z() throws Exception {
assertFalse((boolean) method.invoke(object, 1, 1));
}

@Test
public void testLogicalNot_GE_IL_Z() throws Exception {
Method method = clazz.getMethod("logicalNot_GE_IL_Z", int.class, long.class);
assertNotNull(method);
assertEquals(boolean.class, method.getReturnType());
assertEquals(2, method.getParameterCount());
assertEquals(int.class, method.getParameters()[0].getType());
assertEquals(long.class, method.getParameters()[1].getType());
Object object = clazz.getConstructor().newInstance();
assertTrue((boolean) method.invoke(object, 1, 2L));
assertFalse((boolean) method.invoke(object, 2, 1L));
assertFalse((boolean) method.invoke(object, 1, 1L));
}

@Test
public void testLogicalNot_GT_II_Z() throws Exception {
Method method = clazz.getMethod("logicalNot_GT_II_Z", int.class, int.class);
Expand All @@ -822,6 +864,20 @@ public void testLogicalNot_GT_II_Z() throws Exception {
assertTrue((boolean) method.invoke(object, 1, 1));
}

@Test
public void testLogicalNot_GT_IL_Z() throws Exception {
Method method = clazz.getMethod("logicalNot_GT_IL_Z", int.class, long.class);
assertNotNull(method);
assertEquals(boolean.class, method.getReturnType());
assertEquals(2, method.getParameterCount());
assertEquals(int.class, method.getParameters()[0].getType());
assertEquals(long.class, method.getParameters()[1].getType());
Object object = clazz.getConstructor().newInstance();
assertTrue((boolean) method.invoke(object, 1, 2L));
assertFalse((boolean) method.invoke(object, 2, 1L));
assertTrue((boolean) method.invoke(object, 1, 1L));
}

@Test
public void testLogicalNot_LE_II_Z() throws Exception {
Method method = clazz.getMethod("logicalNot_LE_II_Z", int.class, int.class);
Expand All @@ -836,6 +892,20 @@ public void testLogicalNot_LE_II_Z() throws Exception {
assertFalse((boolean) method.invoke(object, 1, 1));
}

@Test
public void testLogicalNot_LE_IL_Z() throws Exception {
Method method = clazz.getMethod("logicalNot_LE_IL_Z", int.class, long.class);
assertNotNull(method);
assertEquals(boolean.class, method.getReturnType());
assertEquals(2, method.getParameterCount());
assertEquals(int.class, method.getParameters()[0].getType());
assertEquals(long.class, method.getParameters()[1].getType());
Object object = clazz.getConstructor().newInstance();
assertFalse((boolean) method.invoke(object, 1, 2L));
assertTrue((boolean) method.invoke(object, 2, 1L));
assertFalse((boolean) method.invoke(object, 1, 1L));
}

@Test
public void testLogicalNot_LT_II_Z() throws Exception {
Method method = clazz.getMethod("logicalNot_LT_II_Z", int.class, int.class);
Expand All @@ -849,4 +919,18 @@ public void testLogicalNot_LT_II_Z() throws Exception {
assertTrue((boolean) method.invoke(object, 2, 1));
assertTrue((boolean) method.invoke(object, 1, 1));
}

@Test
public void testLogicalNot_LT_IL_Z() throws Exception {
Method method = clazz.getMethod("logicalNot_LT_IL_Z", int.class, long.class);
assertNotNull(method);
assertEquals(boolean.class, method.getReturnType());
assertEquals(2, method.getParameterCount());
assertEquals(int.class, method.getParameters()[0].getType());
assertEquals(long.class, method.getParameters()[1].getType());
Object object = clazz.getConstructor().newInstance();
assertFalse((boolean) method.invoke(object, 1, 2L));
assertTrue((boolean) method.invoke(object, 2, 1L));
assertTrue((boolean) method.invoke(object, 1, 1L));
}
}

0 comments on commit d06d51b

Please sign in to comment.