-package org.simantics.scl.compiler.elaboration.java;\r
-\r
-import org.cojen.classfile.TypeDesc;\r
-import org.simantics.scl.compiler.constants.FunctionValue;\r
-import org.simantics.scl.compiler.internal.codegen.references.Val;\r
-import org.simantics.scl.compiler.internal.codegen.utils.Constants;\r
-import org.simantics.scl.compiler.internal.codegen.utils.MethodBuilder;\r
-import org.simantics.scl.compiler.types.TVar;\r
-import org.simantics.scl.compiler.types.Type;\r
-import org.simantics.scl.compiler.types.Types;\r
-import org.simantics.scl.compiler.types.kinds.Kinds;\r
-\r
-public class HashCodeFunction extends FunctionValue {\r
- private static final TVar A = Types.var(Kinds.STAR);\r
- public static final HashCodeFunction INSTANCE = new HashCodeFunction();\r
- \r
- private HashCodeFunction() {\r
- super(new TVar[] {A}, Types.NO_EFFECTS, Types.INTEGER, A);\r
- }\r
-\r
- @Override\r
- public Type applyExact(MethodBuilder mb, Val[] parameters) {\r
- TypeDesc parameterType = mb.getJavaTypeTranslator().getTypeDesc(parameters[0]);\r
- parameters[0].push(mb);\r
- switch(parameterType.getTypeCode()) {\r
- case TypeDesc.VOID_CODE:\r
- mb.loadStaticField(Constants.TUPLE0, "INSTANCE", Constants.TUPLE0);\r
- mb.invokeVirtual("java/lang/Object", "hashCode", TypeDesc.INT, Constants.OBJECTS[1]);\r
- break;\r
- case TypeDesc.OBJECT_CODE:\r
- mb.invokeStatic("java/util/Objects", "hashCode", TypeDesc.INT, Constants.OBJECTS[1]);\r
- break;\r
- case TypeDesc.INT_CODE:\r
- mb.invokeStatic("java/lang/Integer", "hashCode", TypeDesc.INT, new TypeDesc[] {TypeDesc.INT});\r
- break;\r
- case TypeDesc.LONG_CODE:\r
- mb.invokeStatic("java/lang/Long", "hashCode", TypeDesc.LONG, new TypeDesc[] {TypeDesc.LONG});\r
- break;\r
- case TypeDesc.DOUBLE_CODE:\r
- mb.invokeStatic("java/lang/Double", "hashCode", TypeDesc.DOUBLE, new TypeDesc[] {TypeDesc.DOUBLE});\r
- break;\r
- case TypeDesc.FLOAT_CODE:\r
- mb.invokeStatic("java/lang/Float", "hashCode", TypeDesc.FLOAT, new TypeDesc[] {TypeDesc.FLOAT});\r
- break;\r
- case TypeDesc.SHORT_CODE:\r
- mb.invokeStatic("java/lang/Short", "hashCode", TypeDesc.SHORT, new TypeDesc[] {TypeDesc.SHORT});\r
- break;\r
- }\r
- return Types.INTEGER;\r
- }\r
-}\r
+package org.simantics.scl.compiler.elaboration.java;
+
+import org.cojen.classfile.TypeDesc;
+import org.simantics.scl.compiler.constants.FunctionValue;
+import org.simantics.scl.compiler.internal.codegen.references.Val;
+import org.simantics.scl.compiler.internal.codegen.utils.Constants;
+import org.simantics.scl.compiler.internal.codegen.utils.MethodBuilder;
+import org.simantics.scl.compiler.types.TVar;
+import org.simantics.scl.compiler.types.Type;
+import org.simantics.scl.compiler.types.Types;
+import org.simantics.scl.compiler.types.kinds.Kinds;
+
+public class HashCodeFunction extends FunctionValue {
+ private static final TVar A = Types.var(Kinds.STAR);
+ public static final HashCodeFunction INSTANCE = new HashCodeFunction();
+
+ private HashCodeFunction() {
+ super(new TVar[] {A}, Types.NO_EFFECTS, Types.INTEGER, A);
+ }
+
+ @Override
+ public Type applyExact(MethodBuilder mb, Val[] parameters) {
+ TypeDesc parameterType = mb.getJavaTypeTranslator().getTypeDesc(parameters[0]);
+ parameters[0].push(mb);
+ switch(parameterType.getTypeCode()) {
+ case TypeDesc.VOID_CODE:
+ mb.loadStaticField(Constants.TUPLE0, "INSTANCE", Constants.TUPLE0);
+ mb.invokeVirtual("java/lang/Object", "hashCode", TypeDesc.INT, Constants.OBJECTS[1]);
+ break;
+ case TypeDesc.OBJECT_CODE:
+ mb.invokeStatic("java/util/Objects", "hashCode", TypeDesc.INT, Constants.OBJECTS[1]);
+ break;
+ case TypeDesc.INT_CODE:
+ mb.invokeStatic("java/lang/Integer", "hashCode", TypeDesc.INT, new TypeDesc[] {TypeDesc.INT});
+ break;
+ case TypeDesc.LONG_CODE:
+ mb.invokeStatic("java/lang/Long", "hashCode", TypeDesc.LONG, new TypeDesc[] {TypeDesc.LONG});
+ break;
+ case TypeDesc.DOUBLE_CODE:
+ mb.invokeStatic("java/lang/Double", "hashCode", TypeDesc.DOUBLE, new TypeDesc[] {TypeDesc.DOUBLE});
+ break;
+ case TypeDesc.FLOAT_CODE:
+ mb.invokeStatic("java/lang/Float", "hashCode", TypeDesc.FLOAT, new TypeDesc[] {TypeDesc.FLOAT});
+ break;
+ case TypeDesc.SHORT_CODE:
+ mb.invokeStatic("java/lang/Short", "hashCode", TypeDesc.SHORT, new TypeDesc[] {TypeDesc.SHORT});
+ break;
+ }
+ return Types.INTEGER;
+ }
+}