]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/constants/FailFunction.java
(refs #7250) Merging master, minor CHR bugfixes
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / constants / FailFunction.java
1 package org.simantics.scl.compiler.constants;
2
3 import org.cojen.classfile.TypeDesc;
4 import org.simantics.scl.compiler.internal.codegen.references.Val;
5 import org.simantics.scl.compiler.internal.codegen.utils.MethodBuilder;
6 import org.simantics.scl.compiler.types.TVar;
7 import org.simantics.scl.compiler.types.Type;
8 import org.simantics.scl.compiler.types.Types;
9 import org.simantics.scl.compiler.types.kinds.Kinds;
10
11 public class FailFunction extends FunctionValue {
12
13     private static final TVar A = Types.var(Kinds.STAR);
14     public static final FailFunction INSTANCE = 
15             new FailFunction();
16     
17     private FailFunction() {
18         super(new TVar[] {A}, Types.NO_EFFECTS, A, Types.STRING);
19     }
20     
21     private static final TypeDesc RuntimeException = 
22             TypeDesc.forClass(RuntimeException.class);
23     
24     @Override
25     public Type applyExact(MethodBuilder mb, Val[] parameters) {
26         mb.newObject(RuntimeException);
27         mb.dup();
28         mb.push(parameters, parameterTypes);
29         mb.invokeConstructor(RuntimeException, 
30                 new TypeDesc[] {TypeDesc.STRING});
31         mb.throwObject();
32         return getReturnType();
33     }
34
35     @Override
36     public String toString() {
37          return "fail";
38     }
39 }