Skip to content
This repository has been archived by the owner on Feb 3, 2021. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Closures now properly capture outer context. Also clean up
handling of bare blocks a bit, and bump PARROT_REVISION.
  • Loading branch information
pmichaud committed May 14, 2010
1 parent c3b0e83 commit f427d29
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
2 changes: 1 addition & 1 deletion build/PARROT_REVISION
@@ -1 +1 @@
46564
46600
13 changes: 7 additions & 6 deletions src/NQP/Actions.pm
Expand Up @@ -60,9 +60,7 @@ method statementlist($/) {
for $<statement> {
my $ast := $_.ast;
$ast := $ast<sink> if pir::defined($ast<sink>);
if $ast.isa(PAST::Block) && !$ast.blocktype {
$ast := block_immediate($ast);
}
if $ast<bareblock> { $ast := block_immediate($ast); }
$past.push( $ast );
}
}
Expand Down Expand Up @@ -104,6 +102,7 @@ method blockoid($/) {
my $BLOCK := @BLOCK.shift;
$BLOCK.push($past);
$BLOCK.node($/);
$BLOCK.closure(1);
make $BLOCK;
}

Expand Down Expand Up @@ -652,9 +651,11 @@ method circumfix:sym<ang>($/) { make $<quote_EXPR>.ast; }
method circumfix:sym<« »>($/) { make $<quote_EXPR>.ast; }

method circumfix:sym<{ }>($/) {
make +$<pblock><blockoid><statementlist><statement> > 0
?? $<pblock>.ast
!! vivitype('%');
my $past := +$<pblock><blockoid><statementlist><statement> > 0
?? $<pblock>.ast
!! vivitype('%');
$past<bareblock> := 1;
make $past;
}

method circumfix:sym<sigil>($/) {
Expand Down
14 changes: 14 additions & 0 deletions t/nqp/48-closure.t
@@ -0,0 +1,14 @@
#! nqp

plan(2);

sub A($a) {
return { $a * 2 };
}

my $x := A(3);
my $y := A(5);

ok( $y() == 10, "second closure correct" );
ok( $x() == 6, "first closure correct" );

0 comments on commit f427d29

Please sign in to comment.