Skip to content

Commit cd60db0

Browse files
author
Carl Masak
committed
[QAST::Operations] factored out common loop body
Simple "extract subroutine" for ya. But it's only gonna get worse, once we do slurpies, too.
1 parent d124e96 commit cd60db0

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

src/QAST/Operations.nqp

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,16 @@ QAST::Operations.add_core_op('bind', -> $qastcomp, $op {
331331
});
332332

333333
# Calling.
334+
sub handle_arg($arg, $qastcomp, $ops, @arg_results) {
335+
my $arg_post := $qastcomp.as_post($arg);
336+
$ops.push($arg_post);
337+
my $result := $arg_post.result;
338+
if $arg.named -> $name {
339+
$result := $result ~ " :named(" ~ $qastcomp.escape($name) ~ ")";
340+
}
341+
@arg_results.push($result);
342+
}
343+
334344
QAST::Operations.add_core_op('call', -> $qastcomp, $op {
335345
# Work out what callee is.
336346
my $callee;
@@ -349,13 +359,7 @@ QAST::Operations.add_core_op('call', -> $qastcomp, $op {
349359
my $ops := $qastcomp.post_new('Ops');
350360
my @arg_results;
351361
for @args {
352-
my $arg_post := $qastcomp.as_post($_);
353-
$ops.push($arg_post);
354-
my $result := $arg_post.result;
355-
if $_.named -> $name {
356-
$result := $result ~ " :named(" ~ $qastcomp.escape($name) ~ ")";
357-
}
358-
@arg_results.push($result);
362+
handle_arg($_, $qastcomp, $ops, @arg_results);
359363
}
360364

361365
# Figure out result register type and allocate a register for it.
@@ -395,13 +399,7 @@ QAST::Operations.add_core_op('callmethod', -> $qastcomp, $op {
395399
my $ops := $qastcomp.post_new('Ops');
396400
my @arg_results;
397401
for @args {
398-
my $arg_post := $qastcomp.as_post($_);
399-
$ops.push($arg_post);
400-
my $result := $arg_post.result;
401-
if $_.named -> $name {
402-
$result := $result ~ " :named(" ~ $qastcomp.escape($name) ~ ")";
403-
}
404-
@arg_results.push($result);
402+
handle_arg($_, $qastcomp, $ops, @arg_results);
405403
}
406404

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

0 commit comments

Comments
 (0)