Skip to content

Commit

Permalink
The whatever currying was a little too liberal; after some labour I c…
Browse files Browse the repository at this point in the history
…ame up with this patch to make it a tad more conservative.
  • Loading branch information
jnthn committed May 29, 2010
1 parent ac1571f commit d42fd31
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/Perl6/Actions.pm
Expand Up @@ -2065,7 +2065,7 @@ method EXPR($/, $key?) {
for $/.list { if $_.ast { $past.push($_.ast); } }
}
if $key eq 'PREFIX' || $key eq 'INFIX' || $key eq 'POSTFIX' {
$past := whatever_curry($past);
$past := whatever_curry($past, $key eq 'INFIX' ?? 2 !! 1);
}
make $past;
}
Expand Down Expand Up @@ -3035,10 +3035,10 @@ INIT {
%not_curried{'&infix:<..>'} := 1;
%not_curried{'&infix:<~~>'} := 1;
}
sub whatever_curry($past) {
sub whatever_curry($past, $upto_arity) {
if $past.isa(PAST::Op) && !%not_curried{$past.name} {
if +@($past) == 2 && $past[0] ~~ PAST::Op && $past[0].returns eq 'Whatever'
&& $past[1] ~~ PAST::Op && $past[1].returns eq 'Whatever' {
if $upto_arity == 2 && $past[0] ~~ PAST::Op && $past[0].returns eq 'Whatever'
&& $past[1] ~~ PAST::Op && $past[1].returns eq 'Whatever' {
# Curry left and right, two args.
$past.shift; $past.shift;
$past.push(PAST::Var.new( :name('$x'), :scope('lexical') ));
Expand All @@ -3048,15 +3048,15 @@ sub whatever_curry($past) {
Perl6::Compiler::Parameter.new(:var_name('$y')));
$past := make_block_from($sig, $past);
}
elsif +@($past) == 2 && $past[1] ~~ PAST::Op && $past[1].returns eq 'Whatever' {
elsif $upto_arity == 2 && $past[1] ~~ PAST::Op && $past[1].returns eq 'Whatever' {
# Curry right arg.
$past.pop;
$past.push(PAST::Var.new( :name('$y'), :scope('lexical') ));
my $sig := Perl6::Compiler::Signature.new(
Perl6::Compiler::Parameter.new(:var_name('$y')));
$past := make_block_from($sig, $past);
}
elsif (+@($past) == 1 || +@($past) == 2) && $past[0] ~~ PAST::Op && $past[0].returns eq 'Whatever' {
elsif $upto_arity >= 1 && $past[0] ~~ PAST::Op && $past[0].returns eq 'Whatever' {
# Curry left (or for unary, only) arg.
$past.shift;
$past.unshift(PAST::Var.new( :name('$x'), :scope('lexical') ));
Expand Down

0 comments on commit d42fd31

Please sign in to comment.