1 package org.simantics.scl.compiler.constants.generic;
3 import org.cojen.classfile.TypeDesc;
4 import org.simantics.scl.compiler.constants.FunctionValue;
5 import org.simantics.scl.compiler.internal.codegen.references.Val;
6 import org.simantics.scl.compiler.internal.codegen.types.JavaReferenceValidator;
7 import org.simantics.scl.compiler.internal.codegen.utils.MethodBuilder;
8 import org.simantics.scl.compiler.types.TVar;
9 import org.simantics.scl.compiler.types.Type;
12 * This class represents a call to a Java method as an SCL function value.
13 * It is instantiated by the {@link org.simantics.scl.compiler.compilation.Elaboration.matchType(MethodRef, Type)} method.
15 public class CallJava extends FunctionValue {
16 StackItem[] stackItems;
20 public CallJava(TVar[] typeParameters, Type effect, Type returnType,
21 Type[] parameterTypes, StackItem[] stackItems, MethodRef methodRef,
22 OutputFilter filter) {
23 super(typeParameters, effect, returnType, parameterTypes);
24 if(stackItems == null) {
25 stackItems = new StackItem[parameterTypes.length];
26 for(int i=0;i<parameterTypes.length;++i)
27 stackItems[i] = new ParameterStackItem(i, parameterTypes[i]);
29 this.stackItems = stackItems;
30 this.methodRef = methodRef;
35 public Type applyExact(MethodBuilder mb, Val[] parameters) {
36 methodRef.invoke(mb, stackItems, parameters);
39 return getReturnType();
42 public MethodRef getMethodRef() {
47 public String toString() {
48 return methodRef.getName();
51 public final static int INCOMPARABLE = -2;
52 public final static int LESS = -1;
53 public final static int EQUAL = 0;
54 public final static int GREATER = 1;
56 public int compareTo(JavaReferenceValidator validator, CallJava other) {
57 MethodRef m1 = methodRef;
58 MethodRef m2 = other.methodRef;
59 TypeDesc[] ps1 = m1.getParameterTypes();
60 TypeDesc[] ps2 = m2.getParameterTypes();
61 if(ps1.length != ps2.length)
64 boolean lessOrEqual = true;
65 boolean greaterOrEqual = true;
66 for(int i=0;i<ps1.length;++i) {
67 if(ps1[i].equals(ps2[i]))
69 if(!validator.isAssignableFrom(ps1[i], ps2[i])) {
72 if(!validator.isAssignableFrom(ps2[i], ps1[i])) {
73 greaterOrEqual = false;
91 public void prepare(MethodBuilder mb) {
92 for(StackItem item : stackItems)