Skip to content

Instantly share code, notes, and snippets.

@berekuk
Created June 26, 2010 15:52
Show Gist options
  • Save berekuk/454147 to your computer and use it in GitHub Desktop.
Save berekuk/454147 to your computer and use it in GitHub Desktop.
elsif $upto_arity == 2 && $past[0].returns eq 'WhateverCode' && $past[1].returns eq 'WhateverCode' {
pir::say("# wc(" ~ $past[0].arity ~ ") + wc(" ~ $past[1].arity ~ ")");
my $left := $past[0].shift;
my $left_arity := $left.arity;
my $right := $past[1].shift;
my $right_arity := $right.arity;
my $total_arity := $left_arity + $right_arity;
pir::say("# left_arity: " ~ $left_arity ~ ", right_arity: " ~ $right_arity);
pir::say("# total_arity: " ~ $total_arity);
my $counter := 0;
my $call_left := PAST::Op.new( :pasttype('call'), :node($/), $left);
my $call_right := PAST::Op.new( :pasttype('call'), :node($/), $right);
my $sig := Perl6::Compiler::Signature.new();
while $counter < $left_arity {
$counter := $counter + 1;
pir::say("# (left) counter: " ~ $counter);
$call_left.push(PAST::Var.new( :name('$x' ~ $counter), :scope('lexical') ));
$sig.add_parameter(Perl6::Compiler::Parameter.new(:var_name('$x' ~ $counter)));
}
while $counter < $total_arity {
$counter := $counter + 1;
pir::say("# (right) counter: " ~ $counter);
$call_right.push(PAST::Var.new( :name('$x' ~ $counter), :scope('lexical') ));
$sig.add_parameter(Perl6::Compiler::Parameter.new(:var_name('$x' ~ $counter)));
}
$past.push($call_left);
$past.push($call_right);
$past := make_block_from($sig, $past, 'WhateverCode');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment