Permalink
Browse files

[QAST::Operations] implemented named arguments

Named parameters were already implemented, so making a
call with named args works now.
  • Loading branch information...
1 parent b0b24cf commit 40e7584f51a48e0ee0057a94bd3ab1f2375eccb7 @masak masak committed May 26, 2012
Showing with 34 additions and 1 deletion.
  1. +5 −1 src/QAST/Operations.nqp
  2. +29 −0 t/qast/qast.t
View
@@ -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.
View
@@ -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.