X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.scl.compiler%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fcompiler%2Fconstants%2Fgeneric%2FCallJava.java;fp=bundles%2Forg.simantics.scl.compiler%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fcompiler%2Fconstants%2Fgeneric%2FCallJava.java;h=300f11802ae4df144649a7d0a6f156294dc6e999;hb=969bd23cab98a79ca9101af33334000879fb60c5;hp=0000000000000000000000000000000000000000;hpb=866dba5cd5a3929bbeae85991796acb212338a08;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/constants/generic/CallJava.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/constants/generic/CallJava.java new file mode 100644 index 000000000..300f11802 --- /dev/null +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/constants/generic/CallJava.java @@ -0,0 +1,90 @@ +package org.simantics.scl.compiler.constants.generic; + +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.types.JavaReferenceValidator; +import org.simantics.scl.compiler.internal.codegen.utils.MethodBuilder; +import org.simantics.scl.compiler.types.TVar; +import org.simantics.scl.compiler.types.Type; + +/** + * This class represents a call to a Java method as an SCL function value. + * It is instantiated by the {@link org.simantics.scl.compiler.compilation.Elaboration.matchType(MethodRef, Type)} method. + */ +public class CallJava extends FunctionValue { + StackItem[] stackItems; + MethodRef methodRef; + OutputFilter filter; + + public CallJava(TVar[] typeParameters, Type effect, Type returnType, + Type[] parameterTypes, StackItem[] stackItems, MethodRef methodRef, + OutputFilter filter) { + super(typeParameters, effect, returnType, parameterTypes); + this.stackItems = stackItems; + this.methodRef = methodRef; + this.filter = filter; + } + + @Override + public Type applyExact(MethodBuilder mb, Val[] parameters) { + methodRef.invoke(mb, stackItems, parameters); + if(filter != null) + filter.filter(mb); + return getReturnType(); + } + + public MethodRef getMethodRef() { + return methodRef; + } + + @Override + public String toString() { + return methodRef.getName(); + } + + public final static int INCOMPARABLE = -2; + public final static int LESS = -1; + public final static int EQUAL = 0; + public final static int GREATER = 1; + + public int compareTo(JavaReferenceValidator validator, CallJava other) { + MethodRef m1 = methodRef; + MethodRef m2 = other.methodRef; + TypeDesc[] ps1 = m1.getParameterTypes(); + TypeDesc[] ps2 = m2.getParameterTypes(); + if(ps1.length != ps2.length) + return INCOMPARABLE; + + boolean lessOrEqual = true; + boolean greaterOrEqual = true; + for(int i=0;i