Skip to content

Commit

Permalink
[pmc] Object.invoke as vtable override: fix unstable self heuristic
Browse files Browse the repository at this point in the history
Change experimental usage of vtable overridden subs.
Only push self if the sub is a method, otherwise replace it.

Closes #1013. Thanks to Zefram
  • Loading branch information
Reini Urban committed Nov 15, 2014
1 parent 1625bfd commit 54e24e9
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 7 deletions.
3 changes: 3 additions & 0 deletions ChangeLog
Expand Up @@ -24,6 +24,9 @@
+ Unescape double-quoted .lex string constants. #1095, perl6 RT#116643
+ Downgrade external ascii strings on multi-byte platform encodings
to ascii. #1098
+ Fix self heuristic with vtable overridden method calls.
$P0() instead of $P0($P0) is now stable, push if $P0 is a :method, otherwise set.
https://trac.parrot.org/parrot/ticket/103 #1013
- Build
+ Set -mabi=64 for gcc --m=64 on mips, -m64 on powerpc #1110
+ Add --{en,dis}able-static #1104
Expand Down
6 changes: 4 additions & 2 deletions api.yaml
Expand Up @@ -198,12 +198,14 @@
ticket: 'https://trac.parrot.org/parrot/ticket/852'
-
name: 'Overriding vtable invoke in PIR objects'
note: 'The VTABLE invoke in object.pmc puts SELF at the start of the signature call arguments when there is no current object and is not already here. This allows the usage of $P0() instead of $P0($P0).'
note: 'The VTABLE invoke in object.pmc pushes or replaces SELF at the start of the signature call arguments. It pushes when the vtable method is marked as :method. This allows the usage of $P0() instead of $P0($P0). This changed with 6.10.0'
tags:
- 'PMC'
- 'experimental'
- 'completed'
ticket: 'https://trac.parrot.org/parrot/ticket/103'
ticket:
- 'https://trac.parrot.org/parrot/ticket/103'
- 'https://github.com/parrot/parrot/issues/1013'
-
name: 'PARROT_LIBRARY and PARROT_INCLUDE environment variables'
note: 'A way to provide an equivalent of -L and -I parrot command line options to language that doesn''t support it.'
Expand Down
8 changes: 5 additions & 3 deletions src/pmc/object.pmc
Expand Up @@ -22,6 +22,7 @@ Parrot_ext_call, which creates a new interp, task and calls a new runloop.

#include "parrot/oo_private.h"
#include "pmc/pmc_class.h"
#include "pmc/pmc_sub.h"

/* HEADERIZER HFILE: none */
/* HEADERIZER BEGIN: static */
Expand Down Expand Up @@ -828,10 +829,11 @@ Invokes the object (if this vtable function is overridden).
PMC * const call_sig =
Parrot_pcc_get_signature(INTERP, CURRENT_CONTEXT(INTERP));

if ((VTABLE_elements(INTERP, call_sig) == 0
|| VTABLE_get_pmc_keyed_int(INTERP, call_sig, 0) != SELF))
/* Check for :method if to add or set SELF. GH #1013 */
if (Sub_comp_flag_TEST(METHOD, PARROT_SUB(meth)))
VTABLE_unshift_pmc(INTERP, call_sig, SELF);

else
VTABLE_set_pmc_keyed_int(INTERP, call_sig, 0, SELF);
return VTABLE_invoke(INTERP, meth, next);
}

Expand Down
29 changes: 27 additions & 2 deletions t/pmc/object-meths.t
@@ -1,11 +1,11 @@
#! perl
# Copyright (C) 2001-2010, Parrot Foundation.
# Copyright (C) 2001-2014, Parrot Foundation.

use strict;
use warnings;
use lib qw( . lib ../lib ../../lib );
use Test::More;
use Parrot::Test tests => 38;
use Parrot::Test tests => 39;

=head1 NAME
Expand Down Expand Up @@ -1138,6 +1138,31 @@ CODE
1
OUTPUT

pir_output_is( <<'CODE', <<'OUTPUT', "vtable invoke self", todo => 'GH #1013' );
.sub "" :anon :init :load
$P0 = newclass "MyFunc"
.end
.namespace ["MyFunc"]
.sub invoke :vtable
.param pmc a
say "ok"
.return ()
.end
.namespace []
.sub main :main
$P0 = new "MyFunc"
$P1 = new "MyFunc"
$P0("a")
$P0($P1)
$P0($P0)
.end
CODE
ok
ok
ok
OUTPUT


# Local Variables:
# mode: cperl
# cperl-indent-level: 4
Expand Down

0 comments on commit 54e24e9

Please sign in to comment.