Permalink
Browse files

Implement invoke for CODE refs

  • Loading branch information...
1 parent c774d3a commit 130d1f19acc89d1b60ae4481fc5538fd8f31df7c @sorear sorear committed Mar 27, 2010
Showing with 43 additions and 1 deletion.
  1. +10 −0 nt/callsv.t
  2. +1 −1 src/pmc/p5invocation.pmc
  3. +32 −0 src/pmc/p5scalar.pmc
View
@@ -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");
View
@@ -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);
}
View
@@ -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.

0 comments on commit 130d1f1

Please sign in to comment.