]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/constants/GetPrimitiveConstant.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / constants / GetPrimitiveConstant.java
diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/constants/GetPrimitiveConstant.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/constants/GetPrimitiveConstant.java
new file mode 100644 (file)
index 0000000..9f7a2d6
--- /dev/null
@@ -0,0 +1,33 @@
+package org.simantics.scl.compiler.constants;
+
+import org.cojen.classfile.TypeDesc;
+import org.simantics.scl.compiler.internal.codegen.references.IVal;
+import org.simantics.scl.compiler.internal.codegen.types.JavaTypeTranslator;
+import org.simantics.scl.compiler.internal.codegen.utils.MethodBuilder;
+import org.simantics.scl.compiler.internal.codegen.utils.TransientClassBuilder;
+import org.simantics.scl.compiler.types.Type;
+
+public class GetPrimitiveConstant extends Constant {
+
+    IVal val;
+    TypeDesc typeDesc;
+
+    public GetPrimitiveConstant(Type type, IVal val, TypeDesc typeDesc) {
+        super(type);
+        this.val = val;
+        this.typeDesc = typeDesc;
+    }
+
+    @Override
+    public void push(MethodBuilder mb) {
+        if(typeDesc != TypeDesc.VOID) {
+            val.push(mb);
+            mb.convert(JavaTypeTranslator.toObjectType(typeDesc), typeDesc);
+        }
+    }    
+
+    @Override
+    public Object realizeValue(TransientClassBuilder classLoader) {
+        return val.realizeValue(classLoader);
+    }
+}