Thanks for the head start; now I know to include a test in the future.
Here is an updated version of your patch, with various minor fixes.

On 2/17/07, Allison Randal via RT <[EMAIL PROTECTED]> wrote:
On Sat Jan 27 11:39:15 2007, [EMAIL PROTECTED] wrote:
> This patch allows object vtable method overrides for find_method,
get_attr,
> get_attr, get_attr_str, set_attr, set_attr_str, and get_class.  Now these
> can be overridden in PIR using the :vtable flag or prefixing their
> respective names with "__".  It affects src/pmc/parrotobject.pmc and
> src/ops/object.ops.

Thanks. The patch looks good. Could you also supply a regression test
that demonstrates what was failing before the patch, and passes with the
patch applied? Something along the lines of the attached patch, though I
only spent a few minutes on it and expect you'll want to expand it.

Allison

--- t/pmc/object-meths.t.old	2007-02-19 15:17:21.000000000 +0000
+++ t/pmc/object-meths.t	2007-02-19 16:01:52.000000000 +0000
@@ -6,7 +6,7 @@
 use warnings;
 use lib qw( . lib ../lib ../../lib );
 use Test::More;
-use Parrot::Test tests => 40;
+use Parrot::Test tests => 43;
 
 =head1 NAME
 
@@ -1325,6 +1325,91 @@
 init_pmc was called
 OUTPUT
 
+
+pir_output_is( <<'CODE', <<'OUTPUT', "overloading find_method vtable" );
+.sub main :main
+    .local pmc cl, o
+    cl = newclass 'MyClass'
+    o = new 'MyClass'
+    o.'foo'()
+.end
+
+.namespace ['MyClass']
+
+.sub find_method :method :vtable
+    .param string methodname
+    print "find_method was called\n"
+    $P0 = find_global "MyClass", methodname
+    .return($P0)
+.end
+
+.sub foo
+  print "foo was called\n"
+.end
+
+CODE
+find_method was called
+foo was called
+OUTPUT
+
+pir_output_is( <<'CODE', <<'OUTPUT', "overloading attribute accessor vtable" );
+.sub main :main
+    .local pmc cl, o
+    cl = newclass 'MyClass'
+    o = new 'MyClass'
+    $P2 = new String
+    $P2 = "blue"
+    setattribute o, 0, $P2
+    setattribute o, "blue", $P2
+    $P1 = getattribute o, 0
+    $P1 = getattribute o, "blue"
+.end
+
+.namespace ['MyClass']
+
+.sub get_attr :method :vtable
+    .param int offset
+    print "get_attr was called\n"
+.end
+.sub get_attr_str :method :vtable
+    .param string attrname
+    print "get_attr_str was called\n"
+.end
+.sub set_attr :method :vtable
+    .param int offset
+    .param pmc val
+    print "set_attr was called\n"
+.end
+.sub set_attr_str :method :vtable
+    .param string attrname
+    .param pmc val
+    print "set_attr_str was called\n"
+.end
+CODE
+set_attr was called
+set_attr_str was called
+get_attr was called
+get_attr_str was called
+OUTPUT
+
+pir_output_is( <<'CODE', <<'OUTPUT', "overloading get_class vtable" );
+.sub main :main
+    .local pmc cl, o, cl2
+    cl = newclass 'MyClass'
+    o = new 'MyClass'
+    cl2 = class o
+.end
+
+.namespace ['MyClass']
+
+.sub get_class :method :vtable
+    print "get_class was called\n"
+.end
+
+CODE
+get_class was called
+OUTPUT
+
 # Local Variables:
 #   mode: cperl
 #   cperl-indent-level: 4

Reply via email to