Skip to content
Browse files

implemented named arguments for 'callmethod'

Same code as for 'call'. Will refactor in the next commit.
  • Loading branch information...
1 parent 40e7584 commit d124e9616cd471bc5cb09e145b2dd6c4a019f74c @masak masak committed
Showing with 21 additions and 3 deletions.
  1. +5 −1 src/QAST/Operations.nqp
  2. +1 −1 src/QAST/WVal.nqp
  3. +15 −1 t/qast/qast.t
View
6 src/QAST/Operations.nqp
@@ -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.
View
2 src/QAST/WVal.nqp
@@ -1,2 +1,2 @@
-class QAST::WVal does QAST::CompileTimeValue {
+class QAST::WVal is QAST::Node does QAST::CompileTimeValue {
}
View
16 t/qast/qast.t
@@ -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(
@@ -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.
Something went wrong with that request. Please try again.