1. # this is actually part of the Array class
  2. my role Shaped3Array does ShapedArray {
  3. multi method AT-POS(::?CLASS:D: int \one, int \two, int \three) is raw {
  4. nqp::ifnull(
  5. nqp::atpos3d(
  6. nqp::getattr(self,List,'$!reified'),
  7. one, two, three),
  8. AT-POS-CONTAINER(self, one, two, three)
  9. )
  10. }
  11. multi method AT-POS(::?CLASS:D: Int:D \one, Int:D \two, Int:D \three) is raw {
  12. nqp::ifnull(
  13. nqp::atpos3d(
  14. nqp::getattr(self,List,'$!reified'),
  15. one, two, three),
  16. AT-POS-CONTAINER(self, one, two, three)
  17. )
  18. }
  19. sub AT-POS-CONTAINER(\array, int \one, int \two, int \three) is raw {
  20. nqp::p6bindattrinvres(
  21. (my $scalar := nqp::p6scalarfromdesc(
  22. nqp::getattr(array,Array,'$!descriptor'))),
  23. Scalar,
  24. '$!whence',
  25. -> { nqp::bindpos3d(
  26. nqp::getattr(array,List,'$!reified'),
  27. one, two, three, $scalar) }
  28. )
  29. }
  30. multi method ASSIGN-POS(::?CLASS:D: int \one, int \two, int \three, \value) {
  31. nqp::ifnull(
  32. nqp::atpos3d(
  33. nqp::getattr(self,List,'$!reified'),
  34. one, two, three),
  35. nqp::bindpos3d(
  36. nqp::getattr(self,List,'$!reified'),
  37. one, two, three,
  38. nqp::p6scalarfromdesc(nqp::getattr(self,Array,'$!descriptor')))
  39. ) = value
  40. }
  41. multi method ASSIGN-POS(::?CLASS:D: Int:D \one, Int:D \two, Int:D \three, \value) {
  42. nqp::ifnull(
  43. nqp::atpos3d(
  44. nqp::getattr(self,List,'$!reified'),
  45. one, two, three),
  46. nqp::bindpos3d(
  47. nqp::getattr(self,List,'$!reified'),
  48. one, two, three,
  49. nqp::p6scalarfromdesc(nqp::getattr(self,Array,'$!descriptor')))
  50. ) = value
  51. }
  52. multi method EXISTS-POS(::?CLASS:D: int \one, int \two, int \three) {
  53. nqp::p6bool(
  54. nqp::stmts(
  55. (my $dims :=
  56. nqp::dimensions(nqp::getattr(self,List,'$!reified'))),
  57. nqp::islt_i(one,nqp::atpos_i($dims,0))
  58. && nqp::islt_i(two,nqp::atpos_i($dims,1))
  59. && nqp::not_i(nqp::isnull(
  60. nqp::atpos3d(
  61. nqp::getattr(self,List,'$!reified'),
  62. one, two, three)
  63. ))
  64. )
  65. )
  66. }
  67. multi method EXISTS-POS(::?CLASS:D: Int:D \one, Int:D \two, Int:D \three) {
  68. nqp::p6bool(
  69. nqp::stmts(
  70. (my $dims :=
  71. nqp::dimensions(nqp::getattr(self,List,'$!reified'))),
  72. nqp::islt_i(one,nqp::atpos_i($dims,0))
  73. && nqp::islt_i(two,nqp::atpos_i($dims,1))
  74. && nqp::islt_i(three,nqp::atpos_i($dims,2))
  75. && nqp::not_i(nqp::isnull(
  76. nqp::atpos3d(
  77. nqp::getattr(self,List,'$!reified'),
  78. one, two, three)
  79. ))
  80. )
  81. )
  82. }
  83. multi method DELETE-POS(::?CLASS:D: int \one, int \two, int \three) is raw {
  84. nqp::if(
  85. nqp::isnull(my $value := nqp::atpos3d(
  86. nqp::getattr(self,List,'$!reified'),
  87. one, two, three)),
  88. Nil,
  89. nqp::stmts(
  90. nqp::bindpos3d(
  91. nqp::getattr(self,List,'$!reified'),
  92. one, two, three, nqp::null),
  93. $value
  94. )
  95. )
  96. }
  97. multi method DELETE-POS(::?CLASS:D: Int:D \one, Int:D \two, Int:D \three) is raw {
  98. nqp::if(
  99. nqp::isnull(my $value := nqp::atpos3d(
  100. nqp::getattr(self,List,'$!reified'),
  101. one, two, three)),
  102. Nil,
  103. nqp::stmts(
  104. nqp::bindpos3d(
  105. nqp::getattr(self,List,'$!reified'),
  106. one, two, three, nqp::null),
  107. $value
  108. )
  109. )
  110. }
  111. multi method BIND-POS(::?CLASS:D: int \one, int \two, int \three, \value) {
  112. nqp::bindpos3d(
  113. nqp::getattr(self,List,'$!reified'),
  114. one, two, three, value
  115. )
  116. }
  117. multi method BIND-POS(::?CLASS:D: Int:D \one, Int:D \two, Int:D \three, \value) {
  118. nqp::bindpos3d(
  119. nqp::getattr(self,List,'$!reified'),
  120. one, two, three, value
  121. )
  122. }
  123. }