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