X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.scl.compiler%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fcompiler%2Felaboration%2Fjava%2FHashCodeFunction.java;h=a2b35b116e1748986a1b789bfb496dc601f47922;hb=eb2c2adbfc25f7116e9b8e2db44b6dabf742dd60;hp=2bb6ec2955f255cfe422543317469e1108fa73e1;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/java/HashCodeFunction.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/java/HashCodeFunction.java index 2bb6ec295..a2b35b116 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/java/HashCodeFunction.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/java/HashCodeFunction.java @@ -1,51 +1,51 @@ -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; - } -} +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; + } +}