]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/constants/DoubleConstant.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / constants / DoubleConstant.java
diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/constants/DoubleConstant.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/constants/DoubleConstant.java
new file mode 100644 (file)
index 0000000..34e98a2
--- /dev/null
@@ -0,0 +1,72 @@
+package org.simantics.scl.compiler.constants;
+
+import org.cojen.classfile.TypeDesc;
+import org.objectweb.asm.Label;
+import org.simantics.scl.compiler.internal.codegen.continuations.Cont;
+import org.simantics.scl.compiler.internal.codegen.references.IVal;
+import org.simantics.scl.compiler.internal.codegen.utils.MethodBuilder;
+import org.simantics.scl.compiler.internal.codegen.utils.TransientClassBuilder;
+import org.simantics.scl.compiler.types.Types;
+
+public class DoubleConstant extends Constant {
+    double value;
+
+    public DoubleConstant(double value) {
+        super(Types.DOUBLE);
+        this.value = value;
+    }
+    
+    @Override
+    public void push(MethodBuilder mb) {
+        mb.loadConstant(value);
+    }
+    
+    @Override
+    public String toString() {
+        return String.valueOf(value);
+    }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        long temp;
+        temp = Double.doubleToLongBits(value);
+        result = prime * result + (int) (temp ^ (temp >>> 32));
+        return result;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj)
+            return true;
+        if (obj == null)
+            return false;
+        if (getClass() != obj.getClass())
+            return false;
+        DoubleConstant other = (DoubleConstant) obj;
+        if (Double.doubleToLongBits(value) != Double
+                .doubleToLongBits(other.value))
+            return false;
+        return true;
+    }
+    
+    @Override
+    public void deconstruct(MethodBuilder mb, IVal parameter, Cont success,
+            Label failure) {        
+        mb.push(parameter, Types.DOUBLE);
+        mb.loadConstant(value);
+        mb.ifComparisonBranch(failure, "!=", TypeDesc.DOUBLE);
+        mb.jump(success);
+    }
+    
+    @Override
+    public int constructorTag() {
+        return 0;
+    }
+    
+    @Override
+    public Object realizeValue(TransientClassBuilder classBuilder) {
+        return value;
+    }
+}