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/15 18:06:30 UTC
[lucy-commits] svn commit: r1070972 - in /incubator/lucy/trunk/clownfish: include/CFC.h
lib/Clownfish.xs lib/Clownfish/File.pm src/CFCFile.c src/CFCFile.h typemap
Author: marvin
Date: Tue Feb 15 17:06:29 2011
New Revision: 1070972
URL: http://svn.apache.org/viewvc?rev=1070972&view=rev
Log:
Change Clownfish::File to inside-out pattern wrapped around a skeletal C
implementation.
Added:
incubator/lucy/trunk/clownfish/src/CFCFile.c
incubator/lucy/trunk/clownfish/src/CFCFile.h
Modified:
incubator/lucy/trunk/clownfish/include/CFC.h
incubator/lucy/trunk/clownfish/lib/Clownfish.xs
incubator/lucy/trunk/clownfish/lib/Clownfish/File.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=1070972&r1=1070971&r2=1070972&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/include/CFC.h (original)
+++ incubator/lucy/trunk/clownfish/include/CFC.h Tue Feb 15 17:06:29 2011
@@ -17,6 +17,7 @@
#include "CFCCBlock.h"
#include "CFCClass.h"
#include "CFCDocuComment.h"
+#include "CFCFile.h"
#include "CFCFunction.h"
#include "CFCMethod.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=1070972&r1=1070971&r2=1070972&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish.xs (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish.xs Tue Feb 15 17:06:29 2011
@@ -180,6 +180,24 @@ PPCODE:
}
+MODULE = Clownfish PACKAGE = Clownfish::File
+
+SV*
+_new(klass)
+ const char *klass;
+CODE:
+ CFCFile *self = CFCFile_new();
+ RETVAL = newSV(0);
+ sv_setref_pv(RETVAL, klass, (void*)self);
+OUTPUT: RETVAL
+
+void
+_destroy(self)
+ CFCFile *self;
+PPCODE:
+ CFCFile_destroy(self);
+
+
MODULE = Clownfish PACKAGE = Clownfish::Function
SV*
Modified: incubator/lucy/trunk/clownfish/lib/Clownfish/File.pm
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish/File.pm?rev=1070972&r1=1070971&r2=1070972&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish/File.pm (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish/File.pm Tue Feb 15 17:06:29 2011
@@ -23,6 +23,12 @@ use Scalar::Util qw( blessed );
use File::Spec::Functions qw( catfile );
use Carp;
+# Inside out member vars.
+our %blocks;
+our %source_class;
+our %parcel;
+our %modified;
+
our %new_PARAMS = (
blocks => undef,
source_class => undef,
@@ -32,24 +38,13 @@ our %new_PARAMS = (
sub new {
my ( $either, %args ) = @_;
verify_args( \%new_PARAMS, %args ) or confess $@;
- my $parcel = $args{parcel};
- if ( defined $parcel ) {
- if ( !blessed($parcel) ) {
- $parcel = Clownfish::Parcel->singleton( name => $parcel );
- }
- confess("Not a Clownfish::Parcel")
- unless $parcel->isa('Clownfish::Parcel');
- }
- my $self = bless {
- %new_PARAMS,
- blocks => [],
- source_class => undef,
- modified => 0,
- %args,
- parcel => $parcel,
- },
- ref($either) || $either;
- for my $block ( @{ $self->{blocks} } ) {
+ my $package = ref($either) || $either;
+ my $self = $either->_new();
+ $parcel{$self} = Clownfish::Parcel->acquire( $args{parcel} );
+ $blocks{$self} = $args{blocks} || [];
+ $source_class{$self} = $args{source_class};
+ $modified{$self} = 0;
+ for my $block ( $self->blocks ) {
next if a_isa_b( $block, "Clownfish::Parcel" );
next if a_isa_b( $block, "Clownfish::Class" );
next if a_isa_b( $block, "Clownfish::CBlock" );
@@ -60,16 +55,25 @@ sub new {
return $self;
}
-sub get_modified { shift->{modified} }
-sub set_modified { $_[0]->{modified} = $_[1] }
-sub get_source_class { shift->{source_class} }
+sub DESTROY {
+ my $self = shift;
+ delete $parcel{$self};
+ delete $blocks{$self};
+ delete $source_class{$self};
+ delete $modified{$self};
+ $self->_destroy;
+}
+
+sub get_modified { $modified{ +shift } }
+sub set_modified { $modified{ $_[0] } = $_[1] }
+sub get_source_class { $source_class{ +shift } }
-sub blocks { @{ shift->{blocks} } }
+sub blocks { @{ $blocks{+shift} } }
sub classes {
my $self = shift;
return
- grep { ref $_ and $_->isa('Clownfish::Class') } @{ $self->{blocks} };
+ grep { ref $_ and $_->isa('Clownfish::Class') } $self->blocks;
}
# Return a string used for an include guard, unique per file.
Added: incubator/lucy/trunk/clownfish/src/CFCFile.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCFile.c?rev=1070972&view=auto
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCFile.c (added)
+++ incubator/lucy/trunk/clownfish/src/CFCFile.c Tue Feb 15 17:06:29 2011
@@ -0,0 +1,47 @@
+/* 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 "CFCFile.h"
+
+struct CFCFile {
+ int dummy;
+};
+
+CFCFile*
+CFCFile_new(void)
+{
+ CFCFile *self = (CFCFile*)malloc(sizeof(CFCFile));
+ if (!self) { croak("malloc failed"); }
+ return CFCFile_init(self);
+}
+
+CFCFile*
+CFCFile_init(CFCFile *self)
+{
+ return self;
+}
+
+void
+CFCFile_destroy(CFCFile *self)
+{
+ free(self);
+}
+
Added: incubator/lucy/trunk/clownfish/src/CFCFile.h
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCFile.h?rev=1070972&view=auto
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCFile.h (added)
+++ incubator/lucy/trunk/clownfish/src/CFCFile.h Tue Feb 15 17:06:29 2011
@@ -0,0 +1,28 @@
+/* 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 CFCFile CFCFile;
+
+CFCFile*
+CFCFile_new(void);
+
+CFCFile*
+CFCFile_init(CFCFile *self);
+
+void
+CFCFile_destroy(CFCFile *self);
+
+
Modified: incubator/lucy/trunk/clownfish/typemap
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/typemap?rev=1070972&r1=1070971&r2=1070972&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/typemap (original)
+++ incubator/lucy/trunk/clownfish/typemap Tue Feb 15 17:06:29 2011
@@ -17,6 +17,7 @@ TYPEMAP
CFCCBlock* CLOWNFISH_TYPE
CFCClass* CLOWNFISH_TYPE
CFCDocuComment* CLOWNFISH_TYPE
+CFCFile* CLOWNFISH_TYPE
CFCFunction* CLOWNFISH_TYPE
CFCMethod* CLOWNFISH_TYPE
CFCParamList* CLOWNFISH_TYPE