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 new(\iterables) { nqp::create(self)!SET-SELF(iterables) }
method pull-one() { method pull-one() {
nqp::if( nqp::if(
#?if jvm nqp::eqaddr($!next,IterationEnd),
nqp::eqaddr($!next,Mu),
#?endif
#?if !jvm
nqp::isnull($!next),
#?endif
IterationEnd, IterationEnd,
nqp::stmts( nqp::stmts(


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

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


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

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

0 comments on commit 00eb7b8

Please sign in to comment.