Hi, this patch adds support for dumping of ParrotObjects. If an object "can __dump", this method is called on the object which then is responsible for dumping itself. A test that shows the new functionality in action is included.
jens
Index: library/dumper.imc =================================================================== RCS file: /cvs/public/parrot/library/dumper.imc,v retrieving revision 1.7 diff -u -w -r1.7 dumper.imc --- library/dumper.imc 4 Mar 2004 12:44:45 -0000 1.7 +++ library/dumper.imc 4 Mar 2004 18:10:46 -0000 @@ -313,15 +313,23 @@ if exist, CALL_HELPER typeof type_str, dump - print "unknown-type(pmc #" - print ":" + print "PMC '" print type_str - print type - print ")" + print "' " + can I0, dump, "__dump" + if I0 goto CAN_DUMP + print "{ ... }" branch DONE +CAN_DUMP: + # XXX method calling needs some work + P2 = dump + find_global cb, type_str, "__dump" + branch DO_CALL_HELPER + CALL_HELPER: cb = helper[type] +DO_CALL_HELPER: .pcc_begin prototyped .arg name .arg indent Index: t/pmc/dumper.t =================================================================== RCS file: /cvs/public/parrot/t/pmc/dumper.t,v retrieving revision 1.4 diff -u -w -r1.4 dumper.t --- t/pmc/dumper.t 23 Feb 2004 10:18:43 -0000 1.4 +++ t/pmc/dumper.t 4 Mar 2004 18:10:47 -0000 @@ -18,7 +18,7 @@ use strict; -use Parrot::Test tests => 11; +use Parrot::Test tests => 12; # no. 1 output_is(<<'CODE', <<'OUT', "dumping array of sorted numbers"); @@ -511,5 +511,61 @@ }, \VAR1[0].properties(), \VAR1[1].properties() +] +OUT + +# no. 12 +output_is(<<'CODE', <<'OUT', "dumping objects"); +##PIR## +.sub _main + .local pmc temp + .local pmc array + + newclass temp, "TestClass" + + find_global temp, "_TestClass::__dump" + store_global "TestClass", "__dump", temp + + find_type I0, "TestClass" + new array, .PerlArray + new temp, I0 + push array, temp + new temp, I0 + push array, temp + + _dumper( array ) + end +.end +.sub _TestClass::__dump + .param string name + .param pmc dump + .param pmc cache + .param string indent + + print "{\n" + + print indent + print " this is\n" + + print indent + print " _TestClass::__dump\n" + + print indent + print "}" + + .pcc_begin_return + .pcc_end_return +.end +.include "library/dumper.imc" +CODE +"VAR1" => PerlArray (size:2) [ + PMC 'TestClass' { + this is + _TestClass::__dump + }, + PMC 'TestClass' { + this is + _TestClass::__dump + } ] OUT