Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Eliminate use of Parrot dumper.
We didn't use it for --target=ast, but --target=parse relied on it. The
output was incredibly verbose, so replace it with something that does
not rely on the Parrot dumper and gives more compact, and hopefully
more useful, output. Tweaks welcome.
  • Loading branch information
jnthn committed Feb 27, 2013
1 parent a93281b commit 1c6c851
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 31 deletions.
4 changes: 1 addition & 3 deletions src/HLL/Compiler.pm
Expand Up @@ -337,8 +337,6 @@ class HLL::Compiler does HLL::Backend::Default {
%adverbs<precomp> := 1;
}

nqp::loadbytecode('dumper.pbc');

self.command_eval(|@a, |%adverbs);
}

Expand Down Expand Up @@ -548,7 +546,7 @@ class HLL::Compiler does HLL::Backend::Default {
nqp::print($obj.dump());
}
else {
(Q:PIR { %r = get_root_global ['parrot'], '_dumper' })($obj, $name)
nqp::die("Cannot dump this object; no dump method");
}
}

Expand Down
60 changes: 59 additions & 1 deletion src/QRegex/Cursor.nqp
Expand Up @@ -611,7 +611,65 @@ class NQPMatch is NQPCapture {

method !make($ast) { $!ast := $ast }
method ast() { $!ast }


method dump($indent?) {
unless nqp::defined($indent) {
$indent := 0;
}
if self.Bool() {
my @chunks;

sub dump_match($key, $value) {
nqp::push(@chunks, nqp::x(' ', $indent));
nqp::push(@chunks, '- ');
nqp::push(@chunks, $key);
nqp::push(@chunks, ': ');
if nqp::can($value, 'Str') {
nqp::push(@chunks, $value.Str());
}
else {
nqp::push(@chunks, '<object>');
}
nqp::push(@chunks, "\n");
if nqp::can($value, 'dump') {
nqp::push(@chunks, $value.dump($indent + 2));
}
}

sub dump_match_array($key, @matches) {
nqp::push(@chunks, nqp::x(' ', $indent));
nqp::push(@chunks, '- ');
nqp::push(@chunks, $key);
nqp::push(@chunks, ': ');
nqp::push(@chunks, ~+@matches);
nqp::push(@chunks, " matches\n");
for @matches {
nqp::push(@chunks, $_.dump($indent + 2));
}
}

my int $i := 0;
for self.list() {
if $_ {
nqp::islist($_)
?? dump_match_array($i, $_)
!! dump_match($i, $_);
}
}
for self.hash() {
if $_.value {
nqp::islist($_.value)
?? dump_match_array($_.key, $_.value)
!! dump_match($_.key, $_.value);
}
}
return nqp::join('', @chunks);
}
else {
return nqp::x(' ', $indent) ~ "- NO MATCH\n";
}
}

method !dump_str($key) {
sub dump_array($key, $item) {
my $str := '';
Expand Down
27 changes: 0 additions & 27 deletions src/core/NQPMu.pm
Expand Up @@ -99,31 +99,4 @@ my class NQPMu {
method isa($type) {
self.HOW.isa(self, $type)
}

method __dump($dumper, $label) {
return 0 unless nqp::isconcrete(self);
my $subindent := $dumper.'newIndent'();
print('{');
for self.HOW.parents(self) -> $type {
for $type.HOW.attributes($type, :local) {
my $name := $_.name;
my $attrtype := $_.type;
print("\n", $subindent, $type.HOW.name($type), "::", $name, " => ");
if $attrtype =:= int {
$dumper.'dump'($label, nqp::getattr_i(self, $type, $name));
}
elsif $attrtype =:= num {
$dumper.'dump'($label, nqp::getattr_n(self, $type, $name));
}
elsif $attrtype =:= str {
$dumper.'dump'($label, nqp::getattr_s(self, $type, $name));
}
else {
$dumper.'dump'($label, nqp::getattr(self, $type, $name));
}
}
}
$dumper.deleteIndent();
print("\n", $dumper.indent, '}');
}
}

0 comments on commit 1c6c851

Please sign in to comment.