Skip to content

Commit

Permalink
[past]: Add .closure() flag to PAST::Block to return closures with
Browse files Browse the repository at this point in the history
captured outer context.

git-svn-id: https://svn.parrot.org/parrot/trunk@46600 d31e2699-5ff4-0310-a27c-f18f2fbe73fe
  • Loading branch information
pmichaud committed May 14, 2010
1 parent 1bec943 commit f13bead
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
9 changes: 9 additions & 0 deletions compilers/pct/src/PAST/Compiler.pir
Expand Up @@ -997,9 +997,18 @@ Return the POST representation of a C<PAST::Block>.
bpost = $P0.'new'( bpost, 'node'=>node, 'result'=>blockreg)
bpost.'push_pirop'( blockref, 'result'=>blockreg )
unless islexical goto block_done
$I0 = node.'closure'()
if $I0 goto block_closure
bpost.'push_pirop'('capture_lex', blockreg)
goto block_done
block_closure:
## return a reference to a clone of the block with captured outer context
result = self.'uniquereg'('P')
bpost.'push_pirop'('newclosure', result, blockreg)
bpost.'result'(result)
goto block_done
block_immediate:
.local pmc arglist
arglist = options['arglist']
Expand Down
15 changes: 15 additions & 0 deletions compilers/pct/src/PAST/Node.pir
Expand Up @@ -498,6 +498,21 @@ blocks in Perl6 C<if>, C<while>, and other similar statements).
.end


=item closure([value])

Get/set the closure flag for the block to C<value>. If set,
any block reference returned by the node is to a clone of the
block that has captured the current lexical context.

=cut

.sub 'closure' :method
.param pmc value :optional
.param int has_value :opt_flag
.tailcall self.'attr'('closure', value, has_value)
.end


=item control([value])

Get/set the control exception handler for this block to C<value>.
Expand Down
15 changes: 11 additions & 4 deletions docs/pdds/pdd26_ast.pod
Expand Up @@ -481,13 +481,20 @@ the C<symbol> method below.
=item blocktype([type])

Get/set the type of the block to C<type>. The currently
understood values are 'declaration' and 'immediate'. 'Declaration'
indicates that a block is simply being defined at this point, the
result of the node is a reference to the block. A C<blocktype>
of 'immediate' indicates a block that is to be immediately
understood values are 'declaration', 'immediate', and 'method'.
'Declaration' indicates that a block is simply being defined at
this point, the result of the node is a reference to the block.
A C<blocktype> of 'immediate' indicates a block that is to be immediately
executed when it is evaluated in the AST, and the result of the
last operation is used as the return value for the block.

=item closure([value])

Get/set the closure flag for the block to C<value>. If the closure
flag on a (non-immediate) block is true, then the node returns a
reference to a clone of the block that has captured the current
lexical context.

=item namespace([value])

Get/set the namespace for this particular block (and any nested
Expand Down

0 comments on commit f13bead

Please sign in to comment.