Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Update lexical fixup handling for bs; earlier I just commented it out…
… out. This gets us passing all 00-parrot and all of 01-sanity apart from the final test which requires Test.pm, which we can't quite build yet.
  • Loading branch information
jnthn committed Feb 28, 2012
1 parent 038e84c commit 662c70a
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 25 deletions.
21 changes: 18 additions & 3 deletions src/Perl6/Actions.pm
Expand Up @@ -1265,9 +1265,24 @@ class Perl6::Actions is HLL::Actions {
add_signature_binding_code($block, $sig, @params);
$block.blocktype('declaration');

# Need to ensure we get lexical outers fixed up properly.
# XXX disabled for now - needs redoing due to bs work.
#$block.push($*W.create_lexical_capture_fixup());
# Need to ensure we get lexical outers fixed up properly. To
# do this we make a list of closures, which each point to the
# outer context. These surive serialization and thus point at
# what has to be fixed up.
my $throwaway_block_past := PAST::Block.new(
:blocktype('declaration'),
PAST::Var.new( :name('$_'), :scope('lexical'), :isdecl(1) )
);
$throwaway_block_past<outer> := $block;
$block[0].push($throwaway_block_past);
my $throwaway_block := $*W.create_code_object($throwaway_block_past,
'Block', $*W.create_signature([]));
my $fixup := $*W.create_lexical_capture_fixup();
$fixup.push(PAST::Op.new(
:pasttype('callmethod'), :name('clone'),
$*W.get_ref($throwaway_block)
));
$block.push($fixup);

# As its last act, it should grab the current lexpad so that
# we have the type environment, and also return the parametric
Expand Down
33 changes: 15 additions & 18 deletions src/Perl6/World.pm
Expand Up @@ -1107,33 +1107,30 @@ class Perl6::World is HLL::World {
}

# Some things get cloned many times with a lexical scope that
# we never entered. This makes sure we capture them as needed.
# Yes, it's evil...find a vodka before reading, kthx.
# we never enter. This makes sure we capture them as needed.
method create_lexical_capture_fixup() {
# Create an RPA and put it in the SC. Also code to build
# one and install it.
my $fixup_list := pir::new__Ps('ResizablePMCArray');
my $slot := self.add_code($fixup_list);
if self.is_precompilation_mode() {
self.add_event(:deserialize_past(
self.set_slot_past($slot, PAST::Op.new( :pasttype('list') ))));
}
# Create a list and put it in the SC.
my class FixupList { has $!list }
my $fixup_list := nqp::create(FixupList);
my $slot := self.add_object($fixup_list);
nqp::bindattr($fixup_list, FixupList, '$!list', nqp::list());

# Set up capturing code.
my $capturer := self.cur_lexpad();
$capturer[0].push(PAST::Op.new(
:pirop('capture_all_outers vP'),
self.get_slot_past_for_object($fixup_list)));
PAST::Var.new(
:name('$!list'), :scope('attribute_6model'),
self.get_ref($fixup_list),
self.get_ref(FixupList) )));

# Return code that adds current context to re-capture
# list.
# Return a PAST node that we can push the dummy closure
return PAST::Op.new(
:pirop('push vPP'),
self.get_slot_past_for_object($fixup_list),
PAST::Op.new(
:pirop('set PQPS'),
PAST::Op.new( :pirop('getinterp P') ),
'context'));
PAST::Var.new(
:name('$!list'), :scope('attribute_6model'),
self.get_ref($fixup_list),
self.get_ref(FixupList) ));
}

# Handles addition of a phaser.
Expand Down
10 changes: 6 additions & 4 deletions src/ops/perl6.ops
Expand Up @@ -1359,8 +1359,8 @@ inline op perl6_callerid(out INT) :base_core {

=item capture_all_outers(in PMC)

Takes all the specified contexts and sets their outer pointers
to be this one.
Takes a list of Code objects that map to closures, finds those closures outers
can captures those contexts.

=cut

Expand All @@ -1370,8 +1370,10 @@ inline op capture_all_outers(in PMC) :base_core {
INTVAL elems = VTABLE_elements(interp, $1);
INTVAL i;
for (i = 0; i < elems; i++) {
PMC *inner = VTABLE_get_pmc_keyed_int(interp, $1, i);
Parrot_pcc_set_outer_ctx_func(interp, inner, cur_ctx);
PMC *code_obj = VTABLE_get_pmc_keyed_int(interp, $1, i);
PMC *closure = ((Rakudo_Code *)PMC_data(code_obj))->_do;
PMC *ctx_to_diddle = PARROT_SUB(closure)->outer_ctx;
Parrot_pcc_set_outer_ctx_func(interp, ctx_to_diddle, cur_ctx);
}
}

Expand Down

0 comments on commit 662c70a

Please sign in to comment.