Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Stubs need a fresh LexInfo for closure serialization to work. Gets us…
… a little further with role serialization.
  • Loading branch information
jnthn committed Feb 20, 2012
1 parent 790fc9a commit 69ccfc7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/NQP/World.pm
Expand Up @@ -182,7 +182,7 @@ class NQP::World is HLL::World {
$dummy := $past<compile_time_dummy>;
}
else {
$dummy := pir::clone__PP($stub_code);
$dummy := pir::nqp_fresh_stub__PP($stub_code);
pir::assign__vPS($dummy, $name);
if $is_dispatcher {
# The dispatcher will get cloned if more candidates are added in
Expand Down
24 changes: 24 additions & 0 deletions src/ops/nqp.ops
Expand Up @@ -11,6 +11,7 @@ BEGIN_OPS_PREAMBLE
#include "../6model/serialization_context.h"
#include "../guts/multi_dispatch.h"
#include "../pmc/pmc_dispatchersub.h"
#include "../pmc/pmc_nqplexinfo.h"
#include "pmc_sub.h"

/* SHA1 algorithm. */
Expand Down Expand Up @@ -2177,3 +2178,26 @@ inline op nqp_sha1(out STR, in STR) :base_core {
Parrot_str_free_cstring(cstr);
$1 = Parrot_str_new_init(interp, &output, 40, Parrot_utf8_encoding_ptr, 0);
}


/*

=item nqp_fresh_stub

Takes the Parrot Sub in $2 and makes a clone of it along with a fresh NQPLexInfo.
(This is used for closure to static resolution).

=cut

*/
inline op nqp_fresh_stub(out PMC, in PMC) :base_core {
if ($2->vtable->base_type == enum_class_Sub) {
$1 = VTABLE_clone(interp, $2);
PARROT_SUB($1)->lex_info = VTABLE_clone(interp, PARROT_SUB($2)->lex_info);
PARROT_NQPLEXINFO(PARROT_SUB($1)->lex_info)->static_code = $1;
}
else {
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
"nqp_fresh_sub can only operate on a Parrot Sub");
}
}

0 comments on commit 69ccfc7

Please sign in to comment.