]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/constants/JavaComparisonOperation.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / constants / JavaComparisonOperation.java
1 package org.simantics.scl.compiler.constants;
2
3
4 import org.objectweb.asm.Label;
5 import org.simantics.scl.compiler.internal.codegen.references.Val;
6 import org.simantics.scl.compiler.internal.codegen.types.JavaTypeTranslator;
7 import org.simantics.scl.compiler.internal.codegen.utils.MethodBuilder;
8 import org.simantics.scl.compiler.types.TVar;
9 import org.simantics.scl.compiler.types.Type;
10 import org.simantics.scl.compiler.types.Types;
11
12 public class JavaComparisonOperation extends FunctionValue {
13     
14     String op;
15     
16     public JavaComparisonOperation(String op, Type type) {
17         super(TVar.EMPTY_ARRAY, Types.NO_EFFECTS, Types.BOOLEAN, type, type);
18         this.op = op;
19     }
20
21     @Override
22     public Type applyExact(MethodBuilder mb, Val[] parameters) {
23         JavaTypeTranslator tt = mb.getJavaTypeTranslator();
24         Label thenBranch = mb.createLabel();
25         Label joinPoint = mb.createLabel();
26         
27         mb.push(parameters[0], type);        
28         mb.push(parameters[1], type);
29         mb.ifComparisonBranch(thenBranch, op, tt.toTypeDesc(parameterTypes[0]));
30         
31         mb.loadConstant(false);
32         mb.branch(joinPoint);
33         
34         mb.setLocation(thenBranch);
35         mb.loadConstant(true);
36         mb.setLocation(joinPoint);
37         
38         return getReturnType();
39     }
40     
41     @Override
42     public String toString() {
43         return "(" + op + ")";
44     }
45
46 }