package org.simantics.scl.compiler.elaboration.java; import org.simantics.scl.compiler.common.exceptions.InternalCompilerError; import org.simantics.scl.compiler.constants.FunctionValue; import org.simantics.scl.compiler.internal.codegen.references.Val; import org.simantics.scl.compiler.internal.codegen.types.BTypes; 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.exceptions.MatchException; import org.simantics.scl.compiler.types.kinds.Kinds; public class ApplyUnit extends FunctionValue { private static final TVar A = Types.var(Kinds.STAR); private static final TVar E = Types.var(Kinds.EFFECT); public static final ApplyUnit INSTANCE = new ApplyUnit(); private ApplyUnit() { super(new TVar[] {A}, E, A, Types.functionE(Types.PUNIT, E, A)); } @Override public Type applyExact(MethodBuilder mb, Val[] parameters) { parameters[0].push(mb); mb.pushTuple0(); mb.genericApply(1); try { return BTypes.matchFunction(parameters[0].getType(), 1)[1]; } catch (MatchException e) { throw new InternalCompilerError(); } } @Override public String toString() { return "applyUnit"; } }