Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Allow rotate/reverse of 1-dim fixed arrays.
Or at least, do so for non-native arrays. We didn't yet implement the
two operations at all on native arrays yet.
  • Loading branch information
jnthn committed Dec 13, 2015
1 parent c086506 commit ba273ef
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
16 changes: 14 additions & 2 deletions src/core/Array.pm
Expand Up @@ -252,6 +252,18 @@ my class Array { # declared in BOOTSTRAP
self.STORE((item,))
}

method reverse(::?CLASS:D:) {
self.shape.elems == 1
?? self.new(:shape(self.shape), self.List.reverse())
!! X::IllegalOnFixedDimensionArray.new(operation => 'reverse').throw
}

method rotate(::?CLASS:D: Cool \n) {
self.shape.elems == 1
?? self.new(:shape(self.shape), self.List.rotate(n))
!! X::IllegalOnFixedDimensionArray.new(operation => 'rotate').throw
}

# A shaped array isn't lazy, we these methods don't need to go looking
# into the "todo".
multi method elems(::?CLASS:D:) is nodal {
Expand All @@ -278,7 +290,7 @@ my class Array { # declared in BOOTSTRAP
arr does ShapedArray[Mu];
arr.^set_name('Array');
nqp::bindattr(arr, arr.WHAT, '$!shape', list-shape);
die "Creating shaped array with initial values NYI" if values;
arr.STORE(values) if values;
}
else {
arr.STORE(values);
Expand Down Expand Up @@ -738,13 +750,13 @@ my class Array { # declared in BOOTSTRAP
arr does ShapedArray[Mu];
arr.^set_name('Array');
nqp::bindattr(arr, arr.WHAT, '$!shape', list-shape);
die "Creating shaped array with initial values NYI" if values;
nqp::bindattr(
arr,
Array,
'$!descriptor',
Perl6::Metamodel::ContainerDescriptor.new(:of(TValue), :rw(1))
);
arr.STORE(values) if values;
} else {
nqp::bindattr(
arr,
Expand Down
8 changes: 0 additions & 8 deletions src/core/Rakudo/Internals.pm
Expand Up @@ -393,14 +393,6 @@ my class Rakudo::Internals {
X::IllegalOnFixedDimensionArray.new(operation => 'plan').throw
}

method reverse(::?CLASS:D:) {
X::IllegalOnFixedDimensionArray.new(operation => 'reverse').throw
}

method rotate(::?CLASS:D: Cool) {
X::IllegalOnFixedDimensionArray.new(operation => 'rotate').throw
}

multi method keys(::?CLASS:D:) {
my @shape := self.shape;
@shape.elems == 1
Expand Down
8 changes: 8 additions & 0 deletions src/core/native_array.pm
Expand Up @@ -472,6 +472,14 @@ my class array does Iterable is repr('VMArray') {
multi method STORE(::?CLASS:D: Mu \item) {
self.STORE((item,))
}

method reverse(::?CLASS:D:) {
X::IllegalOnFixedDimensionArray.new(operation => 'reverse').throw
}

method rotate(::?CLASS:D: Cool) {
X::IllegalOnFixedDimensionArray.new(operation => 'rotate').throw
}
}

role shapedintarray[::T] does shapedarray {
Expand Down

0 comments on commit ba273ef

Please sign in to comment.