/
Shaped2.pm6
91 lines (86 loc) · 3.24 KB
/
Shaped2.pm6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
my role Array::Shaped2 does Array::Shaped {
multi method AT-POS(::?CLASS:D: uint $one, uint $two) is raw {
nqp::ifnull(
nqp::atpos2d(nqp::getattr(self,List,'$!reified'),$one,$two),
AT-POS-CONTAINER(self, $one, $two)
)
}
multi method AT-POS(::?CLASS:D: Int:D $one, Int:D $two) is raw {
nqp::ifnull(
nqp::atpos2d(nqp::getattr(self,List,'$!reified'),$one,$two),
AT-POS-CONTAINER(self, $one, $two)
)
}
sub AT-POS-CONTAINER(\array, uint $one, uint $two) is raw {
nqp::p6scalarfromdesc(
ContainerDescriptor::BindArrayPos2D.new(
nqp::getattr(array,Array,'$!descriptor'),
nqp::getattr(array,List,'$!reified'),
$one, $two
)
)
}
multi method ASSIGN-POS(::?CLASS:D: uint $one, uint $two, \value) {
my \reified := nqp::getattr(self,List,'$!reified');
nqp::ifnull(
nqp::atpos2d(reified,$one,$two),
nqp::bindpos2d(reified,$one,$two,
nqp::p6scalarfromdesc(nqp::getattr(self,Array,'$!descriptor')))
) = value
}
multi method ASSIGN-POS(::?CLASS:D: Int:D $one, Int:D $two, \value) {
my \reified := nqp::getattr(self,List,'$!reified');
nqp::ifnull(
nqp::atpos2d(reified,$one,$two),
nqp::bindpos2d(reified,$one,$two,
nqp::p6scalarfromdesc(nqp::getattr(self,Array,'$!descriptor')))
) = value
}
multi method EXISTS-POS(::?CLASS:D: uint $one, uint $two --> Bool:D) {
my \reified := nqp::getattr(self,List,'$!reified');
my \dims := nqp::dimensions(reified);
nqp::hllbool(
nqp::islt_i($one,nqp::atpos_i(dims,0))
&& nqp::islt_i($two,nqp::atpos_i(dims,1))
&& nqp::not_i(nqp::isnull(nqp::atpos2d(reified,$one,$two)))
)
}
multi method EXISTS-POS(::?CLASS:D: Int:D $one, Int:D $two --> Bool:D) {
my \reified := nqp::getattr(self,List,'$!reified');
my \dims := nqp::dimensions(reified);
nqp::hllbool(
nqp::islt_i($one,nqp::atpos_i(dims,0))
&& nqp::islt_i($two,nqp::atpos_i(dims,1))
&& nqp::not_i(nqp::isnull(nqp::atpos2d(reified,$one,$two)))
)
}
multi method DELETE-POS(::?CLASS:D: uint $one, uint $two) is raw {
my \reified := nqp::getattr(self,List,'$!reified');
nqp::if(
nqp::isnull(my \value := nqp::atpos2d(reified,$one,$two)),
Nil,
nqp::stmts(
nqp::bindpos2d(reified,$one,$two,nqp::null),
value
)
)
}
multi method DELETE-POS(::?CLASS:D: Int:D $one, Int:D $two) is raw {
my \reified := nqp::getattr(self,List,'$!reified');
nqp::if(
nqp::isnull(my \value := nqp::atpos2d(reified,$one,$two)),
Nil,
nqp::stmts(
nqp::bindpos2d(reified,$one,$two,nqp::null),
value
)
)
}
multi method BIND-POS(::?CLASS:D: uint $one, uint $two, \value) {
nqp::bindpos2d(nqp::getattr(self,List,'$!reified'),$one,$two,value)
}
multi method BIND-POS(::?CLASS:D: Int:D $one, Int:D $two, \value) {
nqp::bindpos2d(nqp::getattr(self,List,'$!reified'),$one,$two,value)
}
}
# vim: expandtab shiftwidth=4