Skip to content

Commit

Permalink
[pmc2c] compile-time expand pcc params and set the return result #1080
Browse files Browse the repository at this point in the history
optimize pmc2c to emit static fill_params from compile-time known
params into the _call_object args array, ditto for the return values.
  • Loading branch information
ZYROz authored and Reini Urban committed Jun 29, 2014
1 parent 9e15179 commit 497307e
Showing 1 changed file with 32 additions and 3 deletions.
35 changes: 32 additions & 3 deletions lib/Parrot/Pmc2c/PCCMETHOD.pm
Expand Up @@ -212,8 +212,24 @@ END
if ($returns_signature and !$method->is_vtable) {
$e->emit( <<"END" );
{ /*BEGIN RETURN $returns */
END
my $sigtype = {'P' => 'pmc',
'S' => 'string',
'I' => 'integer',
'N' => 'number'};
my $type = $$sigtype{$returns_signature};
if ($type) {
$e->emit( <<"END");
VTABLE_set_${type}_keyed_int(interp, _call_object, 0, $returns_varargs);
END
}
else {
$e->emit( <<"END");
Parrot_pcc_set_call_from_c_args(interp, _call_object,
"$returns_signature", $returns_varargs);
END
}
$e->emit( <<"END" );
$wb
return;
} /*END RETURN $returns */
Expand Down Expand Up @@ -377,10 +393,23 @@ END
$params_declarations
END
if ($params_signature) {
$e->emit( <<"END");
Parrot_pcc_fill_params_from_c_args(interp, _call_object, "$params_signature",
$params_varargs);
my $sigtype = {'P' => 'pmc',
'S' => 'string',
'I' => 'integer',
'N' => 'number'};
my $arg_index = 0;
my @sig_vals = split(//,$params_signature);
my @params_vararg_list = split(/, &/,(substr $params_varargs, 1));

foreach my $sig (@sig_vals) {
if ($$sigtype{$sig}) {
my $type = $$sigtype{$sig};
$e->emit( <<"END");
$params_vararg_list[$arg_index] = VTABLE_get_${type}_keyed_int(interp, _call_object, $arg_index);
END
$arg_index++;
}
}
}
$e->emit( <<'END' );
{ /* BEGIN PMETHOD BODY */
Expand Down

0 comments on commit 497307e

Please sign in to comment.