1 package org.simantics.scl.compiler.elaboration.java;
3 import org.cojen.classfile.TypeDesc;
4 import org.simantics.scl.compiler.common.exceptions.InternalCompilerError;
5 import org.simantics.scl.compiler.constants.FunctionValue;
6 import org.simantics.scl.compiler.internal.codegen.references.Val;
7 import org.simantics.scl.compiler.internal.codegen.utils.Constants;
8 import org.simantics.scl.compiler.internal.codegen.utils.MethodBuilder;
9 import org.simantics.scl.compiler.types.TCon;
10 import org.simantics.scl.compiler.types.TVar;
11 import org.simantics.scl.compiler.types.Type;
12 import org.simantics.scl.compiler.types.Types;
13 import org.simantics.scl.compiler.types.exceptions.MatchException;
14 import org.simantics.scl.compiler.types.kinds.Kinds;
16 public class LengthVector extends FunctionValue {
17 private static final TVar A = Types.var(Kinds.STAR);
18 private final TCon constructor;
20 public LengthVector(TCon constructor) {
21 super(new TVar[] {A}, Types.NO_EFFECTS, Types.INTEGER, Types.apply(constructor, A));
22 this.constructor = constructor;
26 public Type applyExact(MethodBuilder mb, Val[] parameters) {
27 Val vector = parameters[0];
31 Type elementType = Types.canonical(
32 Types.matchApply(constructor, vector.getType()));
33 if(elementType instanceof TVar) {
34 mb.invokeStatic("java/lang/reflect/Array", "getLength", TypeDesc.INT,
35 Constants.OBJECTS[1]);
42 } catch (MatchException e) {
43 throw new InternalCompilerError(e);