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 2011/07/22 02:57:59 UTC
[lucy-commits] svn commit: r1149424 - in /incubator/lucy/trunk/clownfish: lib/Clownfish.xs
lib/Clownfish/Binding/Perl/Subroutine.pm src/CFCPerlSub.c src/CFCPerlSub.h
Author: marvin
Date: Fri Jul 22 00:57:58 2011
New Revision: 1149424
URL: http://svn.apache.org/viewvc?rev=1149424&view=rev
Log:
Port params_hash_def() to C.
Port the routine that generates the Perl hash holding parameters and default
values for each method which takes labeled params.
Modified:
incubator/lucy/trunk/clownfish/lib/Clownfish.xs
incubator/lucy/trunk/clownfish/lib/Clownfish/Binding/Perl/Subroutine.pm
incubator/lucy/trunk/clownfish/src/CFCPerlSub.c
incubator/lucy/trunk/clownfish/src/CFCPerlSub.h
Modified: incubator/lucy/trunk/clownfish/lib/Clownfish.xs
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish.xs?rev=1149424&r1=1149423&r2=1149424&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish.xs (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish.xs Fri Jul 22 00:57:58 2011
@@ -1914,3 +1914,10 @@ PPCODE:
END_SET_OR_GET_SWITCH
}
+SV*
+params_hash_def(self)
+ CFCPerlSub *self;
+CODE:
+ RETVAL = S_sv_eat_c_string(CFCPerlSub_params_hash_def(self));
+OUTPUT: RETVAL
+
Modified: incubator/lucy/trunk/clownfish/lib/Clownfish/Binding/Perl/Subroutine.pm
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish/Binding/Perl/Subroutine.pm?rev=1149424&r1=1149423&r2=1149424&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish/Binding/Perl/Subroutine.pm (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish/Binding/Perl/Subroutine.pm Fri Jul 22 00:57:58 2011
@@ -46,41 +46,6 @@ sub new {
@args{qw( param_list class_name alias use_labeled_params )} );
}
-my %params_hash_vals_map = (
- NULL => 'undef',
- true => 1,
- false => 0,
-);
-
-sub params_hash_def {
- my $self = shift;
- return unless $self->use_labeled_params;
-
- my $params_hash_name = $self->perl_name . "_PARAMS";
- my $arg_vars = $self->get_param_list->get_variables;
- my $vals = $self->get_param_list->get_initial_values;
- my @pairs;
- for ( my $i = 1; $i < @$arg_vars; $i++ ) {
- my $var = $arg_vars->[$i];
- my $val = $vals->[$i];
- if ( !defined $val ) {
- $val = 'undef';
- }
- elsif ( exists $params_hash_vals_map{$val} ) {
- $val = $params_hash_vals_map{$val};
- }
- push @pairs, $var->micro_sym . " => $val,";
- }
-
- if (@pairs) {
- my $list = join( "\n ", @pairs );
- return qq|\%$params_hash_name = (\n $list\n);\n|;
- }
- else {
- return qq|\%$params_hash_name = ();\n|;
- }
-}
-
my %prim_type_to_allot_macro = (
double => 'ALLOT_F64',
float => 'ALLOT_F32',
Modified: incubator/lucy/trunk/clownfish/src/CFCPerlSub.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCPerlSub.c?rev=1149424&r1=1149423&r2=1149424&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCPerlSub.c (original)
+++ incubator/lucy/trunk/clownfish/src/CFCPerlSub.c Fri Jul 22 00:57:58 2011
@@ -20,6 +20,7 @@
#include "CFCPerlSub.h"
#include "CFCUtil.h"
#include "CFCParamList.h"
+#include "CFCVariable.h"
struct CFCPerlSub {
CFCBase base;
@@ -84,6 +85,44 @@ CFCPerlSub_destroy(CFCPerlSub *self) {
CFCBase_destroy((CFCBase*)self);
}
+char*
+CFCPerlSub_params_hash_def(CFCPerlSub *self)
+{
+ if (!self->use_labeled_params) {
+ return NULL;
+ }
+
+ char *def = CFCUtil_strdup("");
+ def = CFCUtil_cat(def, "%", self->perl_name, "_PARAMS = (", NULL);
+
+ CFCVariable **arg_vars = CFCParamList_get_variables(self->param_list);
+ const char **vals = CFCParamList_get_initial_values(self->param_list);
+
+ // No labeled params means an empty params hash def.
+ if (!arg_vars[1]) {
+ def = CFCUtil_cat(def, ");\n", NULL);
+ return def;
+ }
+
+ for (int i = 1; arg_vars[i] != NULL; i++) {
+ CFCVariable *var = arg_vars[i];
+ const char *micro_sym = CFCVariable_micro_sym(var);
+ const char *val = vals[i];
+ val = val == NULL
+ ? "undef"
+ : strcmp(val, "NULL") == 0
+ ? "undef"
+ : strcmp(val, "true") == 0
+ ? "1"
+ : strcmp(val, "false") == 0
+ ? "0"
+ : val;
+ def = CFCUtil_cat(def, "\n ", micro_sym, " => ", val, ",", NULL);
+ }
+ def = CFCUtil_cat(def, "\n);\n", NULL);
+
+ return def;
+}
CFCParamList*
CFCPerlSub_get_param_list(CFCPerlSub *self) {
Modified: incubator/lucy/trunk/clownfish/src/CFCPerlSub.h
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCPerlSub.h?rev=1149424&r1=1149423&r2=1149424&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCPerlSub.h (original)
+++ incubator/lucy/trunk/clownfish/src/CFCPerlSub.h Fri Jul 22 00:57:58 2011
@@ -37,6 +37,9 @@ CFCPerlSub_init(CFCPerlSub *self, struct
void
CFCPerlSub_destroy(CFCPerlSub *self);
+char*
+CFCPerlSub_params_hash_def(CFCPerlSub *self);
+
struct CFCParamList*
CFCPerlSub_get_param_list(CFCPerlSub *self);