1 package org.simantics.scl.compiler.elaboration.java;
\r
3 import org.cojen.classfile.TypeDesc;
\r
4 import org.objectweb.asm.Label;
\r
5 import org.simantics.scl.compiler.constants.FunctionValue;
\r
6 import org.simantics.scl.compiler.internal.codegen.references.Val;
\r
7 import org.simantics.scl.compiler.internal.codegen.utils.Constants;
\r
8 import org.simantics.scl.compiler.internal.codegen.utils.MethodBuilder;
\r
9 import org.simantics.scl.compiler.types.TVar;
\r
10 import org.simantics.scl.compiler.types.Type;
\r
11 import org.simantics.scl.compiler.types.Types;
\r
12 import org.simantics.scl.compiler.types.kinds.Kinds;
\r
14 public class EqualsFunction extends FunctionValue {
\r
15 private static final TVar A = Types.var(Kinds.STAR);
\r
16 public static final EqualsFunction INSTANCE = new EqualsFunction();
\r
18 private EqualsFunction() {
\r
19 super(new TVar[] {A}, Types.NO_EFFECTS, Types.BOOLEAN, A, A);
\r
23 public Type applyExact(MethodBuilder mb, Val[] parameters) {
\r
24 parameters[0].push(mb);
\r
25 parameters[1].push(mb);
\r
26 TypeDesc parameterType = mb.getJavaTypeTranslator().getTypeDesc(parameters[0]);
\r
27 if(parameterType.isPrimitive()) {
\r
28 if(parameterType.equals(TypeDesc.VOID)) {
\r
29 mb.loadConstant(true);
\r
32 Label end = mb.createLabel();
\r
33 Label isEqual = mb.createLabel();
\r
34 mb.ifComparisonBranch(isEqual, "==", parameterType);
\r
35 mb.loadConstant(false);
\r
37 mb.setLocation(isEqual);
\r
38 mb.loadConstant(true);
\r
39 mb.setLocation(end);
\r
43 mb.invokeStatic("java/util/Objects", "equals", TypeDesc.BOOLEAN, Constants.OBJECTS[2]);
\r
44 return Types.BOOLEAN;
\r