lucy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@apache.org
Subject [05/22] lucy-clownfish git commit: Consider num args in Py binding.
Date Tue, 01 Mar 2016 03:03:13 GMT
Consider num args in Py binding.

For generated CPython method glue code, support keyword args if the
method takes arguments.


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

Branch: refs/heads/master
Commit: 6a50d2179d0464048f54f021eff3e70029b6162d
Parents: cb25fd0
Author: Marvin Humphrey <marvin@rectangular.com>
Authored: Tue Feb 2 10:39:32 2016 -0800
Committer: Marvin Humphrey <marvin@rectangular.com>
Committed: Wed Feb 24 15:24:52 2016 -0800

----------------------------------------------------------------------
 compiler/src/CFCPyMethod.c | 28 ++++++++++++++++++++++++----
 1 file changed, 24 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/6a50d217/compiler/src/CFCPyMethod.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCPyMethod.c b/compiler/src/CFCPyMethod.c
index 0a5cd27..863a0cb 100644
--- a/compiler/src/CFCPyMethod.c
+++ b/compiler/src/CFCPyMethod.c
@@ -215,20 +215,40 @@ S_maybe_unreachable(CFCType *return_type) {
     return return_statement;
 }
 
+static char*
+S_meth_top(CFCMethod *method) {
+    CFCParamList *param_list = CFCMethod_get_param_list(method);
+
+    if (CFCParamList_num_vars(param_list) == 1) {
+        char pattern[] =
+            "(PyObject *self, PyObject *unused) {\n"
+            "    CFISH_UNUSED_VAR(unused);\n"
+            ;
+        return CFCUtil_sprintf(pattern);
+    }
+    else {
+        char pattern[] =
+            "(PyObject *self, PyObject *args, PyObject *kwargs) {\n"
+            ;
+        char *result = CFCUtil_sprintf(pattern);
+        return result;
+    }
+}
+
 char*
 CFCPyMethod_wrapper(CFCMethod *method, CFCClass *invoker) {
     char *meth_sym   = CFCMethod_full_method_sym(method, invoker);
+    char *meth_top   = S_meth_top(method);
 
     char pattern[] =
         "static PyObject*\n"
-        "S_%s(PyObject *unused1, PyObject *unused2) {\n"
-        "    CFISH_UNUSED_VAR(unused1);\n"
-        "    CFISH_UNUSED_VAR(unused2);\n"
+        "S_%s%s"
         "    Py_RETURN_NONE;\n"
         "}\n"
         ;
-    char *wrapper = CFCUtil_sprintf(pattern, meth_sym);
+    char *wrapper = CFCUtil_sprintf(pattern, meth_sym, meth_top);
     FREEMEM(meth_sym);
+    FREEMEM(meth_top);
 
     return wrapper;
 }


Mime
View raw message