Skip to content

Commit

Permalink
Implement $obj.Foo::bar() method calls. Patch courtesy of John Harris…
Browse files Browse the repository at this point in the history
…on (__ash__++).
  • Loading branch information
jnthn committed Aug 19, 2009
1 parent 9520b46 commit 8924df4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/builtins/guts.pir
Expand Up @@ -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:
Expand Down
21 changes: 19 additions & 2 deletions src/parser/actions.pm
Expand Up @@ -1393,7 +1393,7 @@ method dotty($/, $key) {

# We actually need to send dispatches for named method calls (other than .*)
# through the.dispatcher.
if $<dottyop><methodop><variable> {
if $past<indirect_call> {
$past.name('!dispatch_method_indirect');
$past.pasttype('call');
}
Expand Down Expand Up @@ -1422,10 +1422,27 @@ method methodop($/, $key) {
$past.node($/);

if $<name> {
$past.name(~$<name>);
my @ns := Perl6::Compiler.parse_name(~$<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<indirect_call> := 1;
}
else {
$past.name(~$<name>);
}
}
elsif $<variable> {
$past.unshift( $<variable>.ast );
$past<indirect_call> := 1;
}
else {
$past.name( $<quote>.ast );
Expand Down

0 comments on commit 8924df4

Please sign in to comment.