Skip to content

Commit

Permalink
[QAST::Operations] factored out common loop body
Browse files Browse the repository at this point in the history
Simple "extract subroutine" for ya. But it's only gonna get
worse, once we do slurpies, too.
  • Loading branch information
Carl Masak committed May 26, 2012
1 parent d124e96 commit cd60db0
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions src/QAST/Operations.nqp
Expand Up @@ -331,6 +331,16 @@ QAST::Operations.add_core_op('bind', -> $qastcomp, $op {
});

# Calling.
sub handle_arg($arg, $qastcomp, $ops, @arg_results) {
my $arg_post := $qastcomp.as_post($arg);
$ops.push($arg_post);
my $result := $arg_post.result;
if $arg.named -> $name {
$result := $result ~ " :named(" ~ $qastcomp.escape($name) ~ ")";
}
@arg_results.push($result);
}

QAST::Operations.add_core_op('call', -> $qastcomp, $op {
# Work out what callee is.
my $callee;
Expand All @@ -349,13 +359,7 @@ QAST::Operations.add_core_op('call', -> $qastcomp, $op {
my $ops := $qastcomp.post_new('Ops');
my @arg_results;
for @args {
my $arg_post := $qastcomp.as_post($_);
$ops.push($arg_post);
my $result := $arg_post.result;
if $_.named -> $name {
$result := $result ~ " :named(" ~ $qastcomp.escape($name) ~ ")";
}
@arg_results.push($result);
handle_arg($_, $qastcomp, $ops, @arg_results);
}

# Figure out result register type and allocate a register for it.
Expand Down Expand Up @@ -395,13 +399,7 @@ QAST::Operations.add_core_op('callmethod', -> $qastcomp, $op {
my $ops := $qastcomp.post_new('Ops');
my @arg_results;
for @args {
my $arg_post := $qastcomp.as_post($_);
$ops.push($arg_post);
my $result := $arg_post.result;
if $_.named -> $name {
$result := $result ~ " :named(" ~ $qastcomp.escape($name) ~ ")";
}
@arg_results.push($result);
handle_arg($_, $qastcomp, $ops, @arg_results);
}

# Figure out result register type and allocate a register for it.
Expand Down

0 comments on commit cd60db0

Please sign in to comment.