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/02/01 02:16:59 UTC

[lucy-commits] svn commit: r1065879 - in /incubator/lucy/trunk/clownfish: include/CFC.h lib/Clownfish.xs lib/Clownfish/ParamList.pm src/CFCParamList.c src/CFCParamList.h typemap

Author: marvin
Date: Tue Feb  1 01:16:59 2011
New Revision: 1065879

URL: http://svn.apache.org/viewvc?rev=1065879&view=rev
Log:
Migrate Clownfish::ParamList to a partial C implementation.

Added:
    incubator/lucy/trunk/clownfish/src/CFCParamList.c
    incubator/lucy/trunk/clownfish/src/CFCParamList.h
Modified:
    incubator/lucy/trunk/clownfish/include/CFC.h
    incubator/lucy/trunk/clownfish/lib/Clownfish.xs
    incubator/lucy/trunk/clownfish/lib/Clownfish/ParamList.pm
    incubator/lucy/trunk/clownfish/typemap

Modified: incubator/lucy/trunk/clownfish/include/CFC.h
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/include/CFC.h?rev=1065879&r1=1065878&r2=1065879&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/include/CFC.h (original)
+++ incubator/lucy/trunk/clownfish/include/CFC.h Tue Feb  1 01:16:59 2011
@@ -15,4 +15,5 @@
  */
 
 #include "CFCType.h"
+#include "CFCParamList.h"
 

Modified: incubator/lucy/trunk/clownfish/lib/Clownfish.xs
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish.xs?rev=1065879&r1=1065878&r2=1065879&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish.xs (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish.xs Tue Feb  1 01:16:59 2011
@@ -48,6 +48,49 @@
         XSRETURN(0); \
     } 
 
+MODULE = Clownfish    PACKAGE = Clownfish::ParamList
+
+SV*
+_new(klass, variables, values, variadic)
+    const char *klass;
+    SV *variables;
+    SV *values;
+    int variadic;
+CODE:
+    CFCParamList *self = CFCParamList_new(variables, values, variadic);
+    RETVAL = newSV(0);
+	sv_setref_pv(RETVAL, klass, (void*)self);
+OUTPUT: RETVAL
+
+void
+DESTROY(self)
+    CFCParamList *self;
+PPCODE:
+    CFCParamList_destroy(self);
+
+void
+_set_or_get(self, ...)
+    CFCParamList *self;
+ALIAS:
+    get_variables      = 2
+    get_initial_values = 4
+    variadic           = 6
+PPCODE:
+{
+    START_SET_OR_GET_SWITCH
+        case 2:
+            retval = newSVsv((SV*)CFCParamList_get_variables(self));
+            break;
+        case 4:
+            retval = newSVsv((SV*)CFCParamList_get_initial_values(self));
+            break;
+        case 6:
+            retval = newSViv(CFCParamList_variadic(self));
+            break;
+    END_SET_OR_GET_SWITCH
+}
+
+
 MODULE = Clownfish    PACKAGE = Clownfish::Type
 
 SV*

Modified: incubator/lucy/trunk/clownfish/lib/Clownfish/ParamList.pm
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish/ParamList.pm?rev=1065879&r1=1065878&r2=1065879&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish/ParamList.pm (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish/ParamList.pm Tue Feb  1 01:16:59 2011
@@ -28,39 +28,39 @@ our %new_PARAMS = (
 );
 
 sub new {
-    my $either = shift;
-    verify_args( \%new_PARAMS, @_ ) or confess $@;
-    my $self = bless { %new_PARAMS, @_, }, ref($either) || $either;
+    my ( $either, %args ) = @_;
+    verify_args( \%new_PARAMS, %args ) or confess $@;
+    my $class_name = ref($either) || $either;
+    my $variables  = delete $args{variables};
+    my $values     = delete $args{initial_values};
+    my $variadic   = delete $args{variadic} || 0;
 
     # Validate variables.
     confess "variables must be an arrayref"
-        unless ref( $self->get_variables ) eq 'ARRAY';
-    for my $var ( @{ $self->get_variables } ) {
+        unless ref($variables) eq 'ARRAY';
+    for my $var (@$variables) {
         confess "invalid variable: '$var'"
             unless ref($var) && $var->isa("Clownfish::Variable");
     }
 
     # Validate or init initial_values.
-    if ( defined $self->get_initial_values ) {
+    if ( defined $values ) {
         confess "variables must be an arrayref"
-            unless ref( $self->get_initial_values ) eq 'ARRAY';
-        my $num_init = scalar @{ $self->get_initial_values };
-        my $num_vars = $self->num_vars;
+            unless ref($values) eq 'ARRAY';
+        my $num_init = scalar @$values;
+        my $num_vars = scalar @$variables;
         confess("mismatch of num vars and init values: $num_vars $num_init")
             unless $num_init == $num_vars;
     }
     else {
         my @initial_values;
-        $#initial_values = $#{ $self->get_variables };
-        $self->{initial_values} = \@initial_values;
+        $#initial_values = $#$variables;
+        $values          = \@initial_values;
     }
 
-    return $self;
+    return $class_name->_new( $variables, $values, $variadic );
 }
 
-sub get_variables      { shift->{variables} }
-sub get_initial_values { shift->{initial_values} }
-sub variadic           { shift->{variadic} }
 sub num_vars           { scalar @{ shift->get_variables } }
 
 sub to_c {

Added: incubator/lucy/trunk/clownfish/src/CFCParamList.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCParamList.c?rev=1065879&view=auto
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCParamList.c (added)
+++ incubator/lucy/trunk/clownfish/src/CFCParamList.c Tue Feb  1 01:16:59 2011
@@ -0,0 +1,73 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdlib.h>
+#include "EXTERN.h"
+#include "perl.h"
+#include "XSUB.h"
+
+#include "CFCParamList.h"
+
+struct CFCParamList {
+    void *variables;
+    void *values;
+    int   variadic;
+};
+
+CFCParamList*
+CFCParamList_new(void *variables, void *values, int variadic)
+{
+    CFCParamList *self = (CFCParamList*)malloc(sizeof(CFCParamList));
+    if (!self) { croak("malloc failed"); }
+    return CFCParamList_init(self, variables, values, variadic);
+}
+
+CFCParamList*
+CFCParamList_init(CFCParamList *self, void *variables, void *values, 
+                  int variadic)
+{
+    self->variables   = newSVsv((SV*)variables);
+    self->values      = newSVsv((SV*)values);
+    self->variadic    = variadic;
+    return self;
+}
+
+void
+CFCParamList_destroy(CFCParamList *self)
+{
+    SvREFCNT_dec((SV*)self->variables);
+    SvREFCNT_dec((SV*)self->values);
+    free(self);
+}
+
+void*
+CFCParamList_get_variables(CFCParamList *self)
+{
+    return self->variables;
+}
+
+void*
+CFCParamList_get_initial_values(CFCParamList *self)
+{
+    return self->values;
+}
+
+int
+CFCParamList_variadic(CFCParamList *self)
+{
+    return self->variadic;
+}
+

Added: incubator/lucy/trunk/clownfish/src/CFCParamList.h
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCParamList.h?rev=1065879&view=auto
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCParamList.h (added)
+++ incubator/lucy/trunk/clownfish/src/CFCParamList.h Tue Feb  1 01:16:59 2011
@@ -0,0 +1,37 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+typedef struct CFCParamList CFCParamList;
+
+CFCParamList*
+CFCParamList_new(void *variables, void *initial_values, int variadic);
+
+CFCParamList*
+CFCParamList_init(CFCParamList *self, void *variables, void *initial_values,
+                  int variadic);
+
+void
+CFCParamList_destroy(CFCParamList *self);
+
+void*
+CFCParamList_get_variables(CFCParamList *self);
+
+void*
+CFCParamList_get_initial_values(CFCParamList *self);
+
+int
+CFCParamList_variadic(CFCParamList *self);
+

Modified: incubator/lucy/trunk/clownfish/typemap
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/typemap?rev=1065879&r1=1065878&r2=1065879&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/typemap (original)
+++ incubator/lucy/trunk/clownfish/typemap Tue Feb  1 01:16:59 2011
@@ -15,6 +15,7 @@
 
 TYPEMAP
 CFCType*	CLOWNFISH_TYPE
+CFCParamList*	CLOWNFISH_TYPE
 
 INPUT