[svn:parrot] r43710 - trunk/lib/Parrot/Pmc2c

NotFound at svn.parrot.org NotFound at svn.parrot.org
Tue Feb 2 20:34:46 UTC 2010


Author: NotFound
Date: Tue Feb  2 20:34:46 2010
New Revision: 43710
URL: https://trac.parrot.org/parrot/changeset/43710

Log:
[pmc] generate a static function from custom class_init instead of inserting the code into the generated one, TT #918

Modified:
   trunk/lib/Parrot/Pmc2c/PMCEmitter.pm

Modified: trunk/lib/Parrot/Pmc2c/PMCEmitter.pm
==============================================================================
--- trunk/lib/Parrot/Pmc2c/PMCEmitter.pm	Tue Feb  2 20:19:19 2010	(r43709)
+++ trunk/lib/Parrot/Pmc2c/PMCEmitter.pm	Tue Feb  2 20:34:46 2010	(r43710)
@@ -97,6 +97,7 @@
     $c->emit( $self->get_vtable_func );
     $c->emit( $self->get_mro_func );
     $c->emit( $self->get_isa_func );
+    $c->emit( $self->pmc_class_init_func );
     $c->emit( $self->init_func );
     $c->emit( $self->postamble );
 
@@ -474,6 +475,34 @@
     return $cache->{$name} = "mfl_$count";
 }
 
+=item C<pmc_class_init_func()>
+
+Returns the C code for the PMC's class_init function as a static
+function to be called from the exported class_init.
+
+=cut
+
+sub pmc_class_init_func {
+    my ($self) = @_;
+    my $class_init_code = "";
+
+    if ($self->has_method('class_init')) {
+        $class_init_code .= $self->get_method('class_init')->body;
+
+        $class_init_code =~ s/INTERP/interp/g;
+
+        # fix indenting
+        $class_init_code =~ s/^/    /mg;
+        $class_init_code = <<ENDOFCODE
+static void thispmc_class_init(PARROT_INTERP, int entry)
+{
+$class_init_code
+}
+ENDOFCODE
+    }
+    return $class_init_code;
+}
+
 =item C<init_func()>
 
 Returns the C code for the PMC's initialization method, or an empty
@@ -528,12 +557,7 @@
     my $class_init_code = "";
 
     if ($self->has_method('class_init')) {
-        $class_init_code    = $self->get_method('class_init')->body;
-
-        $class_init_code =~ s/INTERP/interp/g;
-
-        # fix indenting
-        $class_init_code =~ s/^/        /mg;
+        $class_init_code .= "        thispmc_class_init(interp, entry);\n";
     }
 
     my %extra_vt;
@@ -703,10 +727,10 @@
     # include any class specific init code from the .pmc file
     if ($class_init_code) {
         $cout .= <<"EOC";
+
         /* class_init */
-        {
 $class_init_code
-        }
+
 EOC
     }
 


More information about the parrot-commits mailing list