Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
pervasive changes for non-flattening for loops
(It's possible we can remove some of the .flats here or there without
damage, but I erred on the side of caution on some of them.)
  • Loading branch information
TimToady committed Apr 28, 2015
1 parent 71d6480 commit 04cc1d5
Show file tree
Hide file tree
Showing 16 changed files with 104 additions and 92 deletions.
5 changes: 5 additions & 0 deletions src/core/Any.pm
Expand Up @@ -182,6 +182,11 @@ my class Any { # declared in BOOTSTRAP
proto method for (|) { * }
multi method for(Whatever) is rw { self }
multi method for($block, :$label) is rw {
MapIter.new(self, $block, Bool::False, :$label).list;
}
proto method flatmap (|) { * }
multi method flatmap(Whatever) is rw { self }
multi method flatmap($block, :$label) is rw {
MapIter.new(self, $block, Bool::True, :$label).list
}
method nodemap($block) is rw { nodemap($block, self) }
Expand Down
2 changes: 1 addition & 1 deletion src/core/Capture.pm
Expand Up @@ -22,7 +22,7 @@ my class Capture { # declared in BOOTSTRAP
if $!list {
$WHICH ~= '|';
$WHICH ~= ( '(' ~ $_.WHICH ~ ')' )
for $!list;
for flat $!list;
}
if $!hash {
$WHICH ~= '|';
Expand Down
4 changes: 2 additions & 2 deletions src/core/HashIter.pm
Expand Up @@ -117,7 +117,7 @@ my class HashIter is Iterator {
nqp::push($rpa, Pair.new(
:value($k),
:key($_)))
for nqp::hllize(nqp::iterval($pairish)).list;
for flat nqp::hllize(nqp::iterval($pairish)).list;
}
}
else {
Expand All @@ -127,7 +127,7 @@ my class HashIter is Iterator {
nqp::push($rpa, Pair.new(
:value($k),
:key($_)))
for nqp::hllize(nqp::iterval($pairish)).list;
for flat nqp::hllize(nqp::iterval($pairish)).list;
}
}
}
Expand Down
20 changes: 10 additions & 10 deletions src/core/Mu.pm
Expand Up @@ -307,7 +307,7 @@ my class Mu { # declared in BOOTSTRAP
multi method perl(Mu:U:) { self.^name }
multi method perl(Mu:D:) {
my @attrs;
for self.^attributes().grep: { .has_accessor } -> $attr {
for self.^attributes().flat.grep: { .has_accessor } -> $attr {
my $name := substr($attr.Str,2);
@attrs.push: $name
~ ' => '
Expand All @@ -322,7 +322,7 @@ my class Mu { # declared in BOOTSTRAP
return DUMP(self, :$indent-step) unless %ctx;

my Mu $attrs := nqp::list();
for self.^attributes -> $attr {
for self.^attributes.flat -> $attr {
my str $name = $attr.name;
my str $acc_name = nqp::substr($name, 2, nqp::chars($name) - 2);
my str $build_name = $attr.has_accessor ?? $acc_name !! $name;
Expand Down Expand Up @@ -402,7 +402,7 @@ my class Mu { # declared in BOOTSTRAP
method clone(*%twiddles) {
my $cloned := nqp::clone(nqp::decont(self));
if %twiddles.elems {
for self.^attributes() -> $attr {
for self.^attributes.flat -> $attr {
my $name := $attr.name;
my $package := $attr.package;
unless nqp::objprimspec($attr.type) {
Expand All @@ -417,7 +417,7 @@ my class Mu { # declared in BOOTSTRAP
}
}
else {
for self.^attributes() -> $attr {
for self.^attributes.flat -> $attr {
unless nqp::objprimspec($attr.type) {
my $name := $attr.name;
my $package := $attr.package;
Expand All @@ -433,7 +433,7 @@ my class Mu { # declared in BOOTSTRAP

method Capture() {
my %attrs;
for self.^attributes -> $attr {
for self.^attributes.flat -> $attr {
if $attr.has-accessor {
my $name = substr($attr.name,2);
unless %attrs.EXISTS-KEY($name) {
Expand Down Expand Up @@ -538,7 +538,7 @@ my class Mu { # declared in BOOTSTRAP
push @classes, @search_list;
my @new_search_list;
for @search_list -> $current {
for $current.^parents(:local) -> $next {
for flat $current.^parents(:local) -> $next {
unless @new_search_list.grep({ $^c.WHAT =:= $next.WHAT }) {
push @new_search_list, $next;
}
Expand All @@ -550,7 +550,7 @@ my class Mu { # declared in BOOTSTRAP
sub build_ascendent(Mu $class) {
unless @classes.grep({ $^c.WHAT =:= $class.WHAT }) {
push @classes, $class;
for $class.^parents(:local) {
for flat $class.^parents(:local) {
build_ascendent($^parent);
}
}
Expand All @@ -559,7 +559,7 @@ my class Mu { # declared in BOOTSTRAP
} elsif $descendant {
sub build_descendent(Mu $class) {
unless @classes.grep({ $^c.WHAT =:= $class.WHAT }) {
for $class.^parents(:local) {
for flat $class.^parents(:local) {
build_descendent($^parent);
}
push @classes, $class;
Expand All @@ -578,7 +578,7 @@ my class Mu { # declared in BOOTSTRAP
if (!defined($include) || $include.ACCEPTS($class)) &&
(!defined($omit) || !$omit.ACCEPTS($class)) {
try {
for $class.^methods(:local) -> $method {
for flat $class.^methods(:local) -> $method {
my $check_name = $method.?name;
if $check_name.defined && $check_name eq $name {
@methods.push($method);
Expand Down Expand Up @@ -664,7 +664,7 @@ sub DUMP(|args (*@args, :$indent-step = 4, :%ctx?)) {

my @pieces;
{
for $topic {
for $topic.pairs {
@pieces.push: $_.key ~ ' => ' ~ DUMP($_.value, :$indent-step, :%ctx);
}
CATCH { default { @pieces.push: '...' } }
Expand Down
9 changes: 8 additions & 1 deletion src/core/Parcel.pm
Expand Up @@ -75,7 +75,14 @@ my class Parcel does Positional { # declared in BOOTSTRAP
method list() { nqp::p6list(nqp::clone($!storage), List, Mu) }
method lol() { nqp::p6list(nqp::clone($!storage), LoL, Mu) }
method eager() { nqp::p6list(nqp::clone($!storage), List, Mu).eager }
method for(|c) { nqp::p6list(nqp::clone($!storage), List, Bool::True).map(|c) }
method for(|c) {
if nqp::elems($!storage) == 1 and !nqp::isnull(nqp::atpos($!storage,0)) and !nqp::iscont(nqp::atpos($!storage,0)) {
try { nqp::atpos($!storage,0).map(|c) } // nqp::p6list(nqp::clone($!storage), List, Mu).map(|c);
}
else {
nqp::p6list(nqp::clone($!storage), List, Mu).map(|c);
}
}
method map(|c) { nqp::p6list(nqp::clone($!storage), List, Mu).map(|c) }
method join(|c) { nqp::p6list(nqp::clone($!storage), List, Mu).join(|c) }

Expand Down
2 changes: 1 addition & 1 deletion src/core/Pod.pm
Expand Up @@ -22,7 +22,7 @@ my class Pod::Block {
}
}
@chunks = $leading, $pod.^name, (%confs.perl if %confs), "\n";
for $pod.contents.list -> $c {
for $pod.contents.flat -> $c {
if nqp::istype($c,Pod::Block) {
@chunks.push: pod-gist($c, $level + 2);
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/Regex.pm
Expand Up @@ -15,7 +15,7 @@ my class Regex { # declared in BOOTSTRAP
my $dollar_slash := nqp::getlexrelcaller(
nqp::ctxcallerskipthunks(nqp::ctx()),
'$/');
for @a {
for flat @a {
$dollar_slash = SELF.(Cursor.'!cursor_init'($_, :c(0))).MATCH_SAVE;
return $dollar_slash if $dollar_slash;
}
Expand Down

0 comments on commit 04cc1d5

Please sign in to comment.