Hi, The following patch adds parameter checking to _dumper(), as well as PMC property dumping. Wrong parameters are now reported (no exceptions are used yet). Tests are added to t/pmc/dumper.t, included in this patchfile.
jens
Index: t/pmc/dumper.t =================================================================== RCS file: /cvs/public/parrot/t/pmc/dumper.t,v retrieving revision 1.1 diff -u -w -r1.1 dumper.t --- t/pmc/dumper.t 12 Feb 2004 07:36:05 -0000 1.1 +++ t/pmc/dumper.t 16 Feb 2004 18:04:36 -0000 @@ -1,7 +1,7 @@ #! perl -w use strict; -use Parrot::Test tests => 6; +use Parrot::Test tests => 8; output_is(<<'CODE', <<'OUT', "dumping array of sorted numbers"); ##PIR## @@ -281,7 +281,6 @@ } "hash1" => PerlHash { "hash2" => PerlHash { - "hello3" => "world3", "array1" => PerlArray (size:5) [ "this", "is", @@ -292,8 +291,114 @@ "name" => "parrot", } ], + "hello3" => "world3", }, "hello" => "world", "hello2" => "world2", } +OUT + +output_is(<<'CODE', <<'OUT', "properties"); +##PIR## +.sub _main + .local pmc str + .local pmc array + + new array, .PerlArray + push array, "test1" + push array, "test2" + + new str, .PerlString + set str, "value1" + setprop array, "key1", str + + new str, .PerlString + set str, "value2" + setprop array, "key2", str + + _dumper( array ) + + end +.end +.include "library/dumper.imc" +CODE +PerlArray (size:2) [ + "test1", + "test2" +] with-properties: { + "key1" => "value1", + "key2" => "value2", +} +OUT + +output_is(<<'CODE', <<'OUT', "indent string"); +##PIR## +.sub _main + .local pmc hash1 + .local pmc hash2 + .local pmc array1 + .local pmc array2 + .local string name + .local string indent + + new hash1, .PerlHash + new hash2, .PerlHash + new array1, .PerlArray + new array2, .PerlArray + + set hash1["hash2"], hash2 + set hash2["array"], array1 + set hash1["test1"], "test1" + set hash2["test2"], "test2" + push array1, 1 + push array1, array2 + push array2, "test" + setprop hash1, "array2", array2 + name = "hash" + indent = "|" + _dumper( name, hash1, indent ) + _dumper( name, hash1, indent ) + print "name = '" + print name + print "'\nindent = '" + print indent + print "'\n" + end +.end +.include "library/dumper.imc" +CODE +|"hash" => PerlHash { + |"hash2" => PerlHash { + |"array" => PerlArray (size:2) [ + |1, + |PerlArray (size:1) [ + |"test" + |] + |], + |"test2" => "test2", + |}, + |"test1" => "test1", +|} with-properties: { + |"array2" => PerlArray (size:1) [ + |"test" + |], +|} +|"hash" => PerlHash { + |"hash2" => PerlHash { + |"array" => PerlArray (size:2) [ + |1, + |PerlArray (size:1) [ + |"test" + |] + |], + |"test2" => "test2", + |}, + |"test1" => "test1", +|} with-properties: { + |"array2" => PerlArray (size:1) [ + |"test" + |], +|} +name = 'hash' +indent = '|' OUT Index: library/dumper.imc =================================================================== RCS file: /cvs/public/parrot/library/dumper.imc,v retrieving revision 1.2 diff -u -w -r1.2 dumper.imc --- library/dumper.imc 14 Feb 2004 17:05:26 -0000 1.2 +++ library/dumper.imc 16 Feb 2004 18:04:36 -0000 @@ -151,11 +151,43 @@ .param pmc dump .param string indent + # check the number of INT args + if I1 != 0 goto ERROR + # check the number of PMC args + if I3 != 1 goto ERROR + # check the number of STR args + if I2 > 2 goto ERROR + if I2 < 0 goto ERROR + if I2 == 2 goto NAMED + if I2 == 0 goto UNNAMED + + # I2 == 1; no ident specified + set indent, "" + +NAMED: _helper() _do_dumper_named( name, dump, indent ) print "\n" + .pcc_begin_return + .return 1 + .pcc_end_return + +UNNAMED: + _helper() + _do_dumper_unnamed( dump, "" ) + print "\n" .pcc_begin_return + .return 1 + .pcc_end_return + +ERROR: + print "_dumper Syntax:\n" + print "_dumper( pmc )\n" + print "_dumper( name, pmc )\n" + print "_dumper( name, pmc, indent )\n\n" + .pcc_begin_return + .return 0 .pcc_end_return .end @@ -211,6 +243,13 @@ restoreall DONE: + prophash cb, dump + unless cb goto END + + print " with-properties: " + _dump_Hash( cb, indent ) + +END: .pcc_begin_return .pcc_end_return .end @@ -274,6 +313,19 @@ .sub _dump_PerlHash .param pmc hash .param string indent + + print "PerlHash " + _dump_Hash( hash, indent ) + .pcc_begin_return + .pcc_end_return +.end + +# +# Dumps a 'generic' Hash +# +.sub _dump_Hash + .param pmc hash + .param string indent .local string subindent .local pmc iter .local string key @@ -283,7 +335,7 @@ subindent = " " concat subindent, indent - print "PerlHash {" + print "{" new keys, .PerlArray new iter, .Iterator, hash