Author: tewk
Date: Wed Jun 13 09:34:39 2007
New Revision: 18974

Modified:
   branches/pmc2c/lib/Parrot/Pmc2c/ComposedMethod.pm
   branches/pmc2c/lib/Parrot/Pmc2c/Emitter.pm
   branches/pmc2c/lib/Parrot/Pmc2c/Library.pm
   branches/pmc2c/lib/Parrot/Pmc2c/PMC/Null.pm
   branches/pmc2c/lib/Parrot/Pmc2c/PMC/default.pm
   branches/pmc2c/lib/Parrot/Pmc2c/PMC/delegate.pm
   branches/pmc2c/lib/Parrot/Pmc2c/PMCEmitter.pm
   branches/pmc2c/lib/Parrot/Pmc2c/Pmc2cMain.pm
   branches/pmc2c/tools/build/pmc2c.pl

Log:
[Pmc2c Branch] cleanups


Modified: branches/pmc2c/lib/Parrot/Pmc2c/ComposedMethod.pm
==============================================================================
--- branches/pmc2c/lib/Parrot/Pmc2c/ComposedMethod.pm   (original)
+++ branches/pmc2c/lib/Parrot/Pmc2c/ComposedMethod.pm   Wed Jun 13 09:34:39 2007
@@ -5,7 +5,6 @@
 use warnings;
 use base qw( Parrot::Pmc2c::Method Exporter );
 use Data::Dumper;
-use Parrot::Pmc2c::UtilFunctions qw(count_newlines );
 
 sub new {
     my ( $class, $self_hash ) = @_;
@@ -24,11 +23,9 @@
 }
 
 sub generate_headers {
-    my ( $self, $pmc ) = @_;
     return "";
 }
 
-
 1;
 
 # Local Variables:

Modified: branches/pmc2c/lib/Parrot/Pmc2c/Emitter.pm
==============================================================================
--- branches/pmc2c/lib/Parrot/Pmc2c/Emitter.pm  (original)
+++ branches/pmc2c/lib/Parrot/Pmc2c/Emitter.pm  Wed Jun 13 09:34:39 2007
@@ -66,11 +66,13 @@
 sub replace {
     my ( $self, $regex, $replacement ) = @_;
     my $m = $self->{data} =~ /((.*)\Q$regex\E)(.*)/s;
-    $self->emit($2, $self->filename, $self->{bline});
+    my ( $all, $pre, $post ) = ( $1, $2, $3 );
+    $self->emit($pre, $self->filename, $self->{bline});
     $self->add_fragment($replacement);
-    $self->emit($3, $self->filename, $self->{bline} + count_newlines($1));
-    for my $x qw( data filename bline eline) {
-        delete $self->{data};
+    $self->emit($post, $self->filename, $self->{bline} + count_newlines($all));
+
+    for my $x qw( data bline eline ) {
+        delete $self->{$x};
     }
     return 1;
 }

Modified: branches/pmc2c/lib/Parrot/Pmc2c/Library.pm
==============================================================================
--- branches/pmc2c/lib/Parrot/Pmc2c/Library.pm  (original)
+++ branches/pmc2c/lib/Parrot/Pmc2c/Library.pm  Wed Jun 13 09:34:39 2007
@@ -12,8 +12,7 @@
 =head1 DESCRIPTION
 
 Parrot::Pmc2c::Library is a wrapper around a collection of PMCs linked in the
-same dynamic library. A degenerate case is having an unnamed library with just
-one PMC, which is the case used by the Parrot core. See L<Parrot::Pmc2c>
+same dynamic library.
 
 =head2 Instance Methods
 
@@ -29,68 +28,19 @@
 use Parrot::Pmc2c::PMCEmitter;
 use Parrot::Pmc2c::UtilFunctions qw(dont_edit dynext_load_code c_code_coda 
spew);
 
-=item C<new($opt, $vtable_dump, %pmcs)>
+=item C<generate_library($library_name, $pmcs)>
 
-    $library = Parrot::Pmc2c::Library->new
-        ( $options,     # hash refernce, the same passed to other constructors
-          $vtable_dump, # vtable.dump
-          pmc1        => $pmc1_dump,
-          pmc2        => $pmc2_dump,
-          ... );
-
-Creates a new library object. If the C<$options> hash contains a
-C<library> key its value will be used for the library name.
+    Parrot::Pmc2c::Library->generate_library( $library_name, $pmcs );
 
 =cut
 
-sub new {
-    my ( $class, $opt, $vtable_dump, %pmcs ) = @_;
-    my %emitters;
-
-    foreach my $pmc ( values %pmcs ) {
-        $emitters{$pmc->filename} = Parrot::Pmc2c::PMC->prep_for_emit($pmc, 
$vtable_dump);
-    }
-
-    return bless {
-        opt  => $opt,
-        pmcs => \%pmcs,
-        emitters=> \%emitters,
-    }, $class;
-}
-
-sub generate_library($$) {
-    my ( $self, $library_name ) = @_;
-    my $h_name  = "$library_name.h";
-    my $c_name  = "$library_name.c";
+sub generate_library {
+    my ( $class, $library_name, $pmcs ) = @_;
 
-    my $cout = $self->gen_c;
-    spew($c_name, $cout);
-
-    my $hout = $self->gen_h;
-    spew($h_name, $hout);
+    spew("$library_name.c", gen_c($library_name, $pmcs));
+    spew("$library_name.h", gen_h($library_name));
 }
 
-=item C<write_all_files()>
-
-Writes C and header files for all the PMCs in the library,
-I<or> E<lt>libnameE<gt>.c and pmc_E<lt>libnameE<gt>.h if his object
-represents a named library.
-
-=cut
-
-sub write_all_files {
-    my $self    = shift;
-    my $library_name = $self->{opt}{library};
-
-    if ($library_name) {
-        generate_library($self, $library_name);
-    }
-    else {
-        for my $emitter ( values %{ $self->{emitters} } ) {
-            $emitter->generate;
-        }
-    }
-}
 
 =item C<gen_h>
 
@@ -99,26 +49,25 @@
 =cut
 
 sub gen_h {
-    my ($self)     = @_;
-    my $hout       = dont_edit('various files');
-    my $lc_libname = lc $self->{opt}{library};
+    my $lc_library_name = lc shift;
 
+    my $hout = dont_edit('various files');
     $hout .= <<"EOH";
-Parrot_PMC Parrot_lib_${lc_libname}_load(Parrot_Interp interp);
+Parrot_PMC Parrot_lib_${lc_library_name}_load(Parrot_Interp interp);
 EOH
-    $hout .= $self->c_code_coda;
+    $hout .= c_code_coda;
 
     return $hout;
 }
 
 =item C<gen_c>
 
-Writes the C file for the library.
+rites the C file for the library.
 
 =cut
 
 sub gen_c {
-    my ($self) = @_;
+    my ( $library_name, $pmcs ) = @_;
     my $cout = dont_edit('various files');
 
     $cout .= <<"EOC";
@@ -127,17 +76,17 @@
 #include "parrot/extend.h"
 #include "parrot/dynext.h"
 EOC
+    my %pmcs = ( map { $_->{name} => $_ } @{ $pmcs } );
     
-    foreach my $pmc ( values %{ $self->{pmcs} } ) {
-        my $name = lc $pmc->{name};
+    foreach my $name ( keys %pmcs ) {
+        my $lcname = lc $name;
         $cout .= <<"EOC";
-#include "pmc_$name.h"
+#include "pmc_$lcname.h"
 EOC
     }
     $cout .= "\n";
-    $cout .= dynext_load_code( $self->{opt}{library},
-        map { $_->{name} => $_ } values %{ $self->{pmcs} } );
-    $cout .= $self->c_code_coda;
+    $cout .= dynext_load_code( $library_name, %pmcs );
+    $cout .= c_code_coda;
 
     return $cout;
 }

Modified: branches/pmc2c/lib/Parrot/Pmc2c/PMC/Null.pm
==============================================================================
--- branches/pmc2c/lib/Parrot/Pmc2c/PMC/Null.pm (original)
+++ branches/pmc2c/lib/Parrot/Pmc2c/PMC/Null.pm Wed Jun 13 09:34:39 2007
@@ -11,11 +11,9 @@
 use warnings;
 use Parrot::Pmc2c::UtilFunctions qw( gen_ret );
 
-=item C<body($method, $line, $out_name)>
+=item C<pre_method_gen($method, $line, $out_name)>
 
-Returns the C code for the method body. C<$line> is used to accumulate
-the number of lines, C<$out_name> is the name of the output file we are
-generating.
+Auto generates methods for the NULL PMC. 
 
 The C<Null> PMC throws an execption for all methods.
 
@@ -35,8 +33,7 @@
                 type        => Parrot::Pmc2c::Method::VTABLE,
           });
 
-        my $ret = "";
-        $ret = gen_ret($method);
+        my $ret = gen_ret($method);
         my $output = <<EOC;
     real_exception(interp, NULL, NULL_REG_ACCESS, "Null PMC access in 
$vt_method_name()");
 EOC

Modified: branches/pmc2c/lib/Parrot/Pmc2c/PMC/default.pm
==============================================================================
--- branches/pmc2c/lib/Parrot/Pmc2c/PMC/default.pm      (original)
+++ branches/pmc2c/lib/Parrot/Pmc2c/PMC/default.pm      Wed Jun 13 09:34:39 2007
@@ -30,8 +30,7 @@
                 type        => Parrot::Pmc2c::Method::VTABLE,
           });
 
-        my $ret = "";
-        $ret = gen_ret($method);
+        my $ret = gen_ret($method);
         $new_default_method->body(Parrot::Pmc2c::Emitter->text(<<"EOC"));
     cant_do_method(interp, pmc, "$vt_method_name");
     $ret

Modified: branches/pmc2c/lib/Parrot/Pmc2c/PMC/delegate.pm
==============================================================================
--- branches/pmc2c/lib/Parrot/Pmc2c/PMC/delegate.pm     (original)
+++ branches/pmc2c/lib/Parrot/Pmc2c/PMC/delegate.pm     Wed Jun 13 09:34:39 2007
@@ -30,8 +30,6 @@
                 type        => Parrot::Pmc2c::Method::VTABLE,
           });
         my ( $func_ret, $ret_suffix, $args, $sig ) = $self->signature($method);
-        my $super_args = $args;
-        $super_args =~ s/^,//;
 
         $new_default_method->body(Parrot::Pmc2c::Emitter->text(<<"EOC"));
 
@@ -46,18 +44,6 @@
     return 1;
 }
 
-
-=item C<implements($method)>
-
-True for vtables.
-
-=cut
-
-sub implements {
-    my ( $self, $meth ) = @_;
-    $self->implements_vtable($meth);
-}
-
 =item C<trans($type)>
 
 Used in C<signature()> to normalize argument types.

Modified: branches/pmc2c/lib/Parrot/Pmc2c/PMCEmitter.pm
==============================================================================
--- branches/pmc2c/lib/Parrot/Pmc2c/PMCEmitter.pm       (original)
+++ branches/pmc2c/lib/Parrot/Pmc2c/PMCEmitter.pm       Wed Jun 13 09:34:39 2007
@@ -668,20 +668,6 @@
     $cout;
 }
 
-=item C<implements($method)>
-
-True if this class generates code for the method C<$method>.
-
-=cut
-
-=item C<implements_vtable($method)>
-
-True if this class generates code for VTABLE method C<$method>.
-
-=back
-
-=cut
-
 sub is_vtable_method {
     my ( $self, $vt_method_name ) = @_;
     return 1 if $self->vtable->has_method($vt_method_name);

Modified: branches/pmc2c/lib/Parrot/Pmc2c/Pmc2cMain.pm
==============================================================================
--- branches/pmc2c/lib/Parrot/Pmc2c/Pmc2cMain.pm        (original)
+++ branches/pmc2c/lib/Parrot/Pmc2c/Pmc2cMain.pm        Wed Jun 13 09:34:39 2007
@@ -273,13 +273,19 @@
 
 sub gen_c {
     my $self        = shift;
-    my @files       = @{ $self->{args} };
-    my $optsref     = $self->{opt};
-    my %pmcs        = map { $_, $self->read_dump($_) } @files;
     my $vtable_dump = $self->read_dump("vtable.pmc");
 
-    Parrot::Pmc2c::Library->new( $optsref, $vtable_dump, %pmcs 
)->write_all_files;
+    foreach my $filename ( @{ $self->{args} } ) {
+        Parrot::Pmc2c::PMC->prep_for_emit($self->read_dump($filename), 
$vtable_dump)->generate;
+    }
+    return 1;
+}
+
+sub gen_library {
+    my ( $self, $library_name ) = @_;
+    my $pmcs = [ map { $self->read_dump($_) } @{ $self->{args} } ];
 
+    Parrot::Pmc2c::Library->generate_library( $library_name, $pmcs );
     return 1;
 }
 

Modified: branches/pmc2c/tools/build/pmc2c.pl
==============================================================================
--- branches/pmc2c/tools/build/pmc2c.pl (original)
+++ branches/pmc2c/tools/build/pmc2c.pl Wed Jun 13 09:34:39 2007
@@ -55,6 +55,11 @@
     exit;
 }
 
+if ( $options{library} ) {
+    $self->gen_library($options{library});
+    exit;
+}
+
 if ( $action{gen_c} ) {
     $self->gen_c();
     exit;

Reply via email to