You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by ma...@apache.org on 2016/02/25 00:56:18 UTC

[17/36] lucy-clownfish git commit: Gen list of converter/arg-pointer pairs.

Gen list of converter/arg-pointer pairs.

Generate the list of function-pointer/arg-pointer pairs passed which get
passed to `PyArg_ParseTupleAndKeywords`.


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

Branch: refs/heads/py_exp13
Commit: ba87d53627914d6815122d59e9b0ae5afbcf9e23
Parents: 1853cbf
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Tue Feb 2 13:42:27 2016 -0800
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Wed Feb 24 15:24:52 2016 -0800

----------------------------------------------------------------------
 compiler/src/CFCPyMethod.c | 51 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/ba87d536/compiler/src/CFCPyMethod.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCPyMethod.c b/compiler/src/CFCPyMethod.c
index 48ef443..c0363a5 100644
--- a/compiler/src/CFCPyMethod.c
+++ b/compiler/src/CFCPyMethod.c
@@ -133,6 +133,53 @@ S_gen_declaration(CFCVariable *var, const char *val) {
     return result;
 }
 
+static char*
+S_gen_target(CFCVariable *var, const char *value) {
+    CFCType *type = CFCVariable_get_type(var);
+    const char *specifier = CFCType_get_specifier(type);
+    const char *micro_sym = CFCVariable_get_name(var);
+    const char *maybe_maybe = "";
+    const char *dest_name;
+    char *var_name = NULL;
+    if (CFCType_is_primitive(type)) {
+        dest_name = CFCType_get_specifier(type);
+        if (value != NULL) {
+            maybe_maybe = "maybe_";
+        }
+        var_name = CFCUtil_sprintf("%s_ARG", CFCVariable_get_name(var));
+    }
+    else if (CFCType_is_object(type)) {
+        if (CFCType_nullable(type) ||
+            (value && strcmp(value, "NULL") == 0)
+           ) {
+            maybe_maybe = "maybe_";
+        }
+        if (strcmp(specifier, "cfish_String") == 0) {
+            dest_name = "string";
+            var_name = CFCUtil_sprintf("%s_ARG", CFCVariable_get_name(var));
+        }
+        else if (strcmp(specifier, "cfish_Hash") == 0) {
+            dest_name = "hash";
+            var_name = CFCUtil_sprintf("%s_ARG", CFCVariable_get_name(var));
+        }
+        else if (strcmp(specifier, "cfish_Vector") == 0) {
+            dest_name = "vec";
+            var_name = CFCUtil_sprintf("%s_ARG", CFCVariable_get_name(var));
+        }
+        else {
+            dest_name = "obj";
+            var_name = CFCUtil_sprintf("wrap_arg_%s", micro_sym);
+        }
+    }
+    else {
+        dest_name = "INVALID";
+    }
+    char *content = CFCUtil_sprintf(", CFBind_%sconvert_%s, &%s",
+                                    maybe_maybe, dest_name, var_name);
+    FREEMEM(var_name);
+    return content;
+}
+
 /* Generate the code which parses arguments passed from Python and converts
  * them to Clownfish-flavored C values.
  */
@@ -169,6 +216,10 @@ S_gen_arg_parsing(CFCParamList *param_list, int first_tick, char **error) {
         char *declaration = S_gen_declaration(var, val);
         declarations = CFCUtil_cat(declarations, declaration, NULL);
         FREEMEM(declaration);
+
+        char *target = S_gen_target(var, val);
+        targets = CFCUtil_cat(targets, target, NULL);
+        FREEMEM(target);
     }
 
     char parse_pattern[] =