Skip to content
Permalink
Browse files

Simplify some iterators

  • Loading branch information...
lizmat committed Nov 4, 2018
1 parent 316ad52 commit 00eb7b856129e5c481c9adeae8cadbafcced24dc
Showing with 20 additions and 157 deletions.
  1. +20 −157 src/core/Rakudo/Iterator.pm6
@@ -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(


@@ -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
) )
) )
), ),
@@ -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(


@@ -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
) )
) )
), ),
@@ -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) }
@@ -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(
@@ -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
@@ -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),
@@ -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
)
) )
) )
) )
@@ -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),
@@ -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)),
@@ -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) }
@@ -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),
@@ -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
@@ -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),
@@ -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)
) )
) )

0 comments on commit 00eb7b8

Please sign in to comment.
You can’t perform that action at this time.