Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'nom' of github.com:rakudo/rakudo into nom
  • Loading branch information
moritz committed Nov 7, 2013
2 parents 0faa636 + 4ce2bfa commit 9c888d2
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 33 deletions.
8 changes: 7 additions & 1 deletion src/core/Parcel.pm
Expand Up @@ -78,8 +78,14 @@ my class Parcel does Positional { # declared in BOOTSTRAP
else {
$perl = $perl ~ ',';
}
$perl ~ ')'
}
elsif nqp::iscont(SELF) {
$perl ~ ' )' # beause $() is about Matches...
}
else {
$perl ~ ')'
}
$perl ~ ')';
}

method STORE(|) {
Expand Down
89 changes: 59 additions & 30 deletions src/core/Str.pm
Expand Up @@ -678,45 +678,74 @@ my class Str does Stringy { # declared in BOOTSTRAP
}

multi method split(Str:D: Regex $pat, $limit = *, :$all) {
return ().list if $limit ~~ Numeric && $limit <= 0;
return ().list
if $limit ~~ Numeric && $limit <= 0;
my @matches = nqp::istype($limit, Whatever)
?? self.match($pat, :g)
!! self.match($pat, :x(1..$limit-1), :g);
gather {
my $prev-pos = 0;
for @matches {
take self.substr($prev-pos, .from - $prev-pos);
take $_ if $all;
?? self.match($pat, :g)
!! self.match($pat, :x(1..$limit-1), :g);

# add dummy for last
push @matches, Match.new( :from(self.chars) );
my $prev-pos = 0;

if ($all) {
my $elems = +@matches;
map {
my $value = self.substr($prev-pos, .from - $prev-pos);
$prev-pos = .to;
}
take self.substr($prev-pos);
# we don't want the dummy object
--$elems ?? ($value, $_) !! $value;
}, @matches;
}
else {
map {
my $value = self.substr($prev-pos, .from - $prev-pos);
$prev-pos = .to;
$value;
}, @matches;
}
}

multi method split(Str:D: Cool $delimiter, $limit = *, :$all) {
my $match-string = $delimiter.Str;
return if self eq '' && $delimiter eq '';

my $l = $limit ~~ Whatever ?? $Inf !! $limit;
return ().list if $l <= 0;
return (self).list if $l == 1;

my $c = 0;
my $l = $limit ~~ Whatever ?? $Inf !! $limit - 1;
return ().list if $l < 0;
if $l >= 0 {
gather {
while $l-- > 0 {
if ($match-string eq "") {
last unless $c + 1 < self.chars;
take self.substr($c, 1);
$c++;
} else {
my $m = self.index($match-string, $c);
last unless $m.defined;
take self.substr($c, $m - $c);
take $match-string if $all;
$c = $m + $match-string.chars;
}
my $done = 0;
if $match-string eq "" {
my $chars = self.chars;
map {
last if $done;

if --$chars and --$l {
self.substr($c++, 1);
}
take self.substr($c);
}
} else {
Nil;
else {
$done = 1;
self.substr($c);
}
}, 1 .. $l;
}
else {
my $width = $match-string.chars;
map {
last if $done;

my $m = self.index($match-string, $c);
if $m.defined and --$l {
my $value = self.substr($c, $m - $c);
$c = $m + $width;
$all ?? ($value,$match-string) !! $value;
}
else {
$done = 1;
self.substr($c);
}
}, 1 .. $l;
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/vm/jvm/core/Threading.pm
Expand Up @@ -58,11 +58,12 @@ my class Thread {
{
# This code is a little funky to avoid hitting jvmbootinterop at startup
# even if we never use anything that needs it. This is because it carries
# some cost and may have a bad interaction with the evalserver.
# some cost and has a very bad interaction with the evalserver.
my int $not_yet = 1;
my $init_thread;
PROCESS::<$THREAD> := Proxy.new(
FETCH => -> | {
unless nqp::isconcrete($init_thread) {
unless nqp::isconcrete($init_thread) || $not_yet {
my $interop := nqp::jvmbootinterop();
my \JVMThread := $interop.typeForName('java.lang.Thread');
$init_thread := nqp::create(Thread);
Expand All @@ -75,6 +76,7 @@ my class Thread {
STORE => -> | {
X::Assignment::RO.new.throw
});
$not_yet = 0;
}

# A simple, reentrant lock mechanism.
Expand Down

0 comments on commit 9c888d2

Please sign in to comment.