package org.simantics.scl.compiler.constants.singletons; 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 ListLength extends FunctionValue { private static TVar A = Types.var(Kinds.STAR); public static final ListLength INSTANCE = new ListLength(); private ListLength() { super(new TVar[] {A}, Types.NO_EFFECTS, Types.INTEGER, Types.list(A)); } @Override public Type applyExact(MethodBuilder mb, Val[] parameters) { parameters[0].push(mb); mb.invokeInterface("java/util/List", "size", TypeDesc.INT, Constants.EMPTY_TYPEDESC_ARRAY); return getReturnType(); } @Override public String toString() { return "length"; } }