Repository: lucy-clownfish
Updated Branches:
  refs/heads/master c75ee9248 -> 9debabe4d


Add CFCPyTypeMap.

Only include a C-to-Python conversion routine for now.


Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/d4f52d9c
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/d4f52d9c
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/d4f52d9c

Branch: refs/heads/master
Commit: d4f52d9c6a8c956727e1e530860424fa8ae18cc7
Parents: 11d08c5
Author: Marvin Humphrey <mar...@rectangular.com>
Authored: Sat Dec 20 16:31:19 2014 -0800
Committer: Marvin Humphrey <mar...@rectangular.com>
Committed: Sat Feb 6 09:58:12 2016 -0800

----------------------------------------------------------------------
 compiler/src/CFCPyTypeMap.c | 71 ++++++++++++++++++++++++++++++++++++++++
 compiler/src/CFCPyTypeMap.h | 43 ++++++++++++++++++++++++
 2 files changed, 114 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/d4f52d9c/compiler/src/CFCPyTypeMap.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCPyTypeMap.c b/compiler/src/CFCPyTypeMap.c
new file mode 100644
index 0000000..016d3dc
--- /dev/null
+++ b/compiler/src/CFCPyTypeMap.c
@@ -0,0 +1,71 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <string.h>
+
+#include "CFCPyTypeMap.h"
+#include "CFCType.h"
+#include "CFCUtil.h"
+
+char*
+CFCPyTypeMap_c_to_py(CFCType *type, const char *cf_var) {
+    const char *type_str = CFCType_to_c(type);
+    char *result = NULL;
+
+    if (CFCType_is_object(type)) {
+        result = CFCUtil_sprintf("CFBind_cfish_to_py((cfish_Obj*)%s)", cf_var);
+    }
+    else if (CFCType_is_primitive(type)) {
+        const char *specifier = CFCType_get_specifier(type);
+
+        if (strcmp(specifier, "double") == 0
+            || strcmp(specifier, "float") == 0
+           ) {
+            result = CFCUtil_sprintf("PyFloat_FromDouble(%s)", cf_var);
+        }
+        else if (strcmp(specifier, "int") == 0
+                 || strcmp(specifier, "short") == 0
+                 || strcmp(specifier, "long") == 0
+                 || strcmp(specifier, "char") == 0 // OK if char is unsigned
+                 || strcmp(specifier, "int8_t") == 0
+                 || strcmp(specifier, "int16_t") == 0
+                 || strcmp(specifier, "int32_t") == 0
+                ) {
+            result = CFCUtil_sprintf("PyLong_FromLong(%s)", cf_var);
+        }
+        else if (strcmp(specifier, "int64_t") == 0) {
+            result = CFCUtil_sprintf("PyLong_FromLongLong(%s)", cf_var);
+        }
+        else if (strcmp(specifier, "uint8_t") == 0
+                 || strcmp(specifier, "uint16_t") == 0
+                 || strcmp(specifier, "uint32_t") == 0
+                ) {
+            result = CFCUtil_sprintf("PyLong_FromUnsignedLong(%s)", cf_var);
+        }
+        else if (strcmp(specifier, "uint64_t") == 0) {
+            result = CFCUtil_sprintf("PyLong_FromUnsignedLongLong(%s)", 
cf_var);
+        }
+        else if (strcmp(specifier, "size_t") == 0) {
+            result = CFCUtil_sprintf("PyLong_FromSize_t(%s)", cf_var);
+        }
+        else if (strcmp(specifier, "bool") == 0) {
+            result = CFCUtil_sprintf("PyBool_FromLong(%s)", cf_var);
+        }
+    }
+
+    return result;
+}
+

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/d4f52d9c/compiler/src/CFCPyTypeMap.h
----------------------------------------------------------------------
diff --git a/compiler/src/CFCPyTypeMap.h b/compiler/src/CFCPyTypeMap.h
new file mode 100644
index 0000000..da14829
--- /dev/null
+++ b/compiler/src/CFCPyTypeMap.h
@@ -0,0 +1,43 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef H_CFCPYTYPEMAP
+#define H_CFCPYTYPEMAP
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct CFCType;
+struct CFCParcel;
+
+/** Return an expression converts from a variable of type `type` to a
+ * PyObject*.
+ * 
+ * @param type A Clownfish::CFC::Model::Type, which will be used to select the
+ * mapping code.
+ * @param cf_var The name of the variable from which we are extracting a
+ * value.
+ */ 
+char*
+CFCPyTypeMap_c_to_py(struct CFCType *type, const char *cf_var);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* H_CFCPYTYPEMAP */
+

Reply via email to