Permalink
Browse files

[QAST::Operations] implement flattened arguments

  • Loading branch information...
1 parent 2b55922 commit b66b2e1f8fa6c1e25f14fc97c6dd905967bc37b8 @masak masak committed May 26, 2012
Showing with 47 additions and 2 deletions.
  1. +21 −2 src/QAST/Operations.nqp
  2. +26 −0 t/qast/qast.t
@@ -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);
}
View
@@ -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');
+}

0 comments on commit b66b2e1

Please sign in to comment.