Author: jonathan
Date: Thu Apr 12 16:32:47 2007
New Revision: 18170
Modified:
trunk/src/ops/object.ops
trunk/src/ops/ops.num
trunk/t/oo/ops.t
Log:
[PDD15]: Implement inspect opcodes, plus a test for each of them. One todo'd
due to Class PMC breakage.
Modified: trunk/src/ops/object.ops
==============================================================================
--- trunk/src/ops/object.ops (original)
+++ trunk/src/ops/object.ops Thu Apr 12 16:32:47 2007
@@ -565,11 +565,35 @@
goto NEXT();
}
+###############################################################################
+
+=item B<inspect>(out PMC, in PMC)
+
+Sets $1 to a PMC hash of all introspection data available for $2, keyed on
+name.
+
+=item B<inspect>(out PMC, in PMC, in STR)
+
+Sets $1 to a PMC Hash, Array, String, Integer, or Number value with
+introspection information corresponding to the requested string name.
+
+=cut
+
+inline op inspect(out PMC, in PMC) :object_classes {
+ $1 = VTABLE_inspect(interp, $2);
+ goto NEXT();
+}
+
+inline op inspect(out PMC, in PMC, in STR) :object_classes {
+ $1 = VTABLE_inspect_str(interp, $2, $3);
+ goto NEXT();
+}
+
=back
=head1 COPYRIGHT
-Copyright (C) 2001-2004, The Perl Foundation.
+Copyright (C) 2001-2007, The Perl Foundation.
=head1 LICENSE
Modified: trunk/src/ops/ops.num
==============================================================================
--- trunk/src/ops/ops.num (original)
+++ trunk/src/ops/ops.num Thu Apr 12 16:32:47 2007
@@ -1225,3 +1225,9 @@
stm_abort 1195
stm_depth_i 1196
addrole_p_p 1197
+inspect_p_p 1198
+inspect_p_pc 1199
+inspect_p_p_s 1200
+inspect_p_pc_s 1201
+inspect_p_p_sc 1202
+inspect_p_pc_sc 1203
Modified: trunk/t/oo/ops.t
==============================================================================
--- trunk/t/oo/ops.t (original)
+++ trunk/t/oo/ops.t Thu Apr 12 16:32:47 2007
@@ -6,7 +6,7 @@
use warnings;
use lib qw( . lib ../lib ../../lib );
use Test::More;
-use Parrot::Test tests => 1;
+use Parrot::Test tests => 3;
=head1 NAME
@@ -22,7 +22,7 @@
=cut
-pir_output_is( <<'CODE', <<'OUT', 'addrole' );
+pir_output_is( <<'CODE', <<'OUT', 'addrole_p_p' );
.sub 'test' :main
$P0 = new 'Role'
$P1 = new 'Class'
@@ -41,6 +41,47 @@
ok 2 - addrole op actually added the role
OUT
+pir_output_is( <<'CODE', <<'OUT', 'inspect_p_p', todo => 'inspect vtable
method for class broke' );
+.sub 'test' :main
+ $P0 = new 'Class'
+
+ $P1 = inspect $P0
+ print "ok 1 - inspect_p_p op executed\n"
+
+ $I0 = elements $P1
+ if $I0 == 6 goto ok_2
+ print "not "
+ok_2:
+ print "ok 2 - returned hash had correct number of elements\n"
+.end
+CODE
+ok 1 - inspect_p_p op executed
+ok 2 - returned hash had correct number of elements
+OUT
+
+pir_output_is( <<'CODE', <<'OUT', 'inspect_p_p_s' );
+.sub 'test' :main
+ $P0 = new 'Class'
+ $P0.name('foo')
+ $P0.add_attribute('a')
+
+ $P1 = inspect $P0, 'name'
+ say $P1
+ print "ok 1 - inspect_p_p_s with $3='name'\n"
+
+ $P1 = inspect $P0, 'attributes'
+ $I0 = elements $P1
+ if $I0 == 1 goto ok_2
+ print "not "
+ok_2:
+ print "ok 2 - inspect_p_p_s with $3='attributes'\n"
+.end
+CODE
+foo
+ok 1 - inspect_p_p_s with $3='name'
+ok 2 - inspect_p_p_s with $3='attributes'
+OUT
+
# Local Variables:
# mode: cperl
# cperl-indent-level: 4