Repository: lucy-clownfish Updated Branches: refs/heads/master d8ecb8d38 -> 4adae97b2
Generalize test for whether func can be bound. The algorithm for determining whether bindings can be generated automatically for a Clownfish function will likely the same across all all hosts. Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/1892f4fb Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/1892f4fb Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/1892f4fb Branch: refs/heads/master Commit: 1892f4fbb62c4f785c27c99fa043f8748cca26de Parents: d8ecb8d Author: Marvin Humphrey <[email protected]> Authored: Mon Apr 6 16:22:42 2015 -0700 Committer: Marvin Humphrey <[email protected]> Committed: Mon Apr 6 17:19:36 2015 -0700 ---------------------------------------------------------------------- compiler/src/CFCFunction.c | 23 +++++++++++++++++++++++ compiler/src/CFCFunction.h | 5 +++++ compiler/src/CFCPerlClass.c | 7 ++++--- compiler/src/CFCPerlMethod.c | 2 +- compiler/src/CFCPerlSub.c | 24 ------------------------ compiler/src/CFCPerlSub.h | 5 ----- 6 files changed, 33 insertions(+), 33 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/1892f4fb/compiler/src/CFCFunction.c ---------------------------------------------------------------------- diff --git a/compiler/src/CFCFunction.c b/compiler/src/CFCFunction.c index f0ee468..c875507 100644 --- a/compiler/src/CFCFunction.c +++ b/compiler/src/CFCFunction.c @@ -27,6 +27,7 @@ #include "CFCParcel.h" #include "CFCType.h" #include "CFCParamList.h" +#include "CFCVariable.h" #include "CFCDocuComment.h" #include "CFCUtil.h" @@ -97,6 +98,28 @@ CFCFunction_destroy(CFCFunction *self) { CFCSymbol_destroy((CFCSymbol*)self); } +int +CFCFunction_can_be_bound(CFCFunction *self) { + // Test whether parameters can be mapped automatically. + CFCVariable **arg_vars = CFCParamList_get_variables(self->param_list); + for (size_t i = 0; arg_vars[i] != NULL; i++) { + CFCType *type = CFCVariable_get_type(arg_vars[i]); + if (!CFCType_is_object(type) && !CFCType_is_primitive(type)) { + return false; + } + } + + // Test whether return type can be mapped automatically. + if (!CFCType_is_void(self->return_type) + && !CFCType_is_object(self->return_type) + && !CFCType_is_primitive(self->return_type) + ) { + return false; + } + + return true; +} + CFCType* CFCFunction_get_return_type(CFCFunction *self) { return self->return_type; http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/1892f4fb/compiler/src/CFCFunction.h ---------------------------------------------------------------------- diff --git a/compiler/src/CFCFunction.h b/compiler/src/CFCFunction.h index 752d2da..f2b6794 100644 --- a/compiler/src/CFCFunction.h +++ b/compiler/src/CFCFunction.h @@ -78,6 +78,11 @@ CFCFunction_init(CFCFunction *self, struct CFCParcel *parcel, void CFCFunction_destroy(CFCFunction *self); +/** Test whether bindings can be generated for a function. + */ +int +CFCFunction_can_be_bound(CFCFunction *function); + struct CFCType* CFCFunction_get_return_type(CFCFunction *self); http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/1892f4fb/compiler/src/CFCPerlClass.c ---------------------------------------------------------------------- diff --git a/compiler/src/CFCPerlClass.c b/compiler/src/CFCPerlClass.c index 782f719..e7263c4 100644 --- a/compiler/src/CFCPerlClass.c +++ b/compiler/src/CFCPerlClass.c @@ -23,6 +23,7 @@ #include "CFCPerlClass.h" #include "CFCUtil.h" #include "CFCClass.h" +#include "CFCFunction.h" #include "CFCMethod.h" #include "CFCParcel.h" #include "CFCParamList.h" @@ -288,7 +289,7 @@ CFCPerlClass_constructor_bindings(CFCClass *klass) { if (perl_class == NULL) { // Bind init() to new() when possible. if (strcmp(micro_sym, "init") == 0 - && CFCPerlSub_can_be_bound(function) + && CFCFunction_can_be_bound(function) ) { alias = NEW; } @@ -297,7 +298,7 @@ CFCPerlClass_constructor_bindings(CFCClass *klass) { for (size_t j = 0; j < perl_class->num_cons; j++) { if (strcmp(micro_sym, perl_class->cons_inits[j]) == 0) { alias = perl_class->cons_aliases[j]; - if (!CFCPerlSub_can_be_bound(function)) { + if (!CFCFunction_can_be_bound(function)) { CFCUtil_die("Can't bind %s as %s" " -- types can't be mapped", micro_sym, alias); @@ -310,7 +311,7 @@ CFCPerlClass_constructor_bindings(CFCClass *klass) { if (!alias && !perl_class->exclude_cons && strcmp(micro_sym, "init") == 0 - && CFCPerlSub_can_be_bound(function) + && CFCFunction_can_be_bound(function) ) { int saw_new = 0; for (size_t j = 0; j < perl_class->num_cons; j++) { http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/1892f4fb/compiler/src/CFCPerlMethod.c ---------------------------------------------------------------------- diff --git a/compiler/src/CFCPerlMethod.c b/compiler/src/CFCPerlMethod.c index 2a2aa5f..7d0a7fa 100644 --- a/compiler/src/CFCPerlMethod.c +++ b/compiler/src/CFCPerlMethod.c @@ -129,7 +129,7 @@ CFCPerlMethod_can_be_bound(CFCMethod *method) { * - methods with types which cannot be mapped automatically */ return !CFCSymbol_private((CFCSymbol*)method) - && CFCPerlSub_can_be_bound((CFCFunction*)method); + && CFCFunction_can_be_bound((CFCFunction*)method); } char* http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/1892f4fb/compiler/src/CFCPerlSub.c ---------------------------------------------------------------------- diff --git a/compiler/src/CFCPerlSub.c b/compiler/src/CFCPerlSub.c index d114521..0051258 100644 --- a/compiler/src/CFCPerlSub.c +++ b/compiler/src/CFCPerlSub.c @@ -73,30 +73,6 @@ CFCPerlSub_destroy(CFCPerlSub *self) { CFCBase_destroy((CFCBase*)self); } -int -CFCPerlSub_can_be_bound(CFCFunction *function) { - // Test whether parameters can be mapped automatically. - CFCParamList *param_list = CFCFunction_get_param_list(function); - CFCVariable **arg_vars = CFCParamList_get_variables(param_list); - for (size_t i = 0; arg_vars[i] != NULL; i++) { - CFCType *type = CFCVariable_get_type(arg_vars[i]); - if (!CFCType_is_object(type) && !CFCType_is_primitive(type)) { - return false; - } - } - - // Test whether return type can be mapped automatically. - CFCType *return_type = CFCFunction_get_return_type(function); - if (!CFCType_is_void(return_type) - && !CFCType_is_object(return_type) - && !CFCType_is_primitive(return_type) - ) { - return false; - } - - return true; -} - char* CFCPerlSub_params_hash_def(CFCPerlSub *self) { if (!self->use_labeled_params) { http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/1892f4fb/compiler/src/CFCPerlSub.h ---------------------------------------------------------------------- diff --git a/compiler/src/CFCPerlSub.h b/compiler/src/CFCPerlSub.h index 8582818..945ad6d 100644 --- a/compiler/src/CFCPerlSub.h +++ b/compiler/src/CFCPerlSub.h @@ -65,11 +65,6 @@ CFCPerlSub_init(CFCPerlSub *self, struct CFCParamList *param_list, void CFCPerlSub_destroy(CFCPerlSub *self); -/** Test whether bindings can be generated for a function. - */ -int -CFCPerlSub_can_be_bound(struct CFCFunction *function); - /** Return Perl code initializing a package-global hash where all the keys are * the names of labeled params. The hash's name consists of the the binding's * perl_name() plus "_PARAMS".
