Quellcode durchsuchen

Compares will now use the compare fields directly instead of the type name

kindlich vor 6 Jahren
Ursprung
Commit
04899f9247
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden

+ 4
- 2
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaExpressionVisitor.java Datei anzeigen

@@ -2,6 +2,7 @@ package org.openzen.zenscript.javabytecode.compiler;
2 2
 
3 3
 import org.objectweb.asm.Label;
4 4
 import org.objectweb.asm.Type;
5
+import org.openzen.zenscript.codemodel.CompareType;
5 6
 import org.openzen.zenscript.codemodel.expression.*;
6 7
 import org.openzen.zenscript.codemodel.member.DefinitionMember;
7 8
 import org.openzen.zenscript.codemodel.type.DefinitionTypeID;
@@ -76,9 +77,10 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
76 77
     public Void visitCompare(BasicCompareExpression expression) {
77 78
         expression.left.accept(this);
78 79
         expression.right.accept(this);
79
-        javaWriter.constant(expression.operator.name());
80
+        final Type operatorType = Type.getType(CompareType.class);
81
+        javaWriter.getStaticField(operatorType.getInternalName(), expression.operator.name(), operatorType.getDescriptor());
80 82
 
81
-        javaWriter.invokeStatic(ZenUtils.class, "compare", boolean.class, getForEquals(expression.left.type), getForEquals(expression.right.type), String.class);
83
+        javaWriter.invokeStatic(ZenUtils.class, "compare", boolean.class, getForEquals(expression.left.type), getForEquals(expression.right.type), CompareType.class);
82 84
 
83 85
         return null;
84 86
     }

+ 18
- 20
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/ZenUtils.java Datei anzeigen

@@ -9,51 +9,49 @@ public class ZenUtils {
9 9
     // ###############
10 10
     // ### Compare ###
11 11
     // ###############
12
-
13
-    //TODO how to compare them?
14
-    public static boolean compare(Object a, Object b, String compareType) {
15
-        CompareType type = CompareType.valueOf(compareType);
12
+    public static boolean compare(Object a, Object b, CompareType type) {
16 13
         if (type == CompareType.SAME || type == CompareType.NOTSAME) {
17 14
             final boolean same = a == b;
18 15
             return (type == CompareType.SAME) == same;
19 16
         }
20 17
 
18
+        //TODO how to compare them?
21 19
         if (a instanceof Comparable)
22 20
             return checkCompareReturn(((Comparable) a).compareTo(b), type);
23 21
         return false;
24 22
     }
25 23
 
26 24
 
27
-    public static boolean compare(boolean a, boolean b, String compareType) {
28
-        return checkCompareReturn(Boolean.compare(a, b), CompareType.valueOf(compareType));
25
+    public static boolean compare(boolean a, boolean b, CompareType compareType) {
26
+        return checkCompareReturn(Boolean.compare(a, b), compareType);
29 27
     }
30 28
 
31
-    public static boolean compare(int a, int b, String compareType) {
32
-        return checkCompareReturn(Integer.compare(a, b), CompareType.valueOf(compareType));
29
+    public static boolean compare(int a, int b, CompareType compareType) {
30
+        return checkCompareReturn(Integer.compare(a, b), compareType);
33 31
     }
34 32
 
35
-    public static boolean compare(char a, char b, String compareType) {
36
-        return checkCompareReturn(Character.compare(a, b), CompareType.valueOf(compareType));
33
+    public static boolean compare(char a, char b, CompareType compareType) {
34
+        return checkCompareReturn(Character.compare(a, b), compareType);
37 35
     }
38 36
 
39
-    public static boolean compare(byte a, byte b, String compareType) {
40
-        return checkCompareReturn(Byte.compare(a, b), CompareType.valueOf(compareType));
37
+    public static boolean compare(byte a, byte b, CompareType compareType) {
38
+        return checkCompareReturn(Byte.compare(a, b), compareType);
41 39
     }
42 40
 
43
-    public static boolean compare(short a, short b, String compareType) {
44
-        return checkCompareReturn(Short.compare(a, b), CompareType.valueOf(compareType));
41
+    public static boolean compare(short a, short b, CompareType compareType) {
42
+        return checkCompareReturn(Short.compare(a, b), compareType);
45 43
     }
46 44
 
47
-    public static boolean compare(long a, long b, String compareType) {
48
-        return checkCompareReturn(Long.compare(a, b), CompareType.valueOf(compareType));
45
+    public static boolean compare(long a, long b, CompareType compareType) {
46
+        return checkCompareReturn(Long.compare(a, b), compareType);
49 47
     }
50 48
 
51
-    public static boolean compare(float a, float b, String compareType) {
52
-        return checkCompareReturn(Float.compare(a, b), CompareType.valueOf(compareType));
49
+    public static boolean compare(float a, float b, CompareType compareType) {
50
+        return checkCompareReturn(Float.compare(a, b), compareType);
53 51
     }
54 52
 
55
-    public static boolean compare(double a, double b, String compareType) {
56
-        return checkCompareReturn(Double.compare(a, b), CompareType.valueOf(compareType));
53
+    public static boolean compare(double a, double b, CompareType compareType) {
54
+        return checkCompareReturn(Double.compare(a, b), compareType);
57 55
     }
58 56
 
59 57
     private static boolean checkCompareReturn(int compareResult, CompareType type) {

Laden…
Abbrechen
Speichern