From 8924df4f969fd7eb1c085f634ac5b357d9e9d300 Mon Sep 17 00:00:00 2001 From: jnthn Date: Thu, 20 Aug 2009 00:46:32 +0200 Subject: [PATCH] Implement $obj.Foo::bar() method calls. Patch courtesy of John Harrison (__ash__++). --- src/builtins/guts.pir | 3 +++ src/parser/actions.pm | 21 +++++++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/builtins/guts.pir b/src/builtins/guts.pir index 9d453048f07..0575278cf94 100644 --- a/src/builtins/guts.pir +++ b/src/builtins/guts.pir @@ -106,9 +106,12 @@ Does an indirect method dispatch. .param pmc pos_args :slurpy .param pmc name_args :slurpy :named + $I0 = isa methodish, 'P6Invocation' + if $I0 goto ready_to_dispatch $P0 = get_hll_global 'Callable' $I0 = $P0.'ACCEPTS'(methodish) unless $I0 goto candidate_list + ready_to_dispatch: .tailcall methodish(obj, pos_args :flat, name_args :flat :named) candidate_list: diff --git a/src/parser/actions.pm b/src/parser/actions.pm index df6451a7147..3ac88e929ad 100644 --- a/src/parser/actions.pm +++ b/src/parser/actions.pm @@ -1393,7 +1393,7 @@ method dotty($/, $key) { # We actually need to send dispatches for named method calls (other than .*) # through the.dispatcher. - if $ { + if $past { $past.name('!dispatch_method_indirect'); $past.pasttype('call'); } @@ -1422,10 +1422,27 @@ method methodop($/, $key) { $past.node($/); if $ { - $past.name(~$); + my @ns := Perl6::Compiler.parse_name(~$); + my $short_name := ~@ns.pop(); + + if @ns { + $past.name(''); + $past.unshift(PAST::Op.new( + :inline(' %r = find_method %0, "' ~ $short_name ~ '"'), + PAST::Var.new( + :scope('package'), + :name(@ns.pop), + :namespace(@ns) + ))); + $past := 1; + } + else { + $past.name(~$); + } } elsif $ { $past.unshift( $.ast ); + $past := 1; } else { $past.name( $.ast );