Skip to content

Commit

Permalink
Simplify some iterators
Browse files Browse the repository at this point in the history
  • Loading branch information
lizmat committed Nov 4, 2018
1 parent 316ad52 commit 00eb7b8
Showing 1 changed file with 20 additions and 157 deletions.
177 changes: 20 additions & 157 deletions src/core/Rakudo/Iterator.pm6
Expand Up @@ -904,12 +904,7 @@ class Rakudo::Iterator {
method new(\iterables) { nqp::create(self)!SET-SELF(iterables) }
method pull-one() {
nqp::if(
#?if jvm
nqp::eqaddr($!next,Mu),
#?endif
#?if !jvm
nqp::isnull($!next),
#?endif
nqp::eqaddr($!next,IterationEnd),
IterationEnd,
nqp::stmts(

Expand Down Expand Up @@ -1044,16 +1039,9 @@ class Rakudo::Iterator {
),
nqp::if(
nqp::iseq_i($level,-1),

# was last iteration, free up everything now
($!next :=
$!iterators := $!reifieds := $!indices :=
#?if jvm
Mu)
#?endif
#?if !jvm
nqp::null)
#?endif
($!next := $!iterators := $!reifieds := $!indices :=
IterationEnd)
)
)
),
Expand Down Expand Up @@ -1177,12 +1165,7 @@ class Rakudo::Iterator {
method new(\its,\map) { nqp::create(self)!SET-SELF(its,map) }
method pull-one() {
nqp::if(
#?if jvm
nqp::eqaddr($!next,Mu),
#?endif
#?if !jvm
nqp::isnull($!next),
#?endif
nqp::eqaddr($!next,IterationEnd),
IterationEnd,
nqp::stmts(

Expand Down Expand Up @@ -1319,16 +1302,9 @@ class Rakudo::Iterator {
),
nqp::if(
nqp::iseq_i($level,-1),

# was last iteration, free up everything now
($!next :=
$!iterators := $!reifieds := $!indices :=
#?if jvm
Mu)
#?endif
#?if !jvm
nqp::null)
#?endif
($!next := $!iterators := $!reifieds := $!indices :=
IterationEnd)
)
)
),
Expand Down Expand Up @@ -2391,56 +2367,32 @@ class Rakudo::Iterator {
}
method pull-one() is raw {
nqp::if(
#?if jvm
nqp::eqaddr($!value,IterationEnd),
#?endif
#?if !jvm
nqp::isnull($!value),
#?endif
IterationEnd,
nqp::stmts(
(my Mu $value := $!value),
#?if jvm
($!value := IterationEnd),
#?endif
#?if !jvm
($!value := nqp::null),
#?endif
$value
)
)
}
method push-all($target --> IterationEnd) {
nqp::stmts(
#?if jvm
nqp::unless(nqp::eqaddr($!value,IterationEnd),$target.push($!value)),
nqp::unless(
nqp::eqaddr($!value,IterationEnd),
$target.push($!value)
),
($!value := IterationEnd)
#?endif
#?if !jvm
nqp::unless(nqp::isnull($!value),$target.push($!value)),
($!value := nqp::null)
#?endif
)
}
method skip-one() {
nqp::if(
#?if jvm
nqp::not_i(nqp::eqaddr($!value,IterationEnd)),
nqp::isfalse($!value := IterationEnd)
#?endif
#?if !jvm
nqp::not_i(nqp::isnull($!value)),
nqp::isfalse($!value := nqp::null)
#?endif
)
}
method sink-all(--> IterationEnd) {
#?if jvm
$!value := IterationEnd
#?endif
#?if !jvm
$!value := nqp::null
#?endif
}
}
method OneValue(Mu \value) { OneValue.new(value) }
Expand Down Expand Up @@ -2884,12 +2836,7 @@ class Rakudo::Iterator {
method new(\iter) { nqp::create(self)!SET-SELF(iter) }
method pull-one() is raw {
nqp::if(
#?if jvm
nqp::eqaddr($!iterator,Mu),
#?endif
#?if !jvm
nqp::isnull($!iterator),
#?endif
nqp::eqaddr($!iterator,IterationEnd),
nqp::atpos( # supplying from cache
$!reified,
nqp::mod_i(
Expand All @@ -2905,12 +2852,7 @@ class Rakudo::Iterator {
nqp::if(
nqp::elems($!reified),
nqp::stmts( # exhausted, something in cache
#?if jvm
($!iterator := Mu),
#?endif
#?if !jvm
($!iterator := nqp::null),
#?endif
($!iterator := IterationEnd),
nqp::atpos($!reified,0)
),
IterationEnd # exhausted, nothing in cache
Expand Down Expand Up @@ -3190,12 +3132,7 @@ class Rakudo::Iterator {
method new(\iterables) { nqp::create(self)!SET-SELF(iterables) }
method pull-one() {
nqp::if(
#?if jvm
nqp::eqaddr($!iters,Mu),
#?endif
#?if !jvm
nqp::isnull($!iters),
#?endif
nqp::eqaddr($!iters,IterationEnd),
IterationEnd,
nqp::stmts(
(my int $i = -1),
Expand All @@ -3219,15 +3156,7 @@ class Rakudo::Iterator {
nqp::if(
nqp::elems($buf),
$buf.List,
nqp::stmts( # we're done
#?if jvm
($!iters := Mu),
#?endif
#?if !jvm
($!iters := nqp::null),
#?endif
IterationEnd
)
($!iters := IterationEnd), # we're done
)
)
)
Expand Down Expand Up @@ -3572,7 +3501,6 @@ class Rakudo::Iterator {
}
method pull-one() is raw {
nqp::if(
#?if jvm
nqp::eqaddr($!val1,IterationEnd),
nqp::if(
nqp::eqaddr($!val2,IterationEnd),
Expand All @@ -3586,29 +3514,12 @@ class Rakudo::Iterator {
nqp::stmts(
(my $val1 := $!val1),
($!val1 := IterationEnd),
#?endif
#?if !jvm
nqp::isnull($!val1),
nqp::if(
nqp::isnull($!val2),
IterationEnd,
nqp::stmts(
(my Mu $val2 := $!val2),
($!val2 := nqp::null),
$val2
)
),
nqp::stmts(
(my $val1 := $!val1),
($!val1 := nqp::null),
#?endif
$val1
)
)
}
method push-all($target --> IterationEnd) {
nqp::stmts(
#?if jvm
nqp::if(
nqp::eqaddr($!val1,IterationEnd),
nqp::unless(nqp::eqaddr($!val2,Mu),$target.push($!val2)),
Expand All @@ -3618,46 +3529,20 @@ class Rakudo::Iterator {
)
),
($!val1 := $!val2 := IterationEnd)
#?endif
#?if !jvm
nqp::if(
nqp::isnull($!val1),
nqp::unless(nqp::isnull($!val2),$target.push($!val2)),
nqp::stmts(
$target.push($!val1),
$target.push($!val2)
)
),
($!val1 := $!val2 := nqp::null)
#?endif
)
}
method skip-one() {
nqp::if(
#?if jvm
nqp::not_i(nqp::eqaddr($!val1,IterationEnd)),
nqp::isfalse($!val1 := IterationEnd),
nqp::if(
nqp::not_i(nqp::eqaddr($!val2,IterationEnd)),
nqp::isfalse($!val2 := IterationEnd)
#?endif
#?if !jvm
nqp::not_i(nqp::isnull($!val1)),
nqp::isfalse($!val1 := nqp::null),
nqp::if(
nqp::not_i(nqp::isnull($!val2)),
nqp::isfalse($!val2 := nqp::null)
#?endif
)
)
}
method sink-all(--> IterationEnd) {
#?if jvm
$!val1 := $!val2 := IterationEnd
#?endif
#?if !jvm
$!val1 := $!val2 := nqp::null
#?endif
}
}
method TwoValues(Mu \val1, Mu \val2) { TwoValues.new(val1, val2) }
Expand Down Expand Up @@ -4014,12 +3899,7 @@ class Rakudo::Iterator {
method new(\iterables) { nqp::create(self)!SET-SELF(iterables) }
method pull-one() {
nqp::if(
#?if jvm
nqp::eqaddr($!iters,Mu),
#?endif
#?if !jvm
nqp::isnull($!iters),
#?endif
nqp::eqaddr($!iters,IterationEnd),
IterationEnd,
nqp::stmts(
(my int $i = -1),
Expand All @@ -4039,12 +3919,7 @@ class Rakudo::Iterator {
nqp::if(
$is_iterend, # at least one exhausted
nqp::stmts(
#?if jvm
($!iters := Mu),
#?endif
#?if !jvm
($!iters := nqp::null),
#?endif
($!iters := IterationEnd),
IterationEnd
),
buf.List
Expand Down Expand Up @@ -4102,12 +3977,7 @@ class Rakudo::Iterator {
method new(\iters,\map) { nqp::create(self)!SET-SELF(iters,map) }
method pull-one() {
nqp::if(
#?if jvm
nqp::eqaddr($!iters,Mu),
#?endif
#?if !jvm
nqp::isnull($!iters),
#?endif
nqp::eqaddr($!iters,IterationEnd),
IterationEnd,
nqp::stmts(
(my int $i = -1),
Expand All @@ -4119,23 +3989,16 @@ class Rakudo::Iterator {
nqp::islt_i(($i = nqp::add_i($i,1)),$elems),
nqp::if(
nqp::eqaddr(
(my \pulled := nqp::atpos($!iters,$i).pull-one), IterationEnd
(my \pulled := nqp::atpos($!iters,$i).pull-one),
IterationEnd
),
$is_iterend = 1,
nqp::bindpos($list,$i,pulled)
)
),
nqp::if(
$is_iterend, # at least one exhausted
nqp::stmts(
#?if jvm
($!iters := Mu),
#?endif
#?if !jvm
($!iters := nqp::null),
#?endif
IterationEnd
),
($!iters := IterationEnd),
$!mapper($list)
)
)
Expand Down

0 comments on commit 00eb7b8

Please sign in to comment.