-
-
Notifications
You must be signed in to change notification settings - Fork 372
/
Array.pm
35 lines (31 loc) · 860 Bytes
/
Array.pm
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
augment class Array {
our method push(*@values) is export {
my @a = @values;
Q:PIR {
$P0 = find_lex '@a'
$P0 = getattribute $P0, '$!values'
$P1 = find_lex 'self'
$P2 = $P1.'!generate'(0)
$I0 = elements $P2
splice $P2, $P0, $I0, 0
};
self;
}
our method unshift(*@values) is export {
my @a = @values;
Q:PIR {
$P0 = find_lex '@a'
$P0 = getattribute $P0, '$!values'
$P1 = find_lex 'self'
$P2 = $P1.'!generate'(0)
splice $P2, $P0, 0, 0
$P0 = box 0
setattribute $P1, '$!gen', $P0
};
self;
}
our multi method pop() {
self.elems > 0 ?? pir::pop__PP($!values) !! Mu;
}
}
our proto sub pop(@array) { @array.pop; }