Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'nom' into longlit
  • Loading branch information
TimToady committed Nov 17, 2014
2 parents ef6924e + 38e77b6 commit 4d80624
Show file tree
Hide file tree
Showing 38 changed files with 180 additions and 147 deletions.
2 changes: 1 addition & 1 deletion src/core/AST.pm
Expand Up @@ -24,7 +24,7 @@ my class AST {
got => $_,
expected => AST,
action => 'unquote evaluation',
).throw unless $_ ~~ AST;
).throw unless nqp::istype($_,AST);
nqp::push($pasts, nqp::getattr(nqp::decont($_), AST, '$!past'))
}
$!past.evaluate_unquotes($pasts);
Expand Down
80 changes: 58 additions & 22 deletions src/core/Any.pm
Expand Up @@ -119,18 +119,18 @@ my class Any { # declared in BOOTSTRAP
proto method tree(|) { * }
multi method tree(Any:U:) { self }
multi method tree(Any:D:) {
self ~~ Positional
nqp::istype(self,Positional)
?? LoL.new(|MapIter.new(self.list, { .tree }, Mu).list).item
!! self
}
multi method tree(Any:D: Whatever ) { self.tree }
multi method tree(Any:D: Cool $count as Int) {
self ~~ Positional && $count > 0
nqp::istype(self,Positional) && $count > 0
?? LoL.new(|MapIter.new(self.list, { .tree($count - 1) }, Mu).list).item
!! self
}
multi method tree(Any:D: *@ [&first, *@rest]) {
self ~~ Positional
nqp::istype(self,Positional)
?? @rest ?? first MapIter.new(self.list, { .tree(|@rest) }, Mu).list
!! first self.list
!! self
Expand All @@ -141,7 +141,7 @@ my class Any { # declared in BOOTSTRAP
# auto-vivifying
proto method push(|) { * }
multi method push(Any:U \SELF: *@values) {
SELF = SELF ~~ Positional ?? SELF.new !! Array.new;
SELF = nqp::istype(SELF,Positional) ?? SELF.new !! Array.new;
SELF.push(@values);
}

Expand Down Expand Up @@ -170,16 +170,25 @@ my class Any { # declared in BOOTSTRAP
fail X::Match::Bool.new( type => '.grep-index' );
}
multi method grep-index(Regex:D $test) {
my $index = -1;
self.map: { $index++; +$index if .match($test) };
my int $index = -1;
self.map: {
$index = $index+1;
nqp::box_i($index,Int) if .match($test);
};
}
multi method grep-index(Callable:D $test) {
my $index = -1;
self.map: { $index++; +$index if $test($_) };
my int $index = -1;
self.map: {
$index = $index + 1;
nqp::box_i($index,Int) if $test($_);
};
}
multi method grep-index(Mu $test) {
my $index = -1;
self.map: { $index++; +$index if $_ ~~ $test };
my int $index = -1;
self.map: {
$index = $index + 1;
nqp::box_i($index,Int) if $_ ~~ $test;
};
}

proto method first(|) { * }
Expand All @@ -204,18 +213,27 @@ my class Any { # declared in BOOTSTRAP
fail X::Match::Bool.new( type => '.first-index' );
}
multi method first-index(Regex:D $test) {
my $index = -1;
self.map: { $index++; return $index if .match($test) };
my int $index = -1;
self.map: {
$index = $index + 1;
return nqp::box_i($index,Int) if .match($test);
};
Nil;
}
multi method first-index(Callable:D $test) {
my $index = -1;
self.map: { $index++; return $index if $test($_) };
my int $index = -1;
self.map: {
$index = $index + 1;
return nqp::box_i($index,Int) if $test($_);
};
Nil;
}
multi method first-index(Mu $test) {
my $index = -1;
self.map: { $index++; return $index if $_ ~~ $test };
my int $index = -1;
self.map: {
$index = $index + 1;
return nqp::box_i($index,Int) if $_ ~~ $test;
};
Nil;
}

Expand All @@ -224,18 +242,36 @@ my class Any { # declared in BOOTSTRAP
fail X::Match::Bool.new( type => '.last-index' );
}
multi method last-index(Regex:D $test) {
my $index = self.elems;
self.reverse.map: { $index--; return $index if .match($test) };
my $elems = self.elems;
return Inf if $elems == Inf;

my int $index = $elems;
while $index {
$index = $index - 1;
return nqp::box_i($index,Int) if self.at_pos($index).match($test);
}
Nil;
}
multi method last-index(Callable:D $test) {
my $index = self.elems;
self.reverse.map: { $index--; return $index if $test($_) };
my $elems = self.elems;
return Inf if $elems == Inf;

my int $index = $elems;
while $index {
$index = $index - 1;
return nqp::box_i($index,Int) if $test(self.at_pos($index));
}
Nil;
}
multi method last-index(Mu $test) {
my $index = self.elems;
self.reverse.map: { $index--; return $index if $_ ~~ $test };
my $elems = self.elems;
return Inf if $elems == Inf;

my int $index = $elems;
while $index {
$index = $index - 1;
return nqp::box_i($index,Int) if self.at_pos($index) ~~ $test;
}
Nil;
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/Array.pm
Expand Up @@ -132,7 +132,7 @@ class Array { # declared in BOOTSTRAP
multi method perl(Array:D \SELF:) {
nqp::iscont(SELF)
?? '[' ~ ( # simplify arrays that look 2D (in first 3 elems anyway)
self[0] ~~ Parcel || self[1] ~~ Parcel || self[2] ~~ Parcel
nqp::istype(self[0],Parcel) || nqp::istype(self[1],Parcel) || nqp::istype(self[2],Parcel)
?? self.map({.list.map({.perl}).join(', ')}).join('; ')
!! self.map({.perl}).join(', ')
) ~ ']'
Expand Down
2 changes: 1 addition & 1 deletion src/core/Backtrace.pm
Expand Up @@ -24,7 +24,7 @@ my class Backtrace::Frame {
}

method is-hidden(Backtrace::Frame:D:) { $!code.?is_hidden_from_backtrace }
method is-routine(Backtrace::Frame:D:) { $!code ~~ Routine }
method is-routine(Backtrace::Frame:D:) { nqp::istype($!code,Routine) }
method is-setting(Backtrace::Frame:D:) {
$!file.chars > 12 && $!file.substr(*-12) eq 'CORE.setting'
}
Expand Down
16 changes: 9 additions & 7 deletions src/core/Baggy.pm
Expand Up @@ -77,7 +77,7 @@ my role Baggy does QuantHash {
%!elems.delete_key(%!elems.keys.pick);
}
multi method grabpairs(Baggy:D: $count) {
if $count ~~ Whatever || $count == Inf {
if nqp::istype($count,Whatever) || $count == Inf {
my @grabbed = %!elems{%!elems.keys.pick(%!elems.elems)};
%!elems = ();
@grabbed;
Expand All @@ -93,7 +93,9 @@ my role Baggy does QuantHash {
}
multi method pickpairs(Baggy:D: $count) {
%!elems{ %!elems.keys.pick(
$count ~~ Whatever || $count == Inf ?? %!elems.elems !! $count
nqp::istype($count,Whatever) || $count == Inf
?? %!elems.elems
!! $count
) };
}

Expand All @@ -105,7 +107,7 @@ my role Baggy does QuantHash {
grabbed;
}
multi method grab(Baggy:D: $count) {
if $count ~~ Whatever || $count == Inf {
if nqp::istype($count,Whatever) || $count == Inf {
my @grabbed = ROLLPICKGRABN(self,self.total,%!elems.values);
%!elems = ();
@grabbed;
Expand All @@ -127,7 +129,7 @@ my role Baggy does QuantHash {
}
multi method pick(Baggy:D: $count) {
ROLLPICKGRABN(self,
$count ~~ Whatever || $count == Inf ?? self.total !! $count,
nqp::istype($count,Whatever) || $count == Inf ?? self.total !! $count,
%!elems.values.map: { (.key => .value) }
);
}
Expand All @@ -137,7 +139,7 @@ my role Baggy does QuantHash {
ROLLPICKGRAB1(self,%!elems.values);
}
multi method roll(Baggy:D: $count) {
$count ~~ Whatever || $count == Inf
nqp::istype($count,Whatever) || $count == Inf
?? ROLLPICKGRABW(self,%!elems.values)
!! ROLLPICKGRABN(self,$count, %!elems.values, :keep);
}
Expand Down Expand Up @@ -231,7 +233,7 @@ my role Baggy does QuantHash {
if @list {

# multi-level classify
if test(@list[0]) ~~ List {
if nqp::istype(test(@list[0]),List) {
for @list -> $l {
my @keys = test($l);
my $last := @keys.pop;
Expand Down Expand Up @@ -261,7 +263,7 @@ my role Baggy does QuantHash {
if @list {

# multi-level categorize
if test(@list[0])[0] ~~ List {
if nqp::istype(test(@list[0])[0],List) {
for @list -> $l {
for test($l) -> $k {
my @keys = @($k);
Expand Down
8 changes: 4 additions & 4 deletions src/core/Bool.pm
Expand Up @@ -47,12 +47,12 @@ multi prefix:<so>(Bool:D \a) { a }
multi prefix:<so>(Mu \a) { a.Bool }

proto prefix:<!>(Mu $) is pure { * }
multi prefix:<!>(Bool \a) { nqp::p6bool(a ?? 0 !! 1) }
multi prefix:<!>(Mu \a) { nqp::p6bool(a.Bool ?? 0 !! 1) }
multi prefix:<!>(Bool \a) { nqp::p6bool(nqp::not_i(nqp::istrue(a))) }
multi prefix:<!>(Mu \a) { nqp::p6bool(nqp::not_i(nqp::istrue(a))) }

proto prefix:<not>(Mu $) is pure { * }
multi prefix:<not>(Bool \a) { nqp::p6bool(a ?? 0 !! 1) }
multi prefix:<not>(Mu \a) { nqp::p6bool(a.Bool ?? 0 !! 1) }
multi prefix:<not>(Bool \a) { nqp::p6bool(nqp::not_i(nqp::istrue(a))) }
multi prefix:<not>(Mu \a) { nqp::p6bool(nqp::not_i(nqp::istrue(a))) }

proto prefix:<?^>(Mu $) is pure { * }
multi prefix:<?^>(Mu \a) { not a }
Expand Down
2 changes: 1 addition & 1 deletion src/core/Buf.pm
Expand Up @@ -284,7 +284,7 @@ multi sub pack(Str $template, *@items) {
}
when 'a' {
my $data = shift @items // Buf.new;
$data.=encode if $data ~~ Str;
$data.=encode if nqp::istype($data,Str);
if $amount eq '*' {
$amount = +@$data;
}
Expand Down
8 changes: 4 additions & 4 deletions src/core/CompUnitRepo.pm
Expand Up @@ -7,7 +7,7 @@ class CompUnitRepo {

method files($file, :$name, :$auth, :$ver) {
for @*INC {
if $_ ~~ Str ?? CompUnitRepo::Local::File.new($_) !! $_ -> $cur {
if nqp::istype($_,Str) ?? CompUnitRepo::Local::File.new($_) !! $_ -> $cur {
if $cur.files($name, :$file,:$auth,:$ver).list -> @candi {
return @candi;
}
Expand All @@ -18,7 +18,7 @@ class CompUnitRepo {

method candidates($name, :$file, :$auth, :$ver) {
for @*INC {
if $_ ~~ Str ?? CompUnitRepo::Local::File.new($_) !! $_ -> $cur {
if nqp::istype($_,Str) ?? CompUnitRepo::Local::File.new($_) !! $_ -> $cur {
if $cur.candidates($name, :$file,:$auth,:$ver).list -> @candi {
return @candi;
}
Expand Down Expand Up @@ -87,11 +87,11 @@ class CompUnitRepo {
}

# still don't have a type object
if $class ~~ Str {
if nqp::istype($class,Str) {
my $type = ::($class);

# alas, no a known class
if $type ~~ Failure {
if nqp::istype($type,Failure) {

# it's a short-id
if %id2class.exists_key($class) {
Expand Down
4 changes: 2 additions & 2 deletions src/core/CompUnitRepo/Local/Installation.pm
Expand Up @@ -139,7 +139,7 @@ sub MAIN(:$name, :$auth, :$ver, *@pos, *%named) {
for %!dists.kv -> $path, $repo {
for @($repo<dists>) -> $dist {
my $dver = $dist<ver>
?? $dist<ver> ~~ Version
?? nqp::istype($dist<ver>,Version)
?? $dist<ver>
!! Version.new( $dist<ver> )
!! Version.new('0');
Expand All @@ -164,7 +164,7 @@ sub MAIN(:$name, :$auth, :$ver, *@pos, *%named) {
for %!dists.kv -> $path, $repo {
for @($repo<dists>) -> $dist {
my $dver = $dist<ver>
?? $dist<ver> ~~ Version
?? nqp::istype($dist<ver>,Version)
?? $dist<ver>
!! Version.new( ~$dist<ver> )
!! Version.new('0');
Expand Down
16 changes: 9 additions & 7 deletions src/core/Cursor.pm
Expand Up @@ -161,7 +161,7 @@ my class Cursor does NQPCursorRole {
method INTERPOLATE(\var, $i = 0, $s = 0, $a = 0) {
if nqp::isconcrete(var) {
# Call it if it is a routine. This will capture if requested.
return (var)(self) if var ~~ Callable;
return (var)(self) if nqp::istype(var,Callable);
my $maxlen := -1;
my $cur := self.'!cursor_start_cur'();
my $pos := nqp::getattr_i($cur, $?CLASS, '$!from');
Expand All @@ -186,12 +186,13 @@ my class Cursor does NQPCursorRole {
if $a {
# We are in a regex assertion, the strings we get will be treated as
# regex rules.
return $cur.'!cursor_start_cur'() if $topic ~~ Associative;
return $cur.'!cursor_start_cur'()
if nqp::istype($topic,Associative);
my $rx := MAKE_REGEX($topic, :$i);
my Mu $nfas := nqp::findmethod($rx, 'NFA')($rx);
$nfa.mergesubstates($start, 0, $fate, $nfas, Mu);
}
elsif $topic ~~ Regex {
elsif nqp::istype($topic,Regex) {
# A Regex already.
my Mu $nfas := nqp::findmethod($topic, 'NFA')($topic);
$nfa.mergesubstates($start, 0, $fate, $nfas, Mu);
Expand Down Expand Up @@ -233,12 +234,13 @@ my class Cursor does NQPCursorRole {
if $a {
# We are in a regex assertion, the strings we get will be treated as
# regex rules.
return $cur.'!cursor_start_cur'() if $topic ~~ Associative;
return $cur.'!cursor_start_cur'()
if nqp::istype($topic,Associative);
my $rx := MAKE_REGEX($topic, :$i);
$match := (nqp::substr($tgt, $pos, $eos - $pos) ~~ $rx).Str;
$len := nqp::chars( $match );
}
elsif $topic ~~ Regex {
elsif nqp::istype($topic,Regex) {
# A Regex already.
$match := nqp::substr($tgt, $pos, $eos - $pos) ~~ $topic;

Expand Down Expand Up @@ -272,7 +274,7 @@ my class Cursor does NQPCursorRole {
}

method DYNQUANT_LIMITS($mm) {
if $mm ~~ Range {
if nqp::istype($mm,Range) {
die 'Range minimum in quantifier (**) cannot be +Inf' if $mm.min == Inf;
die 'Range maximum in quantifier (**) cannot be -Inf' if $mm.max == -Inf;
nqp::list_i($mm.min < 0 ?? 0 !! $mm.min.Int, $mm.max == Inf ?? -1 !! $mm.max.Int)
Expand Down Expand Up @@ -301,7 +303,7 @@ sub MAKE_REGEX($arg, :$i) {
my role CachedCompiledRegex {
has $.regex;
}
if $arg ~~ Regex {
if nqp::istype($arg,Regex) {
$arg
}
elsif nqp::istype($arg, CachedCompiledRegex) {
Expand Down
2 changes: 1 addition & 1 deletion src/core/Enum.pm
Expand Up @@ -29,7 +29,7 @@ my class Enum does Associative {
multi method Str(Enum:D:) { $.key ~ "\t" ~ $.value }

multi method perl(Enum:D:) {
if $.key ~~ Enum {
if nqp::istype($.key,Enum) {
'(' ~ $.key.perl ~ ') => ' ~ $.value.perl;
} else {
$.key.perl ~ ' => ' ~ $.value.perl;
Expand Down
3 changes: 0 additions & 3 deletions src/core/Grammar.pm
Expand Up @@ -15,9 +15,6 @@ my class Grammar is Cursor {
my $match := self.parse($filename.IO.slurp, |%opts);
nqp::getlexcaller('$/') = $match;
}

method wemusthavethishereotherwiserakudowontcompile { }

}

# vim: ft=perl6 expandtab sw=4

0 comments on commit 4d80624

Please sign in to comment.