Skip to content

Commit d124e96

Browse files
author
Carl Masak
committed
implemented named arguments for 'callmethod'
Same code as for 'call'. Will refactor in the next commit.
1 parent 40e7584 commit d124e96

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

src/QAST/Operations.nqp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,11 @@ QAST::Operations.add_core_op('callmethod', -> $qastcomp, $op {
397397
for @args {
398398
my $arg_post := $qastcomp.as_post($_);
399399
$ops.push($arg_post);
400-
@arg_results.push($arg_post.result);
400+
my $result := $arg_post.result;
401+
if $_.named -> $name {
402+
$result := $result ~ " :named(" ~ $qastcomp.escape($name) ~ ")";
403+
}
404+
@arg_results.push($result);
401405
}
402406

403407
# Figure out result register type and allocate a register for it.

src/QAST/WVal.nqp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
class QAST::WVal does QAST::CompileTimeValue {
1+
class QAST::WVal is QAST::Node does QAST::CompileTimeValue {
22
}

t/qast/qast.t

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class B { method m() { 'b' } }
3636
class C { method add($a, $b) { $a + $b } }
3737
class D { method m() { 206 } }
3838
class E { has int $!x; }
39+
class F { method greet(:$greeting, :$name) { "$greeting $name" } }
3940

4041
is_qast(
4142
QAST::Block.new(
@@ -774,5 +775,18 @@ is_qast(
774775
)
775776
),
776777
'OH HAI kathy',
777-
'call with named argument works');
778+
'call with named arguments works');
778779
}
780+
781+
is_qast(
782+
QAST::Block.new(
783+
QAST::Op.new(
784+
:op('callmethod'), :name('greet'),
785+
QAST::WVal.new( :value(F) ),
786+
QAST::SVal.new( :named('name'), :value('greg') ),
787+
QAST::SVal.new( :named('greeting'), :value('DDD,') ),
788+
)
789+
),
790+
'DDD, greg',
791+
'callmethod with named arguments works');
792+

0 commit comments

Comments
 (0)