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.TVar;
9 import org.simantics.scl.compiler.types.Type;
10 import org.simantics.scl.compiler.types.Types;
11 import org.simantics.scl.compiler.types.exceptions.MatchException;
12 import org.simantics.scl.compiler.types.kinds.Kinds;
14 public class SetMVector extends FunctionValue {
15 private static final TVar A = Types.var(Kinds.STAR);
16 public static final SetMVector INSTANCE = new SetMVector();
18 private SetMVector() {
19 super(new TVar[] {A}, Types.PROC, Types.UNIT, Types.mvector(A), Types.INTEGER, A);
23 public Type applyExact(MethodBuilder mb, Val[] parameters) {
24 Val vector = parameters[0];
25 Val index = parameters[1];
26 Val value = parameters[2];
32 Type elementType = Types.canonical(
33 Types.matchApply(Types.MVECTOR, vector.getType()));
34 if(elementType instanceof TVar) {
35 mb.push(value, elementType);
36 mb.invokeStatic("java/lang/reflect/Array", "set", TypeDesc.VOID,
37 new TypeDesc[] {TypeDesc.OBJECT, TypeDesc.INT, TypeDesc.OBJECT});
42 TypeDesc desc = mb.getJavaTypeTranslator().toTypeDesc(elementType);
43 mb.storeToArray(desc);
46 } catch (MatchException e) {
47 throw new InternalCompilerError(e);