Skip to content

Commit

Permalink
[QAST::Operations] implement flattened arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
Carl Masak committed May 26, 2012
1 parent 2b55922 commit b66b2e1
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/QAST/Operations.nqp
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}
Expand Down
26 changes: 26 additions & 0 deletions t/qast/qast.t
Expand Up @@ -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.