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/06 21:03:26 UTC

[lucy-commits] svn commit: r1143532 - in /incubator/lucy/trunk/clownfish/lib/Clownfish/Binding: Core.pm Core/File.pm

Author: marvin
Date: Wed Jul  6 19:03:26 2011
New Revision: 1143532

URL: http://svn.apache.org/viewvc?rev=1143532&view=rev
Log:
Consolidate autogenerated C into one file.

The Clownfish compiler has heretofore autogenerated one .h file and one .c
file for each .cfh file.  There's not *that* much autogenerated code in the .c
files, though, so we can save time by consolidating them into a single file,
"autogen/parcel.c".

This commit knocks down the time to build Lucy and run its tests from 3:43 to
3:10 on my Snow Leopard MacBook Pro, a savings of approximately 15%.

Modified:
    incubator/lucy/trunk/clownfish/lib/Clownfish/Binding/Core.pm
    incubator/lucy/trunk/clownfish/lib/Clownfish/Binding/Core/File.pm

Modified: incubator/lucy/trunk/clownfish/lib/Clownfish/Binding/Core.pm
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish/Binding/Core.pm?rev=1143532&r1=1143531&r2=1143532&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish/Binding/Core.pm (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish/Binding/Core.pm Wed Jul  6 19:03:26 2011
@@ -22,6 +22,7 @@ use Clownfish::Binding::Core::File;
 use Clownfish::Binding::Core::Aliases;
 use File::Spec::Functions qw( catfile );
 use Fcntl;
+use Scalar::Util qw( blessed );
 
 our %new_PARAMS = (
     hierarchy => undef,
@@ -68,16 +69,12 @@ sub write_all_modified {
             header => $header,
             footer => $footer,
         );
-        Clownfish::Binding::Core::File->write_c(
-            file   => $file,
-            dest   => $dest,
-            header => $header,
-            footer => $footer,
-        );
     }
 
-    # If any class definition changed, rewrite the parcel.h file.
+    # If any class definition has changed, rewrite the parcel.h and parcel.c
+    # files.
     $self->_write_parcel_h if $modified;
+    $self->_write_parcel_c if $modified;
 
     return $modified;
 }
@@ -188,6 +185,49 @@ $self->{footer}
 END_STUFF
 }
 
+sub _write_parcel_c {
+    my $self      = shift;
+    my $hierarchy = $self->{hierarchy};
+
+    # Aggregate C code from all files.
+    my $content     = "";
+    my $c_file_syms = "";
+    my $includes    = "";
+    for my $file ( @{ $hierarchy->files } ) {
+        for my $block ( @{ $file->blocks } ) {
+            if ( blessed($block) ) {
+                if ( $block->isa('Clownfish::Class') ) {
+                    my $bound = Clownfish::Binding::Core::Class->new(
+                        client => $block, );
+                    $content .= $bound->to_c . "\n";
+                    my $c_file_sym = "C_" . uc( $block->full_struct_sym );
+                    $c_file_syms .= "#define $c_file_sym\n";
+                    my $include_h = $block->include_h;
+                    $includes .= qq|#include "$include_h"\n|;
+                }
+            }
+        }
+    }
+
+    # Unlink then open file.
+    my $filepath = catfile( $self->{dest}, "parcel.c" );
+    unlink $filepath;
+    sysopen( my $fh, $filepath, O_CREAT | O_EXCL | O_WRONLY )
+        or confess("Can't open '$filepath': $!");
+    print $fh <<END_STUFF;
+$self->{header}
+
+$c_file_syms
+#include "parcel.h"
+$includes
+
+$content
+
+$self->{footer}
+
+END_STUFF
+}
+
 1;
 
 __END__

Modified: incubator/lucy/trunk/clownfish/lib/Clownfish/Binding/Core/File.pm
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish/Binding/Core/File.pm?rev=1143532&r1=1143531&r2=1143532&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish/Binding/Core/File.pm (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish/Binding/Core/File.pm Wed Jul  6 19:03:26 2011
@@ -98,59 +98,6 @@ my %write_c_PARAMS = (
     footer => undef,
 );
 
-sub write_c {
-    my ( undef, %args ) = @_;
-    verify_args( \%write_h_PARAMS, %args ) or confess $@;
-    my $file = $args{file};
-    confess("Not a Clownfish::File")
-        unless a_isa_b( $file, "Clownfish::File" );
-    my $c_path = $file->c_path( $args{dest} );
-
-    # Unlink then open file.
-    my ( undef, $out_dir, undef ) = splitpath($c_path);
-    mkpath $out_dir unless -d $out_dir;
-    confess("Can't make dir '$out_dir'") unless -d $out_dir;
-    unlink $c_path;
-    sysopen( my $fh, $c_path, O_CREAT | O_EXCL | O_WRONLY )
-        or confess("Can't open '$c_path' for writing");
-
-    # Aggregate content.
-    my $content     = "";
-    my $c_file_syms = "";
-    for my $block ( @{ $file->blocks } ) {
-        if ( blessed($block) ) {
-            if ( $block->isa('Clownfish::Class') ) {
-                my $bound
-                    = Clownfish::Binding::Core::Class->new( client => $block,
-                    );
-                $content .= $bound->to_c . "\n";
-                my $c_file_sym = "C_" . uc( $block->full_struct_sym );
-                $c_file_syms .= "#define $c_file_sym\n";
-            }
-        }
-    }
-
-    print $fh <<END_STUFF;
-$args{header}
-
-$c_file_syms
-#define C_LUCY_VTABLE
-#define C_LUCY_ZOMBIECHARBUF
-#include "parcel.h"
-#include "Lucy/Object/VTable.h"
-#include "Lucy/Object/CharBuf.h"
-#include "Lucy/Object/Err.h"
-#include "Lucy/Object/Hash.h"
-#include "Lucy/Object/Host.h"
-#include "Lucy/Object/VArray.h"
-
-$content
-
-$args{footer}
-
-END_STUFF
-}
-
 1;
 
 __END__
@@ -200,15 +147,4 @@ typically copyright information.
 
 =back 
 
-=head2 write_h
-
-    Clownfish::Binding::Core::File->write_c(
-        file   => $file,                            # required
-        dest   => '/path/to/autogen_dir',           # required
-        header => "/* Autogenerated file. */\n",    # required
-        footer => $copyfoot,                        # required
-    );
-
-Generate a C file containing code needed by the class implementations.
-
 =cut