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/03/01 04:03:23 UTC
[15/22] lucy-clownfish git commit: Stub out generated Python
constructors.
Stub out generated Python constructors.
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/5443a743
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/5443a743
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/5443a743
Branch: refs/heads/master
Commit: 5443a74386b0bd6217d12c16a5ef9265c99d78c7
Parents: d8ced59
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Tue Feb 2 17:50:12 2016 -0800
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Wed Feb 24 15:36:07 2016 -0800
----------------------------------------------------------------------
compiler/src/CFCPyClass.c | 23 +++++++++++++++++++++--
compiler/src/CFCPyMethod.c | 18 ++++++++++++++++++
compiler/src/CFCPyMethod.h | 7 +++++++
3 files changed, 46 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/5443a743/compiler/src/CFCPyClass.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCPyClass.c b/compiler/src/CFCPyClass.c
index 529c6cf..0fe168e 100644
--- a/compiler/src/CFCPyClass.c
+++ b/compiler/src/CFCPyClass.c
@@ -145,6 +145,14 @@ CFCPyClass_gen_binding_code(CFCPyClass *self) {
char *bindings = CFCUtil_strdup(self->pre_code ? self->pre_code : "");
char *meth_defs = CFCUtil_strdup(self->meth_defs);
+ // Constructor.
+ CFCFunction *init_func = CFCClass_function(klass, "init");
+ if (init_func && CFCFunction_can_be_bound(init_func)) {
+ char *wrapper = CFCPyMethod_constructor_wrapper(init_func, klass);
+ bindings = CFCUtil_cat(bindings, wrapper, "\n", NULL);
+ FREEMEM(wrapper);
+ }
+
// Instance methods.
CFCMethod **methods = CFCClass_fresh_methods(klass);
for (size_t j = 0; methods[j] != NULL; j++) {
@@ -201,6 +209,16 @@ S_pytype_struct_def(CFCPyClass *self) {
const char *struct_sym = CFCClass_get_struct_sym(klass);
+ char *tp_new;
+ CFCFunction *init_func = CFCClass_function(klass, "init");
+ if (init_func && CFCFunction_can_be_bound(init_func)) {
+ tp_new = CFCUtil_sprintf("S_%s_PY_NEW",
+ CFCClass_full_struct_sym(klass));
+ }
+ else {
+ tp_new = CFCUtil_strdup("0");
+ }
+
char pattern[] =
"static PyTypeObject %s_pytype_struct = {\n"
" PyVarObject_HEAD_INIT(NULL, 0)\n"
@@ -240,12 +258,13 @@ S_pytype_struct_def(CFCPyClass *self) {
" 0, // tp_dictoffset\n"
" 0, // tp_init\n"
" 0, // tp_allow\n"
- " 0, // tp_new\n"
+ " %s, // tp_new\n"
"};\n"
;
char *content = CFCUtil_sprintf(pattern, struct_sym, pymod_name,
- struct_sym, struct_sym);
+ struct_sym, struct_sym, tp_new);
+ FREEMEM(tp_new);
FREEMEM(pymod_name);
return content;
}
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/5443a743/compiler/src/CFCPyMethod.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCPyMethod.c b/compiler/src/CFCPyMethod.c
index 1291568..c93252e 100644
--- a/compiler/src/CFCPyMethod.c
+++ b/compiler/src/CFCPyMethod.c
@@ -520,6 +520,24 @@ CFCPyMethod_wrapper(CFCMethod *method, CFCClass *invoker) {
}
char*
+CFCPyMethod_constructor_wrapper(CFCFunction *init_func, CFCClass *invoker) {
+ const char *struct_sym = CFCClass_full_struct_sym(invoker);
+
+ char pattern[] =
+ "static PyObject*\n"
+ "S_%s_PY_NEW(PyTypeObject *type, PyObject *args, PyObject *kwargs) {\n"
+ " CFISH_UNUSED_VAR(type);\n"
+ " CFISH_UNUSED_VAR(args);\n"
+ " CFISH_UNUSED_VAR(kwargs);\n"
+ " Py_RETURN_NONE;\n"
+ "}\n"
+ ;
+ char *wrapper = CFCUtil_sprintf(pattern, struct_sym);
+
+ return wrapper;
+}
+
+char*
CFCPyMethod_pymethoddef(CFCMethod *method, CFCClass *invoker) {
CFCParamList *param_list = CFCMethod_get_param_list(method);
const char *flags = CFCParamList_num_vars(param_list) == 1
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/5443a743/compiler/src/CFCPyMethod.h
----------------------------------------------------------------------
diff --git a/compiler/src/CFCPyMethod.h b/compiler/src/CFCPyMethod.h
index b3d6808..f85844f 100644
--- a/compiler/src/CFCPyMethod.h
+++ b/compiler/src/CFCPyMethod.h
@@ -21,6 +21,7 @@
extern "C" {
#endif
+struct CFCFunction;
struct CFCMethod;
struct CFCClass;
@@ -39,6 +40,12 @@ CFCPyMethod_pymethoddef(struct CFCMethod *method, struct CFCClass *invoker);
char*
CFCPyMethod_wrapper(struct CFCMethod *method, struct CFCClass *invoker);
+/** Generate glue code for a constructor.
+ */
+char*
+CFCPyMethod_constructor_wrapper(struct CFCFunction *init_func,
+ struct CFCClass *invoker);
+
#ifdef __cplusplus
}
#endif