Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 110 lines (92 sloc) 3.414 kb
dbdb675 @jnthn Add empty Associative and Positional roles; make List/Parcel/EnumMap …
jnthn authored
1 my class Parcel does Positional {
8812718 @pmichaud Create an opcode for building Parcels; the opcode also handles replacing
pmichaud authored
2 # declared in BOOTSTRAP.pm:
3 # is Cool; # parent class
4 # has $!storage; # RPA of Parcel's elements
4f8db8f @pmichaud Stub in Seq, add Parcel.list .
pmichaud authored
5
f5c25da @pmichaud More array-related methods and fixes. This _almost_ gets us
pmichaud authored
6 multi method Str(Parcel:D:) { self.flat.Str }
7
475b15f @pmichaud First stage of refactoring List/ListIter. Defines List generation in…
pmichaud authored
8 method flat() {
ab1dda5 @pmichaud Convert some more pir:: opcodes to nqp:: .
pmichaud authored
9 nqp::p6list(nqp::clone($!storage), List, 1.Bool)
475b15f @pmichaud First stage of refactoring List/ListIter. Defines List generation in…
pmichaud authored
10 }
11
16c2f0d @pmichaud Clean up for -> map translation, add Parcel.item.
pmichaud authored
12 method item() { my $v = self; }
13
4f8db8f @pmichaud Stub in Seq, add Parcel.list .
pmichaud authored
14 method list() {
ab1dda5 @pmichaud Convert some more pir:: opcodes to nqp:: .
pmichaud authored
15 nqp::p6list(nqp::clone($!storage), List, Mu)
475b15f @pmichaud First stage of refactoring List/ListIter. Defines List generation in…
pmichaud authored
16 }
17
ead83d4 @pmichaud Let Parcels participate in postcircumfix:<[ ]>.
pmichaud authored
18 method at_pos(Parcel:D: \$x) { self.flat.at_pos($x); }
19
20 multi method postcircumfix:<[ ]>(Parcel:D: \$x) { self.flat.[$x] }
21
ba6af41 @pmichaud First cut at an implementation of 'gist' (from specs commit 669e0dd).
pmichaud authored
22 multi method gist(Parcel:D:) {
0cde9b8 @pmichaud Update gist/.gist/say with latest specifics from TimToady++.
pmichaud authored
23 my Mu $gist := nqp::list();
24 my Mu $iter := nqp::iterator($!storage);
25 nqp::push($gist, nqp::unbox_s(nqp::shift($iter).gist)) while $iter;
26 nqp::p6box_s(nqp::join(' ', $gist))
ba6af41 @pmichaud First cut at an implementation of 'gist' (from specs commit 669e0dd).
pmichaud authored
27 }
28
342f7a5 @pmichaud Improve .perl by making it a multimethod; Mu.perl now produces "Mu" …
pmichaud authored
29 multi method perl(Parcel:D:) {
ab1dda5 @pmichaud Convert some more pir:: opcodes to nqp:: .
pmichaud authored
30 my Mu $rpa := nqp::clone($!storage);
475b15f @pmichaud First stage of refactoring List/ListIter. Defines List generation in…
pmichaud authored
31 my $perl = '(';
e3fb8b7 @pmichaud Clean up .perl a bit for List/Array/Parcel.
pmichaud authored
32 if $rpa {
b54894d Substitute several more pir ops by their nqp op counterparts.
kristof authored
33 $perl = $perl ~ nqp::shift($rpa).perl;
e3fb8b7 @pmichaud Clean up .perl a bit for List/Array/Parcel.
pmichaud authored
34 if $rpa {
b54894d Substitute several more pir ops by their nqp op counterparts.
kristof authored
35 $perl = $perl ~ ', ' ~ nqp::shift($rpa).perl while $rpa;
e3fb8b7 @pmichaud Clean up .perl a bit for List/Array/Parcel.
pmichaud authored
36 }
37 else {
38 $perl = $perl ~ ',';
39 }
40 }
342f7a5 @pmichaud Improve .perl by making it a multimethod; Mu.perl now produces "Mu" …
pmichaud authored
41 $perl ~ ')';
ac26106 @pmichaud Initial implementation of Array, List, and Parcel.
pmichaud authored
42 }
43
4923896 @pmichaud Re-enable list (Parcel) assignment, although my() declarations still …
pmichaud authored
44 method STORE(|$) {
45 # get the list of rvalues to store and lhs containers
46 my Mu $args := pir::perl6_current_args_rpa__P();
47 nqp::shift($args);
48 my $rhs := nqp::p6list($args, List, 1.Bool); # XXX this might need to be Seq
49
50 # first pass -- scan lhs containers and pick out
51 # scalar versus list assignment. This also reifies
52 # the rhs values
53 my Mu $lhs := nqp::clone($!storage);
54 my Mu $tv := nqp::list();
55 while ($lhs) {
56 my Mu $x := $lhs.shift;
57 if nqp::iscont($x) {
58 # container: scalar assignment
59 nqp::push($tv, $x);
60 nqp::push($tv, $rhs ?? pir::perl6_decontainerize__PP($rhs.shift) !! Nil);
61 }
62 elsif nqp::istype($x, Whatever) {
63 # Whatever: skip assigning value
64 $rhs.shift;
65 }
66 elsif nqp::istype($x, Parcel) {
67 # Parcel: splice into current lhs
68 nqp::splice($lhs, nqp::getattr($x, Parcel, '$!storage'), 0, 0)
69 }
70 else {
71 # store entire rhs
72 nqp::push($tv, $x);
73 nqp::push($tv, $rhs);
74 $rhs := ().list;
75 }
76 }
77
78 # second pass, perform the assignments
79 while ($tv) { my $x := nqp::shift($tv); $x = nqp::shift($tv); }
80 self
81 }
82
a56af91 @pmichaud Add Nil handling.
pmichaud authored
83 multi method DUMP(Parcel:D:) {
8424798 @pmichaud Fix array assignment and transitive iteration. Add a &DUMP primitive…
pmichaud authored
84 self.DUMP-ID() ~ '(:storage(' ~ DUMP($!storage) ~ '))'
85 }
e9d014b @pmichaud Stub in Iterable and Parcel, initial infix:<,> implementation.
pmichaud authored
86 }
87
88
ac26106 @pmichaud Initial implementation of Array, List, and Parcel.
pmichaud authored
89 my sub infix:<,>(|$) {
ab1dda5 @pmichaud Convert some more pir:: opcodes to nqp:: .
pmichaud authored
90 nqp::p6parcel(pir::perl6_current_args_rpa__P(), nqp::null());
e9d014b @pmichaud Stub in Iterable and Parcel, initial infix:<,> implementation.
pmichaud authored
91 }
92
93
66fe892 @pmichaud Create box/unbox functions for RPA <-> Parcel. Eventually we may
pmichaud authored
94 # I'm getting tired of building and unpacking Parcel RPAs by hand,
95 # so here are some pir::lookalikes to do it. Eventually we may just
96 # turn these into opcodes, since it's a common and sometimes
97 # speed-critical operation. (I'm leaving &infix:<,> alone above
98 # to avoid the extra subcall as it's very common.)
99 sub pir__perl6_box_rpa__PP(|$) {
100 pir::setattribute__0PPsP(
101 pir::repr_instance_of__PP(Parcel),
102 Parcel,
103 '$!storage',
b54894d Substitute several more pir ops by their nqp op counterparts.
kristof authored
104 nqp::shift(pir::perl6_current_args_rpa__P()))
66fe892 @pmichaud Create box/unbox functions for RPA <-> Parcel. Eventually we may
pmichaud authored
105 }
106
107 sub pir__perl6_unbox_rpa__PP(\$parcel) {
108 pir::getattribute__PPPs($parcel, Parcel, '$!storage')
109 }
Something went wrong with that request. Please try again.