Skip to content

Commit

Permalink
Fix a tricky init ordering issue that meant we could not use where cl…
Browse files Browse the repository at this point in the history
…auses in parametric role signatures.
  • Loading branch information
jnthn committed Apr 23, 2010
1 parent 7a1409b commit 2405a0b
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions src/Perl6/Actions.pm
Expand Up @@ -2555,7 +2555,7 @@ class Perl6::RegexActions is Regex::P6Regex::Actions {
}
}

# Takes a block and adds a signature ot it, as well as code to bind the call
# Takes a block and adds a signature to it, as well as code to bind the call
# capture against the signature. Returns the name of the signature setup block.
sub add_signature($block, $sig_obj, $lazy) {
# Set arity.
Expand All @@ -2576,18 +2576,24 @@ sub add_signature($block, $sig_obj, $lazy) {
));

# If lazy, make and push signature setup block.
$block<signature_ast> := $sig_obj.ast(1);
if $lazy {
my $sig_setup_block :=
PAST::Block.new( :blocktype<declaration>, $sig_obj.ast(1) );
$block[0].push($sig_setup_block);
PAST::Val.new(:value($sig_setup_block));
make_lazy_sig_block($block)
}
else {
$block.loadinit.push($sig_obj.ast(1));
$block.loadinit.push($block<signature_ast>);
$block.loadinit.push(PAST::Op.new( :inline(' setprop block, "$!signature", signature') ));
}
}

# Makes a lazy signature building block.
sub make_lazy_sig_block($block) {
my $sig_setup_block :=
PAST::Block.new( :blocktype<declaration>, $block<signature_ast> );
$block[0].push($sig_setup_block);
PAST::Val.new(:value($sig_setup_block));
}

# Adds a placeholder parameter to this block's signature.
sub add_placeholder_parameter($sigil, $ident, :$named, :$slurpy_pos, :$slurpy_named) {
our @BLOCK;
Expand Down Expand Up @@ -2632,6 +2638,7 @@ sub create_code_object($block, $type, $multiness, $lazy_init) {
);
if $lazy_init { $past.push($lazy_init) }
$past<past_block> := $block;
$past<block_class> := $type;
$past
}

Expand Down Expand Up @@ -2924,8 +2931,9 @@ sub prevent_null_return($block) {
# one. Used by things doing where clause-ish things.
sub where_blockify($expr) {
my $past;
if $expr.isa(PAST::Block) {
$past := $expr;
if $expr<past_block> && $expr<block_class> eq 'Block' {
my $lazy_name := make_lazy_sig_block($expr<past_block>);
$past := create_code_object($expr<past_block>, 'Block', 0, $lazy_name);
}
else {
$past := PAST::Block.new( :blocktype('declaration'),
Expand Down

0 comments on commit 2405a0b

Please sign in to comment.