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.MethodBuilder;
8 import org.simantics.scl.compiler.types.TCon;
9 import org.simantics.scl.compiler.types.TVar;
10 import org.simantics.scl.compiler.types.Type;
11 import org.simantics.scl.compiler.types.Types;
12 import org.simantics.scl.compiler.types.exceptions.MatchException;
13 import org.simantics.scl.compiler.types.kinds.Kinds;
15 public class GetVector extends FunctionValue {
16 private static final TVar A = Types.var(Kinds.STAR);
17 private final TCon constructor;
19 public GetVector(Type effect, TCon constructor) {
20 super(new TVar[] {A}, effect, A, Types.apply(constructor, A), Types.INTEGER);
21 this.constructor = constructor;
25 public Type applyExact(MethodBuilder mb, Val[] parameters) {
26 Val vector = parameters[0];
27 Val index = parameters[1];
33 Type elementType = Types.canonical(
34 Types.matchApply(constructor, vector.getType()));
35 if(elementType instanceof TVar) {
36 mb.invokeStatic("java/lang/reflect/Array", "get", TypeDesc.OBJECT,
37 new TypeDesc[] {TypeDesc.OBJECT, TypeDesc.INT});
41 TypeDesc desc = mb.getJavaTypeTranslator().toTypeDesc(elementType);
42 mb.loadFromArray(desc);
45 } catch (MatchException e) {
46 throw new InternalCompilerError(e);