Skip to content

Commit

Permalink
Use same role detection logic for (non)-natives
Browse files Browse the repository at this point in the history
  • Loading branch information
lizmat committed Nov 28, 2016
1 parent 87dcc08 commit 4dffef7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
13 changes: 7 additions & 6 deletions src/core/ShapedNArray.pm
@@ -1,7 +1,7 @@
# this is actually part of the Array class

constant dim2type := nqp::list(Mu,Shaped1Array,Shaped2Array,Shaped3Array);
constant ArrayN := ShapedArray;
constant dim2role :=
nqp::list(ShapedArray,Shaped1Array,Shaped2Array,Shaped3Array);

sub set-shape(\base, \shape) is raw {
nqp::stmts(
Expand All @@ -11,17 +11,18 @@
shape.list
))),
nqp::if(
(my int $dimensions = $shape.elems), # reifies
(my int $dims = $shape.elems), # reifies
nqp::stmts(
nqp::unless(
nqp::iseq_i($dimensions,1)
nqp::iseq_i($dims,1)
&& nqp::istype( # ignore single [*] shape
nqp::atpos(nqp::getattr($shape,List,'$!reified'),0),
Whatever),
nqp::stmts(
(my $what := base.WHAT.^mixin(
nqp::ifnull(nqp::atpos(dim2type,$dimensions),ArrayN))),
nqp::if(
nqp::atpos(dim2role,nqp::isle_i($dims,3) && $dims))
),
nqp::if( # correct name if needed
nqp::isne_s($what.^name,base.^name),
$what.^set_name(base.^name)
),
Expand Down
4 changes: 2 additions & 2 deletions src/core/native_array.pm
Expand Up @@ -1776,7 +1776,7 @@ my class array does Iterable {
}

# poor man's 3x4 matrix
my $shaperole := nqp::list("",
constant typedim2role := nqp::list(nqp::null,
nqp::list(shapedintarray,shaped1intarray,shaped2intarray,shaped3intarray),
nqp::list(shapednumarray,shaped1numarray,shaped2numarray,shaped3numarray),
nqp::list(shapedstrarray,shaped1strarray,shaped2strarray,shaped3strarray)
Expand All @@ -1789,7 +1789,7 @@ my class array does Iterable {
# Calculate new meta-object (probably hitting caches in most cases).
(my \shaped-type = self.WHAT.^mixin(
nqp::atpos(
nqp::atpos($shaperole,nqp::objprimspec(my \T = self.of)),
nqp::atpos(typedim2role,nqp::objprimspec(my \T = self.of)),
nqp::isle_i($dims,3) && $dims
)
)),
Expand Down

0 comments on commit 4dffef7

Please sign in to comment.