Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[QAST::Operations] implemented named arguments
Named parameters were already implemented, so making a
call with named args works now.
  • Loading branch information
Carl Masak committed May 26, 2012
1 parent b0b24cf commit 40e7584
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/QAST/Operations.nqp
Expand Up @@ -351,7 +351,11 @@ QAST::Operations.add_core_op('call', -> $qastcomp, $op {
for @args {
my $arg_post := $qastcomp.as_post($_);
$ops.push($arg_post);
@arg_results.push($arg_post.result);
my $result := $arg_post.result;
if $_.named -> $name {
$result := $result ~ " :named(" ~ $qastcomp.escape($name) ~ ")";
}
@arg_results.push($result);
}

# Figure out result register type and allocate a register for it.
Expand Down
29 changes: 29 additions & 0 deletions t/qast/qast.t
Expand Up @@ -747,3 +747,32 @@ is_qast(
my $missing := $block.symbol('sabre-toothed tiger');
ok(!pir::defined($missing), 'QAST::Block.symbol on a nonexistent key returns an undefined value');
}

{
my $greeter := QAST::Block.new(
QAST::Var.new( :name('greeting'), :named('greeting'), :scope('local'), :decl('param'), :returns(str) ),
QAST::Var.new( :name('name'), :named('name'), :scope('local'), :decl('param'), :returns(str) ),
QAST::Op.new(
:op('concat'),
QAST::Op.new(
:op('concat'),
QAST::Var.new( :name('greeting'), :scope('local') ),
QAST::SVal.new( :value(' ') ),
),
QAST::Var.new( :name('name'), :scope('local') )
),
);

is_qast(
QAST::Block.new(
$greeter,
QAST::Op.new(
:op('call'),
QAST::BVal.new( :value($greeter) ),
QAST::SVal.new( :named('name'), :value('kathy') ),
QAST::SVal.new( :named('greeting'), :value('OH HAI') ),
)
),
'OH HAI kathy',
'call with named argument works');
}

0 comments on commit 40e7584

Please sign in to comment.