Skip to content

Commit

Permalink
Implement invoke for CODE refs
Browse files Browse the repository at this point in the history
  • Loading branch information
sorear committed Mar 27, 2010
1 parent c774d3a commit 130d1f1
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
10 changes: 10 additions & 0 deletions nt/callsv.t
@@ -0,0 +1,10 @@
# vim: ft=perl6

plan(1);

my $p5code := 'sub { my $x = shift; return $x ** $x }';

pir::load_bytecode("perl5.pir");
my $p5fun := pir::compreg__ps("perl5").make_interp($p5code)();

ok($p5fun(4) == 256, "can call through p5 subs");
2 changes: 1 addition & 1 deletion src/pmc/p5invocation.pmc
Expand Up @@ -117,7 +117,7 @@ Handles the actual invocation.
SvREFCNT_dec(namesv);
mem_sys_free(c_name);

Parrot_pcc_build_call_from_c_args(interp, call_object, "Ps", results);
Parrot_pcc_build_call_from_c_args(interp, call_object, "Pf", results);

return blizkost_return_from_invoke(interp, next);
}
Expand Down
32 changes: 32 additions & 0 deletions src/pmc/p5scalar.pmc
Expand Up @@ -138,6 +138,38 @@ the given name on the given Perl 5 Scalar invocant.

/*

=item C<opcode_t *invoke(void *next)>

Attempts to invoke the target of a code reference.

=cut

*/
VTABLE opcode_t *invoke(void *next) {
PMC *p5i, *positional, *named, *results;
PerlInterpreter *my_perl;
SV *invref;

PMC *ctx = CURRENT_CONTEXT(interp);
PMC *call_object = Parrot_pcc_get_signature(interp, ctx);

GET_ATTR_p5i(interp, SELF, p5i);
GETATTR_P5Interpreter_my_perl(interp, p5i, my_perl);
GET_ATTR_sv(interp, SELF, invref);

Parrot_pcc_fill_params_from_c_args(interp, call_object, "PsPns",
&positional, &named);

blizkost_call_in(interp, p5i, invref, G_ARRAY, positional, named,
&results);

Parrot_pcc_build_call_from_c_args(interp, call_object, "Pf", results);

return blizkost_return_from_invoke(interp, next);
}

/*

=item C<INTVAL can(STRING *name)>

Checks if a class can do a given method.
Expand Down

0 comments on commit 130d1f1

Please sign in to comment.