X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.scl.compiler%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fcompiler%2Fconstants%2Fsingletons%2FTypeOfConstant.java;h=f99f2ac78ad93cf5fc2d9fd09342c4eaa0a44da4;hb=48e0bda8e45286b2bcc65b75e0364e2223ba3ec4;hp=a98e4e5bf58bf0c99c0eae96192953dd78166cfb;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/constants/singletons/TypeOfConstant.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/constants/singletons/TypeOfConstant.java index a98e4e5bf..f99f2ac78 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/constants/singletons/TypeOfConstant.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/constants/singletons/TypeOfConstant.java @@ -1,32 +1,48 @@ -package org.simantics.scl.compiler.constants.singletons; - -import org.simantics.scl.compiler.constants.FunctionValue; -import org.simantics.scl.compiler.internal.codegen.references.Val; -import org.simantics.scl.compiler.internal.codegen.utils.MethodBuilder; -import org.simantics.scl.compiler.types.TCon; -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 TypeOfConstant extends FunctionValue { - private static final TVar A = Types.var(Kinds.STAR); - private static final TCon Type = Types.con(Types.BUILTIN, "Type"); - public static final TypeOfConstant INSTANCE = new TypeOfConstant(); - - private TypeOfConstant() { - super(new TVar[] {A}, Types.NO_EFFECTS, Type, - Types.pred(Types.TYPEABLE, A), A); - } - - @Override - public Type applyExact(MethodBuilder mb, Val[] parameters) { - mb.push(parameters[0], Type); - return getReturnType(); - } - - @Override - public String toString() { - return "typeOf"; - } +package org.simantics.scl.compiler.constants.singletons; + +import java.util.Arrays; + +import org.simantics.scl.compiler.constants.FunctionValue; +import org.simantics.scl.compiler.internal.codegen.references.Val; +import org.simantics.scl.compiler.internal.codegen.references.ValRef; +import org.simantics.scl.compiler.internal.codegen.ssa.statements.LetApply; +import org.simantics.scl.compiler.internal.codegen.utils.MethodBuilder; +import org.simantics.scl.compiler.internal.codegen.utils.SSASimplificationContext; +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 TypeOfConstant extends FunctionValue { + private static final TVar A = Types.var(Kinds.STAR); + public static final TypeOfConstant INSTANCE = new TypeOfConstant(); + + private TypeOfConstant() { + super(new TVar[] {A}, Types.NO_EFFECTS, Types.TYPE, + Types.pred(Types.TYPEABLE, A), A); + } + + @Override + public Type applyExact(MethodBuilder mb, Val[] parameters) { + mb.push(parameters[0], Types.TYPE); + return getReturnType(); + } + + @Override + public String toString() { + return "typeOf"; + } + + @Override + public void inline(SSASimplificationContext context, LetApply apply) { + ValRef[] parameters = apply.getParameters(); + if(parameters.length == 2) { + parameters[1].remove(); + apply.setParameters(Arrays.copyOf(parameters, 1)); + } + ValRef oldFunc = apply.getFunction(); + apply.setFunction(TypeValueConstant.INSTANCE.createOccurrence(oldFunc.getTypeParameters())); + oldFunc.remove(); + context.markModified("inline-typeOf"); + } } \ No newline at end of file