Ticket #918: class_init.patch

File class_init.patch, 1.9 KB (added by NotFound, 5 years ago)
  • lib/Parrot/Pmc2c/PMCEmitter.pm

     
    9696    $c->emit( $self->get_vtable_func ); 
    9797    $c->emit( $self->get_mro_func ); 
    9898    $c->emit( $self->get_isa_func ); 
     99    $c->emit( $self->pmc_class_init_func ); 
    99100    $c->emit( $self->init_func ); 
    100101    $c->emit( $self->postamble ); 
    101102 
     
    479480    return $cache->{$name} = "mfl_$count"; 
    480481} 
    481482 
     483=item C<pmc_class_init_func()> 
     484 
     485Returns the C code for the PMC's class_init function as a static 
     486function to be called from the exported class_init. 
     487 
     488=cut 
     489 
     490sub pmc_class_init_func { 
     491    my ($self) = @_; 
     492    my $class_init_code = ""; 
     493 
     494    if ($self->has_method('class_init')) { 
     495        $class_init_code .= $self->get_method('class_init')->body; 
     496 
     497        $class_init_code =~ s/INTERP/interp/g; 
     498 
     499        # fix indenting 
     500        $class_init_code =~ s/^/    /mg; 
     501        $class_init_code = <<ENDOFCODE 
     502static void thispmc_class_init(PARROT_INTERP, int entry) 
     503{ 
     504$class_init_code 
     505} 
     506ENDOFCODE 
     507    } 
     508    return $class_init_code; 
     509} 
     510 
    482511=item C<init_func()> 
    483512 
    484513Returns the C code for the PMC's initialization method, or an empty 
     
    533562    my $class_init_code = ""; 
    534563 
    535564    if ($self->has_method('class_init')) { 
    536         $class_init_code    = $self->get_method('class_init')->body; 
    537  
    538         $class_init_code =~ s/INTERP/interp/g; 
    539  
    540         # fix indenting 
    541         $class_init_code =~ s/^/        /mg; 
     565        $class_init_code .= "        thispmc_class_init(interp, entry);\n"; 
    542566    } 
    543567 
    544568    my %extra_vt; 
     
    715739    # include any class specific init code from the .pmc file 
    716740    if ($class_init_code) { 
    717741        $cout .= <<"EOC"; 
     742 
    718743        /* class_init */ 
    719         { 
    720744$class_init_code 
    721         } 
     745 
    722746EOC 
    723747    } 
    724748