Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
use native types in the setting a bit more
  • Loading branch information
moritz committed Oct 5, 2011
1 parent 2146e92 commit 5b40d01
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 17 deletions.
6 changes: 3 additions & 3 deletions src/core/IO.pm
Expand Up @@ -218,10 +218,10 @@ multi sub cwd() {

sub dir($path = '.', Mu :$test = none('.', '..')) {
my Mu $RSA := pir::new__PS('OS').readdir(nqp::unbox_s($path.Stringy));
my Int $elems := nqp::p6box_i(pir::set__IP($RSA));
my int $elems = pir::set__IP($RSA);
my @res;
loop (my Int $i = 0; $i < $elems; $i++) {
my Str $item := nqp::p6box_s(nqp::atpos($RSA, nqp::unbox_i($i)));
loop (my int $i = 0; $i < $elems; $i = $i + 1) {
my Str $item := nqp::p6box_s(nqp::atpos($RSA, $i));
@res.push: $item if $test.ACCEPTS($item);
}
@res;
Expand Down
6 changes: 3 additions & 3 deletions src/core/Int.pm
Expand Up @@ -39,16 +39,16 @@ my class Int {

method base(Cool $base) {
fail("base must be between 2 and 36, got $base") unless 2 <= $base <= 36;
my Int $b = $base.Int;
my int $b = $base.Int;
my @conversion = qw/0 1 2 3 4 5 6 7 8 9
A B C D E F G H I J
K L M N O P Q R S T
U V W X Y Z/;
my @res;
my $n = self.abs;
my int $n = self.abs;
repeat {
push @res, @conversion[$n % $b];
$n div= $b;
$n = $n div $b;
} while $n > 0;
push @res, '-' if self < 0;
join '', @res.reverse;
Expand Down
14 changes: 8 additions & 6 deletions src/core/Mu.pm
Expand Up @@ -162,13 +162,14 @@ my class Mu {
}
multi method isa(Str:D $name) {
my @mro = self.HOW.mro(self);
my $i = 0;
while $i < +@mro {
my int $mro_count = +@mro;
my int $i = 0;
while $i < $mro_count {
my $obj = @mro[$i];
if $obj.HOW.name($obj) eq $name {
return Bool::True;
}
$i++;
$i = $i + 1;
}
Bool::False
}
Expand Down Expand Up @@ -247,9 +248,10 @@ my class Mu {

method dispatch:<.*>($name, *@pos, *%named) {
my @mro = self.HOW.mro(self);
my int $mro_count = +@mro;
my @results;
my $i = 0;
while $i < +@mro {
my int $i = 0;
while $i < $mro_count {
my $obj = @mro[$i];
my $meth = ($obj.HOW.method_table($obj)){$name};
if !$meth && $i == 0 {
Expand All @@ -258,7 +260,7 @@ my class Mu {
if $meth {
@results.push($meth(self, |@pos, |%named));
}
$i++;
$i = $i + 1;
}
&infix:<,>(|@results)
}
Expand Down
10 changes: 5 additions & 5 deletions src/core/Str.pm
Expand Up @@ -14,14 +14,14 @@ my class Str does Stringy {
multi method ACCEPTS(Str:D: $other) { $other eq self }

method chomp(Str:D:) {
my Int $chars = self.chars;
my int $chars = self.chars;
return '' if $chars == 0;
my Str $last = nqp::p6box_s(nqp::substr(nqp::unbox_s(self), nqp::unbox_i($chars - 1)));
my Int $to_remove = 0;
my str $last = nqp::substr(nqp::unbox_s(self), $chars - 1);
my int $to_remove = 0;
$to_remove = 1 if $last eq "\n" || $last eq "\r";
$to_remove = 2 if $chars > 1
&& nqp::p6box_s(nqp::substr(nqp::unbox_s(self), nqp::unbox_i($chars - 2))) eq "\r\n";
nqp::p6box_s(pir::chopn__Ssi(nqp::unbox_s(self),nqp::unbox_i($to_remove)))
&& nqp::p6box_s(nqp::substr(nqp::unbox_s(self), $chars - 2)) eq "\r\n";
nqp::p6box_s(pir::chopn__Ssi(nqp::unbox_s(self), $to_remove))
}

method chop(Str:D:) {
Expand Down

0 comments on commit 5b40d01

Please sign in to comment.