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