Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Postpone introduction of Pos until after release
  • Loading branch information
lizmat committed Jul 24, 2015
1 parent 7a15752 commit e12548c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 23 deletions.
19 changes: 9 additions & 10 deletions src/core/Any.pm
@@ -1,6 +1,5 @@
my class MapIter { ... }
my class Pair { ... }
my class Pos { ... }
my class Range { ... }
my class X::Adverb::Slice { ... }
my class X::Bind { ... }
Expand Down Expand Up @@ -297,23 +296,23 @@ my class Any { # declared in BOOTSTRAP
self.map: {
$index = $index+1;
next unless .match($test);
nqp::box_i($index,Pos);
nqp::box_i($index,Int);
};
}
multi method grep-index(Callable:D $test) {
my int $index = -1;
self.map: {
$index = $index + 1;
next unless $test($_);
nqp::box_i($index,Pos);
nqp::box_i($index,Int);
};
}
multi method grep-index(Mu $test) {
my int $index = -1;
self.map: {
$index = $index + 1;
next unless $_ ~~ $test;
nqp::box_i($index,Pos);
nqp::box_i($index,Int);
};
}

Expand Down Expand Up @@ -342,23 +341,23 @@ my class Any { # declared in BOOTSTRAP
my int $index = -1;
self.map: {
$index = $index + 1;
return nqp::box_i($index,Pos) if .match($test);
return nqp::box_i($index,Int) if .match($test);
};
Nil;
}
multi method first-index(Callable:D $test) {
my int $index = -1;
self.map: {
$index = $index + 1;
return nqp::box_i($index,Pos) if $test($_);
return nqp::box_i($index,Int) if $test($_);
};
Nil;
}
multi method first-index(Mu $test) {
my int $index = -1;
self.map: {
$index = $index + 1;
return nqp::box_i($index,Pos) if $_ ~~ $test;
return nqp::box_i($index,Int) if $_ ~~ $test;
};
Nil;
}
Expand All @@ -374,7 +373,7 @@ my class Any { # declared in BOOTSTRAP
my int $index = $elems;
while $index {
$index = $index - 1;
return nqp::box_i($index,Pos) if self.AT-POS($index).match($test);
return nqp::box_i($index,Int) if self.AT-POS($index).match($test);
}
Nil;
}
Expand All @@ -385,7 +384,7 @@ my class Any { # declared in BOOTSTRAP
my int $index = $elems;
while $index {
$index = $index - 1;
return nqp::box_i($index,Pos) if $test(self.AT-POS($index));
return nqp::box_i($index,Int) if $test(self.AT-POS($index));
}
Nil;
}
Expand All @@ -396,7 +395,7 @@ my class Any { # declared in BOOTSTRAP
my int $index = $elems;
while $index {
$index = $index - 1;
return nqp::box_i($index,Pos) if self.AT-POS($index) ~~ $test;
return nqp::box_i($index,Int) if self.AT-POS($index) ~~ $test;
}
Nil;
}
Expand Down
26 changes: 15 additions & 11 deletions src/core/Cool.pm
Expand Up @@ -190,22 +190,26 @@ my class Cool { # declared in BOOTSTRAP
nqp::unbox_s($needle.Str),
nqp::unbox_i($pos.Int)
);
$result < 0 ?? Pos !! nqp::box_i($result,Pos);
# TODO: fail() instead of returning Int
$result < 0 ?? Int !! nqp::p6box_i($result);
}

proto method rindex(|) {*}
multi method rindex(Cool $needle, Cool $pos?) {
my $result = $pos.defined
?? nqp::rindex(
nqp::unbox_s(self.Str),
nqp::unbox_s($needle.Str),
nqp::unbox_i($pos.Int)
)
!! nqp::rindex(
nqp::unbox_s(self.Str),
nqp::unbox_s($needle.Str),
);
$result < 0 ?? Pos !! nqp::box_i($result,Pos);
?? nqp::p6box_i(
nqp::rindex(
nqp::unbox_s(self.Str),
nqp::unbox_s($needle.Str),
nqp::unbox_i($pos.Int)
))
!! nqp::p6box_i(
nqp::rindex(
nqp::unbox_s(self.Str),
nqp::unbox_s($needle.Str),
));
fail "substring not found" if $result < 0;
$result;
}

proto method split(|) {*}
Expand Down
2 changes: 0 additions & 2 deletions src/core/Int.pm
Expand Up @@ -162,8 +162,6 @@ my class Int does Real { # declared in BOOTSTRAP
}
}

my class Pos is Int { multi method Bool(Pos:) { self.defined } }

multi sub prefix:<++>(Int:D $a is rw) {
$a = nqp::add_I(nqp::decont($a), 1, Int);
}
Expand Down

0 comments on commit e12548c

Please sign in to comment.