develooper Front page | perl.cvs.parrot | Postings from December 2008

[svn:parrot] r33582 - trunk/runtime/parrot/library/Data/Dumper

From:
pmichaud
Date:
December 6, 2008 17:07
Subject:
[svn:parrot] r33582 - trunk/runtime/parrot/library/Data/Dumper
Message ID:
20081207010704.BE36CCB9AF@x12.develooper.com
Author: pmichaud
Date: Sat Dec  6 17:07:04 2008
New Revision: 33582

Modified:
   trunk/runtime/parrot/library/Data/Dumper/Default.pir

Log:
[library]:  Add dumper for Capture PMCs.


Modified: trunk/runtime/parrot/library/Data/Dumper/Default.pir
==============================================================================
--- trunk/runtime/parrot/library/Data/Dumper/Default.pir	(original)
+++ trunk/runtime/parrot/library/Data/Dumper/Default.pir	Sat Dec  6 17:07:04 2008
@@ -404,6 +404,76 @@
     .return ( 1 )
 .end
 
+
+=cut
+
+=item Capture dumpe
+
+Dump a capture object.
+
+=cut
+
+.namespace ['Capture']
+.sub '__dump' :method
+    .param pmc dumper
+    .param string label
+    .local int hasstuff
+    hasstuff = 0
+
+    .local string subindent, indent
+    (subindent, indent) = dumper.'newIndent'()
+
+    .local pmc hash, iter
+    hash = self.'hash'()
+    iter = new 'Iterator', hash
+  dump_hash_loop:
+    unless iter goto dump_hash_end
+    if hasstuff goto dump_hash_1
+    print " {"
+    hasstuff = 1
+  dump_hash_1:
+    print "\n"
+    print subindent
+    .local string key
+    .local pmc val
+    key = shift iter
+    val = hash[key]
+    print "<"
+    print key
+    print "> => "
+    dumper.'dump'(label, val)
+    goto dump_hash_loop
+  dump_hash_end:
+
+    .local pmc array
+    array = self.'list'()
+    if null array goto dump_array_end
+    $I1 = elements array
+    $I0 = 0
+  dump_array_loop:
+    if $I0 >= $I1 goto dump_array_end
+    if hasstuff goto dump_array_1
+    print " {"
+    hasstuff = 1
+  dump_array_1:
+    print "\n"
+    print subindent
+    val = array[$I0]
+    print "["
+    print $I0
+    print "] => "
+    dumper.'dump'(label, val)
+    inc $I0
+    goto dump_array_loop
+  dump_array_end:
+    unless hasstuff goto end
+    print "\n"
+    print indent
+    print '}'
+  end:
+    dumper.'deleteIndent'()
+.end
+
 =back
 
 =head1 AUTHOR



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About