Skip to content

Commit

Permalink
implemented named arguments for 'callmethod'
Browse files Browse the repository at this point in the history
Same code as for 'call'. Will refactor in the next commit.
  • Loading branch information
Carl Masak committed May 26, 2012
1 parent 40e7584 commit d124e96
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/QAST/Operations.nqp
Expand Up @@ -397,7 +397,11 @@ QAST::Operations.add_core_op('callmethod', -> $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
2 changes: 1 addition & 1 deletion src/QAST/WVal.nqp
@@ -1,2 +1,2 @@
class QAST::WVal does QAST::CompileTimeValue {
class QAST::WVal is QAST::Node does QAST::CompileTimeValue {
}
16 changes: 15 additions & 1 deletion t/qast/qast.t
Expand Up @@ -36,6 +36,7 @@ class B { method m() { 'b' } }
class C { method add($a, $b) { $a + $b } }
class D { method m() { 206 } }
class E { has int $!x; }
class F { method greet(:$greeting, :$name) { "$greeting $name" } }

is_qast(
QAST::Block.new(
Expand Down Expand Up @@ -774,5 +775,18 @@ is_qast(
)
),
'OH HAI kathy',
'call with named argument works');
'call with named arguments works');
}

is_qast(
QAST::Block.new(
QAST::Op.new(
:op('callmethod'), :name('greet'),
QAST::WVal.new( :value(F) ),
QAST::SVal.new( :named('name'), :value('greg') ),
QAST::SVal.new( :named('greeting'), :value('DDD,') ),
)
),
'DDD, greg',
'callmethod with named arguments works');

0 comments on commit d124e96

Please sign in to comment.