lucy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@apache.org
Subject [04/22] lucy-clownfish git commit: Prepare to parse Python meth args.
Date Tue, 01 Mar 2016 03:03:12 GMT
Prepare to parse Python meth args.

Stub out data structures into which we will read arguments from Python.


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

Branch: refs/heads/master
Commit: 15602e67deb05b28329c9eaf0612a739547ddf8b
Parents: 6a50d21
Author: Marvin Humphrey <marvin@rectangular.com>
Authored: Tue Feb 2 11:03:02 2016 -0800
Committer: Marvin Humphrey <marvin@rectangular.com>
Committed: Wed Feb 24 15:24:52 2016 -0800

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


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/15602e67/compiler/src/CFCPyMethod.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCPyMethod.c b/compiler/src/CFCPyMethod.c
index 863a0cb..c89d12c 100644
--- a/compiler/src/CFCPyMethod.c
+++ b/compiler/src/CFCPyMethod.c
@@ -67,6 +67,41 @@ S_build_py_args(CFCParamList *param_list) {
     return py_args;
 }
 
+/* Generate the code which parses arguments passed from Python and converts
+ * them to Clownfish-flavored C values.
+ */
+static char*
+S_gen_arg_parsing(CFCParamList *param_list) {
+    char *content = NULL;
+
+    CFCVariable **vars = CFCParamList_get_variables(param_list);
+    const char **vals = CFCParamList_get_initial_values(param_list);
+    int num_vars = CFCParamList_num_vars(param_list);
+
+    char *declarations = CFCUtil_strdup("");
+    char *keywords     = CFCUtil_strdup("");
+    char *format_str   = CFCUtil_strdup("");
+    char *targets      = CFCUtil_strdup("");
+    int optional_started = 0;
+
+    char parse_pattern[] =
+        "%s"
+        "    char *keywords[] = {%sNULL};\n"
+        "    char *fmt = \"%s\";\n"
+        "    int ok = PyArg_ParseTupleAndKeywords(args, kwargs, fmt,\n"
+        "        keywords%s);\n"
+        "    if (!ok) { return NULL; }\n"
+        ;
+    content = CFCUtil_sprintf(parse_pattern, declarations, keywords,
+                              format_str, targets);
+
+    FREEMEM(declarations);
+    FREEMEM(keywords);
+    FREEMEM(format_str);
+    FREEMEM(targets);
+    return content;
+}
+
 static char*
 S_build_pymeth_invocation(CFCMethod *method) {
     CFCType *return_type = CFCMethod_get_return_type(method);
@@ -227,10 +262,13 @@ S_meth_top(CFCMethod *method) {
         return CFCUtil_sprintf(pattern);
     }
     else {
+        char *arg_parsing = S_gen_arg_parsing(param_list);
         char pattern[] =
             "(PyObject *self, PyObject *args, PyObject *kwargs) {\n"
+            "%s"
             ;
-        char *result = CFCUtil_sprintf(pattern);
+        char *result = CFCUtil_sprintf(pattern, arg_parsing);
+        FREEMEM(arg_parsing);
         return result;
     }
 }


Mime
View raw message