You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by nw...@apache.org on 2015/05/09 19:50:02 UTC
[05/11] lucy-clownfish git commit: Call method name helpers with
non-null class
Call method name helpers with non-null class
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/ac313c1a
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/ac313c1a
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/ac313c1a
Branch: refs/heads/master
Commit: ac313c1a41508c8a457a5318002a9b7cfbf4e072
Parents: 8847fbf
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Sat Jul 26 23:09:08 2014 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Thu May 7 21:13:59 2015 +0200
----------------------------------------------------------------------
compiler/perl/lib/Clownfish/CFC.xs | 5 +++--
compiler/src/CFCMethod.c | 24 +++++-------------------
compiler/src/CFCPerl.c | 2 +-
compiler/src/CFCPerlMethod.c | 33 +++++++++++++--------------------
compiler/src/CFCPerlMethod.h | 3 ++-
5 files changed, 24 insertions(+), 43 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/ac313c1a/compiler/perl/lib/Clownfish/CFC.xs
----------------------------------------------------------------------
diff --git a/compiler/perl/lib/Clownfish/CFC.xs b/compiler/perl/lib/Clownfish/CFC.xs
index b87cc0b..02f7eaf 100644
--- a/compiler/perl/lib/Clownfish/CFC.xs
+++ b/compiler/perl/lib/Clownfish/CFC.xs
@@ -2181,10 +2181,11 @@ CODE:
OUTPUT: RETVAL
SV*
-xsub_def(self)
+xsub_def(self, klass)
CFCPerlMethod *self;
+ CFCClass *klass;
CODE:
- RETVAL = S_sv_eat_c_string(CFCPerlMethod_xsub_def(self));
+ RETVAL = S_sv_eat_c_string(CFCPerlMethod_xsub_def(self, klass));
OUTPUT: RETVAL
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/ac313c1a/compiler/src/CFCMethod.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCMethod.c b/compiler/src/CFCMethod.c
index ff1f4f6..8ee3e9c 100644
--- a/compiler/src/CFCMethod.c
+++ b/compiler/src/CFCMethod.c
@@ -313,30 +313,16 @@ CFCMethod_find_novel_method(CFCMethod *self) {
static char*
S_short_method_sym(CFCMethod *self, CFCClass *invoker, const char *postfix) {
- const char *nickname;
- if (invoker) {
- nickname = CFCClass_get_nickname(invoker);
- }
- else {
- nickname = CFCMethod_get_class_nickname(self);
- }
- const char *name = CFCMethod_get_name(self);
+ const char *nickname = CFCClass_get_nickname(invoker);
+ const char *name = CFCMethod_get_name(self);
return CFCUtil_sprintf("%s_%s%s", nickname, name, postfix);
}
static char*
S_full_method_sym(CFCMethod *self, CFCClass *invoker, const char *postfix) {
- const char *PREFIX;
- const char *nickname;
- if (invoker) {
- PREFIX = CFCClass_get_PREFIX(invoker);
- nickname = CFCClass_get_nickname(invoker);
- }
- else {
- PREFIX = CFCMethod_get_PREFIX(self);
- nickname = CFCMethod_get_class_nickname(self);
- }
- const char *name = CFCMethod_get_name(self);
+ const char *PREFIX = CFCClass_get_PREFIX(invoker);
+ const char *nickname = CFCClass_get_nickname(invoker);
+ const char *name = CFCMethod_get_name(self);
return CFCUtil_sprintf("%s%s_%s%s", PREFIX, nickname, name, postfix);
}
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/ac313c1a/compiler/src/CFCPerl.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCPerl.c b/compiler/src/CFCPerl.c
index e8cd424..6947542 100644
--- a/compiler/src/CFCPerl.c
+++ b/compiler/src/CFCPerl.c
@@ -475,7 +475,7 @@ CFCPerl_write_bindings(CFCPerl *self) {
CFCPerlSub *xsub = (CFCPerlSub*)methods[j];
// Add the XSUB function definition.
- char *xsub_def = CFCPerlMethod_xsub_def(methods[j]);
+ char *xsub_def = CFCPerlMethod_xsub_def(methods[j], klass);
generated_xs = CFCUtil_cat(generated_xs, xsub_def, "\n",
NULL);
FREEMEM(xsub_def);
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/ac313c1a/compiler/src/CFCPerlMethod.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCPerlMethod.c b/compiler/src/CFCPerlMethod.c
index 92e4d2f..cfc474a 100644
--- a/compiler/src/CFCPerlMethod.c
+++ b/compiler/src/CFCPerlMethod.c
@@ -39,7 +39,7 @@ struct CFCPerlMethod {
// Return the main chunk of the code for the xsub.
static char*
-S_xsub_body(CFCPerlMethod *self);
+S_xsub_body(CFCPerlMethod *self, CFCClass *klass);
// Create an assignment statement for extracting $self from the Perl stack.
static char*
@@ -47,11 +47,11 @@ S_self_assign_statement(CFCPerlMethod *self, CFCType *type);
// Return code for an xsub which uses labeled params.
static char*
-S_xsub_def_labeled_params(CFCPerlMethod *self);
+S_xsub_def_labeled_params(CFCPerlMethod *self, CFCClass *klass);
// Return code for an xsub which uses positional args.
static char*
-S_xsub_def_positional_args(CFCPerlMethod *self);
+S_xsub_def_positional_args(CFCPerlMethod *self, CFCClass *klass);
/* Generate code which converts C types to Perl types and pushes arguments
* onto the Perl stack.
@@ -140,30 +140,23 @@ CFCPerlMethod_perl_name(CFCMethod *method) {
}
char*
-CFCPerlMethod_xsub_def(CFCPerlMethod *self) {
+CFCPerlMethod_xsub_def(CFCPerlMethod *self, CFCClass *klass) {
if (self->sub.use_labeled_params) {
- return S_xsub_def_labeled_params(self);
+ return S_xsub_def_labeled_params(self, klass);
}
else {
- return S_xsub_def_positional_args(self);
+ return S_xsub_def_positional_args(self, klass);
}
}
static char*
-S_xsub_body(CFCPerlMethod *self) {
+S_xsub_body(CFCPerlMethod *self, CFCClass *klass) {
CFCMethod *method = self->method;
CFCParamList *param_list = CFCMethod_get_param_list(method);
CFCVariable **arg_vars = CFCParamList_get_variables(param_list);
char *name_list = CFCPerlSub_arg_name_list((CFCPerlSub*)self);
char *body = CFCUtil_strdup("");
- CFCParcel *parcel = CFCMethod_get_parcel(method);
- const char *class_name = CFCMethod_get_class_name(method);
- CFCClass *klass = CFCClass_fetch_singleton(parcel, class_name);
- if (!klass) {
- CFCUtil_die("Can't find a CFCClass for '%s'", class_name);
- }
-
// Extract the method function pointer.
char *full_meth = CFCMethod_full_method_sym(method, klass);
char *method_ptr
@@ -230,7 +223,7 @@ S_self_assign_statement(CFCPerlMethod *self, CFCType *type) {
}
static char*
-S_xsub_def_labeled_params(CFCPerlMethod *self) {
+S_xsub_def_labeled_params(CFCPerlMethod *self, CFCClass *klass) {
CFCMethod *method = self->method;
const char *c_name = self->sub.c_name;
CFCParamList *param_list = self->sub.param_list;
@@ -241,10 +234,10 @@ S_xsub_def_labeled_params(CFCPerlMethod *self) {
const char *self_type_c = CFCType_to_c(self_type);
const char *self_name = CFCVariable_get_name(self_var);
char *arg_decls = CFCPerlSub_arg_declarations((CFCPerlSub*)self);
- char *meth_type_c = CFCMethod_full_typedef(method, NULL);
+ char *meth_type_c = CFCMethod_full_typedef(method, klass);
char *self_assign = S_self_assign_statement(self, self_type);
char *allot_params = CFCPerlSub_build_allot_params((CFCPerlSub*)self);
- char *body = S_xsub_body(self);
+ char *body = S_xsub_body(self, klass);
char *retval_decl;
if (CFCType_is_void(return_type)) {
@@ -291,7 +284,7 @@ S_xsub_def_labeled_params(CFCPerlMethod *self) {
}
static char*
-S_xsub_def_positional_args(CFCPerlMethod *self) {
+S_xsub_def_positional_args(CFCPerlMethod *self, CFCClass *klass) {
CFCMethod *method = self->method;
CFCParamList *param_list = CFCMethod_get_param_list(method);
CFCVariable **arg_vars = CFCParamList_get_variables(param_list);
@@ -302,9 +295,9 @@ S_xsub_def_positional_args(CFCPerlMethod *self) {
const char **arg_inits = CFCParamList_get_initial_values(param_list);
unsigned num_vars = (unsigned)CFCParamList_num_vars(param_list);
char *arg_decls = CFCPerlSub_arg_declarations((CFCPerlSub*)self);
- char *meth_type_c = CFCMethod_full_typedef(method, NULL);
+ char *meth_type_c = CFCMethod_full_typedef(method, klass);
char *self_assign = S_self_assign_statement(self, self_type);
- char *body = S_xsub_body(self);
+ char *body = S_xsub_body(self, klass);
// Determine how many args are truly required and build an error check.
unsigned min_required = 0;
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/ac313c1a/compiler/src/CFCPerlMethod.h
----------------------------------------------------------------------
diff --git a/compiler/src/CFCPerlMethod.h b/compiler/src/CFCPerlMethod.h
index be441c4..2e5b7f3 100644
--- a/compiler/src/CFCPerlMethod.h
+++ b/compiler/src/CFCPerlMethod.h
@@ -32,6 +32,7 @@ extern "C" {
* will be set up to accept a single positional argument.
*/
typedef struct CFCPerlMethod CFCPerlMethod;
+struct CFCClass;
struct CFCMethod;
CFCPerlMethod*
@@ -55,7 +56,7 @@ CFCPerlMethod_perl_name(struct CFCMethod *method);
/** Generate C code for the XSUB.
*/
char*
-CFCPerlMethod_xsub_def(CFCPerlMethod *self);
+CFCPerlMethod_xsub_def(CFCPerlMethod *self, struct CFCClass *klass);
/** Return C code implementing a callback to Perl for this method. This code
* is run when a Perl subclass has overridden a method in a Clownfish base