1 package org.simantics.scl.compiler.constants.singletons;
3 import org.simantics.scl.compiler.constants.FunctionValue;
4 import org.simantics.scl.compiler.internal.codegen.references.Val;
5 import org.simantics.scl.compiler.internal.codegen.ssa.SSABlock;
6 import org.simantics.scl.compiler.internal.codegen.ssa.SSAStatement;
7 import org.simantics.scl.compiler.internal.codegen.ssa.exits.Throw2;
8 import org.simantics.scl.compiler.internal.codegen.ssa.statements.LetApply;
9 import org.simantics.scl.compiler.internal.codegen.utils.MethodBuilder;
10 import org.simantics.scl.compiler.internal.codegen.utils.SSASimplificationContext;
11 import org.simantics.scl.compiler.types.TVar;
12 import org.simantics.scl.compiler.types.Type;
13 import org.simantics.scl.compiler.types.Types;
14 import org.simantics.scl.compiler.types.kinds.Kinds;
16 public class ThrowFunction extends FunctionValue {
18 private static final TVar A = Types.var(Kinds.STAR);
19 private static final TVar B = Types.var(Kinds.STAR);
20 public static final ThrowFunction INSTANCE =
23 private ThrowFunction() {
24 super(new TVar[] {A, B}, Types.PROC, B, A);
28 public Type applyExact(MethodBuilder mb, Val[] parameters) {
29 mb.pushBoxed(parameters[0]);
31 return getReturnType();
35 public String toString() {
40 public void inline(SSASimplificationContext context, LetApply apply) {
41 if(apply.getParameters().length != 1)
42 return; // shouldn't be possible
44 SSABlock block = apply.getParent();
45 for(SSAStatement statement=apply.getNext();statement != null;statement=statement.getNext())
47 apply.getFunction().remove();
48 apply.detachThisAndSuccessors();
49 block.getExit().destroy();
50 block.setExit(new Throw2(apply.getParameters()[0]));
51 context.markModified("inline-throw");