package org.simantics.scl.compiler.constants; import org.objectweb.asm.Label; import org.simantics.scl.compiler.internal.codegen.references.Val; import org.simantics.scl.compiler.internal.codegen.types.JavaTypeTranslator; 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; public class JavaComparisonOperation extends FunctionValue { String op; public JavaComparisonOperation(String op, Type type) { super(TVar.EMPTY_ARRAY, Types.NO_EFFECTS, Types.BOOLEAN, type, type); this.op = op; } @Override public Type applyExact(MethodBuilder mb, Val[] parameters) { JavaTypeTranslator tt = mb.getJavaTypeTranslator(); Label thenBranch = mb.createLabel(); Label joinPoint = mb.createLabel(); mb.push(parameters[0], type); mb.push(parameters[1], type); mb.ifComparisonBranch(thenBranch, op, tt.toTypeDesc(parameterTypes[0])); mb.loadConstant(false); mb.branch(joinPoint); mb.setLocation(thenBranch); mb.loadConstant(true); mb.setLocation(joinPoint); return getReturnType(); } @Override public String toString() { return "(" + op + ")"; } }