diff --git a/src/QAST/Operations.nqp b/src/QAST/Operations.nqp index 326dc93e50..d67e5261a8 100644 --- a/src/QAST/Operations.nqp +++ b/src/QAST/Operations.nqp @@ -127,6 +127,22 @@ QAST::Operations.add_core_op('list', -> $qastcomp, $op { $ops }); +QAST::Operations.add_core_op('list_i', -> $qastcomp, $op { + # Create register for the resulting list and make an empty one. + my $list_reg := $*REGALLOC.fresh_p(); + my $ops := $qastcomp.post_new('Ops', :result($list_reg)); + $ops.push_pirop('new', $list_reg, "'ResizableIntegerArray'"); + + # Push all the things. + for $op.list { + my $post := $qastcomp.coerce($qastcomp.as_post($_), 'i'); + $ops.push($post); + $ops.push_pirop('push', $list_reg, $post.result); + } + + $ops +}); + QAST::Operations.add_core_op('hash', -> $qastcomp, $op { # Create register for the resulting hash and make an empty one. my $hash_reg := $*REGALLOC.fresh_p(); @@ -335,8 +351,11 @@ 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) ~ ")"; + if $arg.flat { + $result := "$result :flat"; + } + elsif $arg.named -> $name { + $result := "$result :named(" ~ $qastcomp.escape($name) ~ ")"; } @arg_results.push($result); } diff --git a/t/qast/qast.t b/t/qast/qast.t index d0e2b6d60f..ed7b95437c 100644 --- a/t/qast/qast.t +++ b/t/qast/qast.t @@ -815,3 +815,29 @@ is_qast( 'call to block with slurpy parameter works'); } +{ + my $third := QAST::Block.new( + QAST::Var.new( :name('a'), :scope('local'), :decl('param') ), + QAST::Var.new( :name('b'), :scope('local'), :decl('param') ), + QAST::Var.new( :name('c'), :scope('local'), :decl('param') ), + QAST::Var.new( :name('c'), :scope('local') ), + ); + + is_qast( + QAST::Block.new( + $third, + QAST::Op.new( + :op('call'), + QAST::BVal.new( :value($third) ), + QAST::Op.new( + :op('list_i'), + QAST::IVal.new( :value(40) ), + QAST::IVal.new( :value(41) ), + QAST::IVal.new( :value(42) ), + :flat, + ) + ) + ), + 42, + 'call with flattened argument works'); +}