Skip to content

Commit

Permalink
Merge branch 'master' into lizmat-nano
Browse files Browse the repository at this point in the history
  • Loading branch information
lizmat committed Jul 15, 2022
2 parents 7efd928 + 7ec4b10 commit cba2801
Show file tree
Hide file tree
Showing 13 changed files with 140 additions and 10 deletions.
20 changes: 14 additions & 6 deletions src/core.c/Iterable.pm6
Expand Up @@ -30,13 +30,17 @@ my role Iterable {
}

method hyper(
Int(Cool) :$batch = 64,
Int(Cool) :$degree = Kernel.cpu-cores-but-one,
Int(Cool) :$batch,
Int(Cool) :$degree,
) {
#?if !js
HyperSeq.new:
configuration =>
HyperConfiguration.new(:$degree, :$batch, :method<hyper>),
HyperConfiguration.new(
:batch($batch // 64),
:degree($degree // Kernel.cpu-cores-but-one),
:method<hyper>
),
work-stage-head =>
Rakudo::Internals::HyperIteratorBatcher.new(:$.iterator)
#?endif
Expand All @@ -46,13 +50,17 @@ my role Iterable {
}

method race(
Int(Cool) :$batch = 64,
Int(Cool) :$degree = Kernel.cpu-cores-but-one,
Int(Cool) :$batch,
Int(Cool) :$degree,
) {
#?if !js
RaceSeq.new:
configuration =>
HyperConfiguration.new(:$degree, :$batch, :method<race>),
HyperConfiguration.new(
:batch($batch // 64),
:degree($degree // Kernel.cpu-cores-but-one),
:method<race>
),
work-stage-head =>
Rakudo::Internals::HyperIteratorBatcher.new(:$.iterator)
#?endif
Expand Down
4 changes: 4 additions & 0 deletions src/core.c/Str.pm6
Expand Up @@ -3898,6 +3898,10 @@ proto sub parse-base($, $, *%) {*}
multi sub parse-base(Str:D $str, Int:D $radix) { $str.parse-base($radix) }

proto sub substr($, $?, $?, *%) {*}
multi sub substr(str $s) { $s }
multi sub substr(str $s, int $f) { nqp::substr($s,$f) }
multi sub substr(str $s, int $f, int $c) { nqp::substr($s,$f,$c) }

multi sub substr(\what --> Str:D) { what.substr }
multi sub substr(\what, \from --> Str:D) { what.substr(from) }
multi sub substr(\what, \from, \chars --> Str:D) { what.substr(from,chars) }
Expand Down
18 changes: 18 additions & 0 deletions src/core.e/Any-iterable-methods.pm6
@@ -1,3 +1,16 @@
augment class Any {
proto method snip(|) {*}
multi method snip(Any:D: \condition) {
Seq.new: Rakudo::Iterator.Snip(condition, self.iterator)
}
multi method snip(Any:D: @conditions) {
Seq.new: Rakudo::Iterator.Snip(@conditions, self.iterator)
}
multi method snip(Any:D: *@conditions) {
Seq.new: Rakudo::Iterator.Snip(@conditions, self.iterator)
}
}

proto sub rotor(|) {*}
multi sub rotor(Int:D $batch, \thing, *%_) {
thing.rotor($batch, |%_)
Expand All @@ -7,3 +20,8 @@ multi sub rotor(**@cycle-and-thing, *%_) {
@cycle-and-thing.tail.rotor(@cycle-and-thing.head(*-1), |%_)
}

proto sub snip($, |) {*}
multi sub snip(\condition, +values) { values.snip(condition) }
multi sub snip(@conditions, +values) { values.snip(@conditions) }

# vim: expandtab shiftwidth=4
1 change: 0 additions & 1 deletion src/core.e/Int.pm6
@@ -1,4 +1,3 @@
use MONKEY;
augment class Int {
proto method roll(|) {*}
multi method roll() { nqp::rand_I(self,Int) }
Expand Down
59 changes: 59 additions & 0 deletions src/core.e/Rakudo/Iterator.pm6
@@ -0,0 +1,59 @@
augment class Rakudo::Iterator {
# Return an iterator that generates Lists of a given iterator
# and one or Callables with conditions. This is basically the
# Haskell "span" functionality.
my class Snip does Iterator {
has $!tests;
has $!iterator;
has $!next;

method !SET-SELF(@tests, $iterator) {
$!tests := nqp::getattr(@tests,List,'$!reified');
$!iterator := $iterator;
$!next := $iterator.pull-one;
self
}

method new(@tests, $iterator) {
nqp::create(self)!SET-SELF(@tests, $iterator)
}

method pull-one() {
if nqp::eqaddr($!next,IterationEnd) {
IterationEnd
}
else {
my $buffer := nqp::create(IterationBuffer);
nqp::push($buffer,$!next);

my $iterator := $!iterator;
my $pulled;

if nqp::elems($!tests) {
my $test := nqp::shift($!tests);
nqp::until(
nqp::eqaddr(($pulled := $iterator.pull-one),IterationEnd)
|| nqp::isfalse($test.ACCEPTS($pulled)),
nqp::push($buffer,$pulled)
);

}
else {
nqp::until(
nqp::eqaddr(($pulled := $iterator.pull-one),IterationEnd),
nqp::push($buffer,$pulled)
);
}

$!next := $pulled;
$buffer.List
}
}
}

proto method Snip(|) {*}
multi method Snip(\test, $iterator) { Snip.new: (test,), $iterator }
multi method Snip(@tests, $iterator) { Snip.new: @tests, $iterator }
}

# vim: expandtab shiftwidth=4
36 changes: 36 additions & 0 deletions src/core.e/Supply.pm6
@@ -0,0 +1,36 @@
augment class Supply {
proto method snip($, |) {*}
multi method snip(Supply:D: $test) {
self.snip( ($test,) )
}

multi method snip(Supply:D: @tests) {
my @left = @tests;
my $test := @left ?? @left.shift !! Nil;
my $buffer := nqp::create(IterationBuffer);
supply {
whenever self -> \val {
if nqp::eqaddr($test,Nil) {
nqp::push($buffer,val);
}
elsif $test.ACCEPTS(val) {
emit $buffer.List;
nqp::push(($buffer := nqp::create(IterationBuffer)),val);
$test := @left ?? @left.shift !! Nil;
}
else {
nqp::push($buffer,val);
}
LAST {
emit $buffer.List;
}
}
}
}

multi method snip(Supply:D: *@tests) {
self.snip(@tests)
}
}

# vim: expandtab shiftwidth=4
2 changes: 1 addition & 1 deletion src/core.e/core_prologue.pm6
@@ -1,4 +1,4 @@
use nqp;
use MONKEY;

# This constant must specify current CORE revision
# Must preceede class declarations to allow correct recording of their respective language version.
Expand Down
1 change: 1 addition & 0 deletions t/02-rakudo/03-corekeys-6e.t
Expand Up @@ -433,6 +433,7 @@ my @expected = (
Q{&sleep-until},
Q{&slip},
Q{&slurp},
Q{&snip},
Q{&so},
Q{&sort},
Q{&splice},
Expand Down
1 change: 1 addition & 0 deletions t/02-rakudo/03-corekeys.t
Expand Up @@ -802,6 +802,7 @@ my @allowed =
Q{&postcircumfix:<[; ]>},
Q{&postcircumfix:<{; }>},
Q{&rotor},
Q{&snip},
Q{&term:<nano>},
Q{CORE-SETTING-REV},
Q{Grammar},
Expand Down
1 change: 1 addition & 0 deletions t/02-rakudo/04-settingkeys-6e.t
Expand Up @@ -430,6 +430,7 @@ my %allowed = (
Q{&sleep-until},
Q{&slip},
Q{&slurp},
Q{&snip},
Q{&so},
Q{&sort},
Q{&splice},
Expand Down
2 changes: 1 addition & 1 deletion t/02-rakudo/07-implementation-detail-6.e.t
Expand Up @@ -30,7 +30,7 @@ my @lower = ("",<<
prompt push put rand redo reduce rename repeated repl return
return-rw reverse rotor rindex rmdir roll roots rotate round roundrobin
run samecase samemark samewith say sec sech set shell shift sign
signal sin sinh skip sleep sleep-timer sleep-until slip slurp so sort
signal sin sinh skip sleep sleep-timer sleep-until slip slurp snip so sort
splice split sprintf spurt sqrt squish srand subbuf-rw substr
substr-rw succeed sum symlink tail take take-rw tan tanh tc tclc trim
trim-leading trim-trailing truncate uc unimatch uniname
Expand Down
1 change: 1 addition & 0 deletions t/06-telemetry/01-basic.t
Expand Up @@ -25,6 +25,7 @@ my $T = T;
isa-ok $T, Telemetry, 'did we get a Telemetry object from T';
for <wallclock cpu max-rss> {
todo 'JVM gives zero for max-rss', 2 if $*VM.name eq 'jvm' and $_ eq 'max-rss';
todo 'Solaris gives zero for max-rss - see getrusage(3C)', 2 if $*VM.osname eq 'solaris';
ok $T{$_}, "did we get a non-zero value for $_ using AT-KEY";
ok $T."$_"(), "did we get a non-zero value for $_ with a method";
}
Expand Down
4 changes: 3 additions & 1 deletion tools/templates/6.e/core_sources
@@ -1,10 +1,12 @@
src/core.e/core_prologue.pm6
src/core.e/control.pm6
src/core.e/Any-iterable-methods.pm6
src/core.e/Supply.pm6
src/core.e/PseudoStash.pm6
src/core.e/Grammar.pm6
src/core.e/EXPORTHOW.pm6
src/core.e/Int.pm6
src/core.e/array_multislice.pm6
src/core.e/hash_multislice.pm6
src/core.e/Rakudo/Internals/Sprintf.pm6
src/core.e/Any-iterable-methods.pm6
src/core.e/Rakudo/Iterator.pm6

0 comments on commit cba2801

Please sign in to comment.