Skip to content

Commit b66b2e1

Browse files
author
Carl Masak
committed
[QAST::Operations] implement flattened arguments
1 parent 2b55922 commit b66b2e1

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed

src/QAST/Operations.nqp

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,22 @@ QAST::Operations.add_core_op('list', -> $qastcomp, $op {
127127
$ops
128128
});
129129

130+
QAST::Operations.add_core_op('list_i', -> $qastcomp, $op {
131+
# Create register for the resulting list and make an empty one.
132+
my $list_reg := $*REGALLOC.fresh_p();
133+
my $ops := $qastcomp.post_new('Ops', :result($list_reg));
134+
$ops.push_pirop('new', $list_reg, "'ResizableIntegerArray'");
135+
136+
# Push all the things.
137+
for $op.list {
138+
my $post := $qastcomp.coerce($qastcomp.as_post($_), 'i');
139+
$ops.push($post);
140+
$ops.push_pirop('push', $list_reg, $post.result);
141+
}
142+
143+
$ops
144+
});
145+
130146
QAST::Operations.add_core_op('hash', -> $qastcomp, $op {
131147
# Create register for the resulting hash and make an empty one.
132148
my $hash_reg := $*REGALLOC.fresh_p();
@@ -335,8 +351,11 @@ sub handle_arg($arg, $qastcomp, $ops, @arg_results) {
335351
my $arg_post := $qastcomp.as_post($arg);
336352
$ops.push($arg_post);
337353
my $result := $arg_post.result;
338-
if $arg.named -> $name {
339-
$result := $result ~ " :named(" ~ $qastcomp.escape($name) ~ ")";
354+
if $arg.flat {
355+
$result := "$result :flat";
356+
}
357+
elsif $arg.named -> $name {
358+
$result := "$result :named(" ~ $qastcomp.escape($name) ~ ")";
340359
}
341360
@arg_results.push($result);
342361
}

t/qast/qast.t

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -815,3 +815,29 @@ is_qast(
815815
'call to block with slurpy parameter works');
816816
}
817817

818+
{
819+
my $third := QAST::Block.new(
820+
QAST::Var.new( :name('a'), :scope('local'), :decl('param') ),
821+
QAST::Var.new( :name('b'), :scope('local'), :decl('param') ),
822+
QAST::Var.new( :name('c'), :scope('local'), :decl('param') ),
823+
QAST::Var.new( :name('c'), :scope('local') ),
824+
);
825+
826+
is_qast(
827+
QAST::Block.new(
828+
$third,
829+
QAST::Op.new(
830+
:op('call'),
831+
QAST::BVal.new( :value($third) ),
832+
QAST::Op.new(
833+
:op('list_i'),
834+
QAST::IVal.new( :value(40) ),
835+
QAST::IVal.new( :value(41) ),
836+
QAST::IVal.new( :value(42) ),
837+
:flat,
838+
)
839+
)
840+
),
841+
42,
842+
'call with flattened argument works');
843+
}

0 commit comments

Comments
 (0)