1 package org.simantics.scl.compiler.constants.singletons;
3 import org.objectweb.asm.Label;
4 import org.simantics.scl.compiler.constants.ComparisonFunction;
5 import org.simantics.scl.compiler.constants.FunctionValue;
6 import org.simantics.scl.compiler.internal.codegen.continuations.Cont;
7 import org.simantics.scl.compiler.internal.codegen.references.Val;
8 import org.simantics.scl.compiler.internal.codegen.utils.MethodBuilder;
9 import org.simantics.scl.compiler.types.TVar;
10 import org.simantics.scl.compiler.types.Type;
11 import org.simantics.scl.compiler.types.Types;
12 import org.simantics.scl.compiler.types.kinds.Kinds;
14 public class NullCheck extends FunctionValue implements ComparisonFunction {
15 private static final TVar A = Types.var(Kinds.STAR);
16 public static final NullCheck INSTANCE =
20 super(new TVar[] {A}, Types.NO_EFFECTS, Types.BOOLEAN, A);
24 public Type applyExact(MethodBuilder mb, Val[] parameters) {
25 parameters[0].push(mb);
26 Label join = mb.createLabel();
27 Label isNull = mb.createLabel();
28 mb.ifNullBranch(isNull, true);
29 mb.loadConstant(false);
31 mb.setLocation(isNull);
32 mb.loadConstant(true);
34 return getReturnType();
38 public void generateCondition(MethodBuilder mb, Val[] parameters, Cont then_, Cont else_) {
39 parameters[0].push(mb);
40 mb.ifNullBranch(mb.getLabel(then_), true);
42 mb.ensureExists(then_);
46 public String toString() {