Skip to content

Commit

Permalink
Add dummy "is rw" trait for Routines. Doesn't do anything yet, but
Browse files Browse the repository at this point in the history
allows us to properly future-proof code by adding "is rw" where it
will ultimately be needed.   Also mark many of the existing core
routines that are known to be "is rw".
  • Loading branch information
pmichaud committed May 29, 2011
1 parent 30809a2 commit b15c9ef
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 22 deletions.
32 changes: 16 additions & 16 deletions src/core/Any-list.pm
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ augment class Any {
fail('No values matched');
}

our multi method grep(Mu $test) {
our multi method grep(Mu $test) is rw {
gather {
for @.list {
take $_ if $_ ~~ $test;
Expand Down Expand Up @@ -285,25 +285,25 @@ augment class Any {
}
}

multi method values() {
multi method values() is rw {
gather for $.list -> $value {
take $value;
}
}

multi method pairs() {
multi method pairs() is rw {
self.kv.map(-> $key, $value { $key => $value; });
}

our multi method postcircumfix:<[ ]>() { self.list }
our multi method postcircumfix:<[ ]>() is rw { self.list }

our multi method postcircumfix:<[ ]>(Whatever $w) {
our multi method postcircumfix:<[ ]>(Whatever $w) is rw {
self[0..(self.elems-1)]
}

our multi method postcircumfix:<[ ]>(&block) { self[&block(|(self.elems xx &block.count))]; }
our multi method postcircumfix:<[ ]>(&block) is rw { self[&block(|(self.elems xx &block.count))]; }

our multi method postcircumfix:<[ ]>(@pos) {
our multi method postcircumfix:<[ ]>(@pos) is rw {
my $result = pir::new__ps('ResizablePMCArray');
for @pos {
pir::push($result, self[$_])
Expand All @@ -314,12 +314,12 @@ augment class Any {
}
}
our multi method postcircumfix:<[ ]>($pos) {
our multi method postcircumfix:<[ ]>($pos) is rw {
fail "Cannot use negative index $pos on {self.WHO}" if $pos < 0;
self.at_pos($pos)
}
method at_pos($pos) {
method at_pos($pos) is rw {
if self.defined {
fail ".[$pos] out of range for type {self.WHAT}" if $pos != 0;
return self;
Expand All @@ -331,15 +331,15 @@ augment class Any {
);
}
our multi method postcircumfix:<{ }>() {
our multi method postcircumfix:<{ }>() is rw {
self.values()
}
our multi method postcircumfix:<{ }>(Whatever $w) {
our multi method postcircumfix:<{ }>(Whatever $w) is rw {
self.{self.keys}
}
our multi method postcircumfix:<{ }>(@keys) {
our multi method postcircumfix:<{ }>(@keys) is rw {
my $result = pir::new__ps('ResizablePMCArray');
for @keys {
pir::push($result, self{$_})
Expand All @@ -350,9 +350,9 @@ augment class Any {
}
}
our multi method postcircumfix:<{ }>($key) { self.at_key($key) }
our multi method postcircumfix:<{ }>($key) is rw { self.at_key($key) }
method at_key($key) {
method at_key($key) is rw {
fail "postcircumfix:<\{ \}> not defined for type {self.WHAT}"
if self.defined;
my $z = Any!butWHENCE(
Expand All @@ -365,8 +365,8 @@ augment class Any {
# XXX Workarounds for Match objects which also ~~ Positional
# (http://irclog.perlgeek.de/perl6/2010-09-07#i_2795277)
# and RT #75868
our multi method postcircumfix:<[ ]>(Match $m) { self.[+$m] }
our multi method postcircumfix:<{ }>(Match $m) { self.{~$m} }
our multi method postcircumfix:<[ ]>(Match $m) is rw { self.[+$m] }
our multi method postcircumfix:<{ }>(Match $m) is rw { self.{~$m} }
method !butWHENCE(&by) {
pir::setprop__0PsP(pir::clone__PP(pir::descalarref__PP(self)), 'WHENCE', &by);
Expand Down
2 changes: 1 addition & 1 deletion src/core/Array.pm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
augment class Array {
method at_pos($pos) {
method at_pos($pos) is rw {
my $z = Any!butWHENCE(
{ pir::set__vQiP(self!fill($pos+1), $pos, $z) }
);
Expand Down
2 changes: 1 addition & 1 deletion src/core/Buf.pm
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ role Buf[::T = Int] does Stringy does Positional {
@.contents.elems;
}

multi method postcircumfix:<[ ]>($index) {
multi method postcircumfix:<[ ]>($index) is rw {
@.contents[$index];
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/Hash.pm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
role Hash is EnumMap {
method at_key($key) {
method at_key($key) is rw {
my $z = Any!butWHENCE(
{ pir::set__vQsP($!storage, $key, $z); }
);
Expand Down
6 changes: 3 additions & 3 deletions src/core/List.pm
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ augment class List does Positional {
self.map({ .fmt($format) }).join($separator);
}

multi method map(&block) {
multi method map(&block) is rw {
Q:PIR {
.local pmc self, mapiter, block
mapiter = new ['MapIter']
Expand All @@ -44,7 +44,7 @@ augment class List does Positional {
'(' ~ self.map({ $^a.perl }).join(', ') ~ ')';
}
method reverse() {
method reverse() is rw {
if self.elems ~~ Inf {
fail "Cannot reverse an infinite list"
}
Expand Down Expand Up @@ -144,7 +144,7 @@ augment class List does Positional {
!$tseq;
}

method at_pos($pos) {
method at_pos($pos) is rw {
Q:PIR {
.local pmc self, pos, items
self = find_lex 'self'
Expand Down
4 changes: 4 additions & 0 deletions src/core/traits.pm
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ our multi trait_mod:<is>(Routine $r, :$default!) {
$r does role { method default { True } }
}

our multi trait_mod:<is>(Routine $r, :$rw!) {
$r does role { method rw { True } }
}

our multi trait_mod:<hides>(Mu $child, Mu $parent) {
trait_mod:<is>($child, $parent);
$child.^hides.push($parent);
Expand Down

0 comments on commit b15c9ef

Please sign in to comment.