Browse Source

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

kindlich 6 years ago
parent
commit
04899f9247
No known key found for this signature in database

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

2
 
2
 
3
 import org.objectweb.asm.Label;
3
 import org.objectweb.asm.Label;
4
 import org.objectweb.asm.Type;
4
 import org.objectweb.asm.Type;
5
+import org.openzen.zenscript.codemodel.CompareType;
5
 import org.openzen.zenscript.codemodel.expression.*;
6
 import org.openzen.zenscript.codemodel.expression.*;
6
 import org.openzen.zenscript.codemodel.member.DefinitionMember;
7
 import org.openzen.zenscript.codemodel.member.DefinitionMember;
7
 import org.openzen.zenscript.codemodel.type.DefinitionTypeID;
8
 import org.openzen.zenscript.codemodel.type.DefinitionTypeID;
76
     public Void visitCompare(BasicCompareExpression expression) {
77
     public Void visitCompare(BasicCompareExpression expression) {
77
         expression.left.accept(this);
78
         expression.left.accept(this);
78
         expression.right.accept(this);
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
         return null;
85
         return null;
84
     }
86
     }

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

9
     // ###############
9
     // ###############
10
     // ### Compare ###
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
         if (type == CompareType.SAME || type == CompareType.NOTSAME) {
13
         if (type == CompareType.SAME || type == CompareType.NOTSAME) {
17
             final boolean same = a == b;
14
             final boolean same = a == b;
18
             return (type == CompareType.SAME) == same;
15
             return (type == CompareType.SAME) == same;
19
         }
16
         }
20
 
17
 
18
+        //TODO how to compare them?
21
         if (a instanceof Comparable)
19
         if (a instanceof Comparable)
22
             return checkCompareReturn(((Comparable) a).compareTo(b), type);
20
             return checkCompareReturn(((Comparable) a).compareTo(b), type);
23
         return false;
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
     private static boolean checkCompareReturn(int compareResult, CompareType type) {
57
     private static boolean checkCompareReturn(int compareResult, CompareType type) {

Loading…
Cancel
Save