]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/constants/singletons/ListLength.java
Fixed multiple issues causing dangling references to discarded queries
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / constants / singletons / ListLength.java
1 package org.simantics.scl.compiler.constants.singletons;
2
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.utils.Constants;
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;
10 import org.simantics.scl.compiler.types.Types;
11 import org.simantics.scl.compiler.types.kinds.Kinds;
12
13 public class ListLength extends FunctionValue {    
14     private static TVar A = Types.var(Kinds.STAR);
15     public static final ListLength INSTANCE = new ListLength();
16     
17     private ListLength() {
18         super(new TVar[] {A}, Types.NO_EFFECTS, Types.INTEGER, Types.list(A));
19     }
20     
21     @Override
22     public Type applyExact(MethodBuilder mb, Val[] parameters) {
23         parameters[0].push(mb);
24         mb.invokeInterface("java/util/List", "size", TypeDesc.INT, Constants.EMPTY_TYPEDESC_ARRAY);
25         return getReturnType();
26     }
27
28     @Override
29     public String toString() {
30         return "length";
31     }
32 }