Skip to content

Commit

Permalink
Make IterationEnd.perl/gist/Str show "IterationEnd"
Browse files Browse the repository at this point in the history
Mostly for making debugging of iterators easier.
  • Loading branch information
lizmat committed Nov 13, 2016
1 parent cdca973 commit 59bb1b1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
3 changes: 0 additions & 3 deletions src/core/Any.pm
Expand Up @@ -11,9 +11,6 @@ my class X::Subscript::Negative { ... }

my role Numeric { ... }

# We use a sentinel value to mark the end of an iteration.
my constant IterationEnd = nqp::create(Mu);

my class Any { # declared in BOOTSTRAP
# my class Any is Mu

Expand Down
29 changes: 20 additions & 9 deletions src/core/Mu.pm
Expand Up @@ -3,6 +3,9 @@ my class X::Method::NotFound { ... }
my class X::Method::InvalidQualifier { ... }
my class X::Attribute::Required { ... }

# We use a sentinel value to mark the end of an iteration.
my constant IterationEnd = nqp::create(Mu);

my class Mu { # declared in BOOTSTRAP

method self { self }
Expand Down Expand Up @@ -444,7 +447,11 @@ my class Mu { # declared in BOOTSTRAP
''
}
multi method Str(Mu:D:) {
self.^name ~ '<' ~ nqp::tostr_I(nqp::objectid(self)) ~ '>'
nqp::if(
nqp::eqaddr(self,IterationEnd),
"IterationEnd",
self.^name ~ '<' ~ nqp::tostr_I(nqp::objectid(self)) ~ '>'
)
}

proto method Stringy(|) { * }
Expand Down Expand Up @@ -517,14 +524,18 @@ my class Mu { # declared in BOOTSTRAP
proto method perl(|) { * }
multi method perl(Mu:U:) { self.^name }
multi method perl(Mu:D:) {
self.perlseen(self.^name, {
my @attrs;
for self.^attributes().flat.grep: { .has_accessor } -> $attr {
my $name := substr($attr.Str,2);
@attrs.push: $name ~ ' => ' ~ $attr.get_value(self).perl
}
self.^name ~ '.new' ~ ('(' ~ @attrs.join(', ') ~ ')' if @attrs)
})
nqp::if(
nqp::eqaddr(self,IterationEnd),
"IterationEnd",
self.perlseen(self.^name, {
my @attrs;
for self.^attributes().flat.grep: { .has_accessor } -> $attr {
my $name := substr($attr.Str,2);
@attrs.push: $name ~ ' => ' ~ $attr.get_value(self).perl
}
self.^name ~ '.new' ~ ('(' ~ @attrs.join(', ') ~ ')' if @attrs)
})
)
}

proto method DUMP(|) { * }
Expand Down

0 comments on commit 59bb1b1

Please sign in to comment.