Skip to content
Newer
Older
100644 114 lines (95 sloc) 3.41 KB
dbdb675 @jnthn Add empty Associative and Positional roles; make List/Parcel/EnumMap …
jnthn authored Jun 26, 2011
1 my class Parcel does Positional {
29921e6 @pmichaud Update comments.
pmichaud authored Jun 17, 2011
2 has $!storage; # RPA of Parcel's elements
4f8db8f @pmichaud Stub in Seq, add Parcel.list .
pmichaud authored Jun 9, 2011
3
475b15f @pmichaud First stage of refactoring List/ListIter. Defines List generation in …
pmichaud authored Jun 17, 2011
4 method flat() {
a7fa958 @pmichaud Change the argument ordering for perl6_list_from_rpa so that the rpa …
pmichaud authored Jun 25, 2011
5 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
6 }
7
4f8db8f @pmichaud Stub in Seq, add Parcel.list .
pmichaud authored Jun 9, 2011
8 method list() {
a7fa958 @pmichaud Change the argument ordering for perl6_list_from_rpa so that the rpa …
pmichaud authored Jun 25, 2011
9 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
10 }
11
ead83d4 @pmichaud Let Parcels participate in postcircumfix:<[ ]>.
pmichaud authored Jun 24, 2011
12 method at_pos(Parcel:D: \$x) { self.flat.at_pos($x); }
13
14 multi method postcircumfix:<[ ]>(Parcel:D: \$x) { self.flat.[$x] }
15
ba6af41 @pmichaud First cut at an implementation of 'gist' (from specs commit 669e0dd).
pmichaud authored Jun 18, 2011
16 multi method gist(Parcel:D:) {
0cde9b8 @pmichaud Update gist/.gist/say with latest specifics from TimToady++.
pmichaud authored Jun 25, 2011
17 my Mu $gist := nqp::list();
18 my Mu $iter := nqp::iterator($!storage);
19 nqp::push($gist, nqp::unbox_s(nqp::shift($iter).gist)) while $iter;
20 nqp::p6box_s(nqp::join(' ', $gist))
ba6af41 @pmichaud First cut at an implementation of 'gist' (from specs commit 669e0dd).
pmichaud authored Jun 18, 2011
21 }
22
342f7a5 @pmichaud Improve .perl by making it a multimethod; Mu.perl now produces "Mu" i…
pmichaud authored Jun 17, 2011
23 multi method perl(Parcel:D:) {
475b15f @pmichaud First stage of refactoring List/ListIter. Defines List generation in …
pmichaud authored Jun 17, 2011
24 my Mu $rpa := pir::clone($!storage);
25 my $perl = '(';
e3fb8b7 @pmichaud Clean up .perl a bit for List/Array/Parcel.
pmichaud authored Jun 18, 2011
26 if $rpa {
b54894d Substitute several more pir ops by their nqp op counterparts.
kristof authored Jun 22, 2011
27 $perl = $perl ~ nqp::shift($rpa).perl;
e3fb8b7 @pmichaud Clean up .perl a bit for List/Array/Parcel.
pmichaud authored Jun 18, 2011
28 if $rpa {
b54894d Substitute several more pir ops by their nqp op counterparts.
kristof authored Jun 22, 2011
29 $perl = $perl ~ ', ' ~ nqp::shift($rpa).perl while $rpa;
e3fb8b7 @pmichaud Clean up .perl a bit for List/Array/Parcel.
pmichaud authored Jun 18, 2011
30 }
31 else {
32 $perl = $perl ~ ',';
33 }
34 }
342f7a5 @pmichaud Improve .perl by making it a multimethod; Mu.perl now produces "Mu" i…
pmichaud authored Jun 17, 2011
35 $perl ~ ')';
ac26106 @pmichaud Initial implementation of Array, List, and Parcel.
pmichaud authored Jun 10, 2011
36 }
37
d19672e @pmichaud Significant refactor of lists and iterators. Results in a 50%
pmichaud authored Jun 23, 2011
38 method RPA() { $!storage }
39
4923896 @pmichaud Re-enable list (Parcel) assignment, although my() declarations still …
pmichaud authored Jun 25, 2011
40 method STORE(|$) {
41 # get the list of rvalues to store and lhs containers
42 my Mu $args := pir::perl6_current_args_rpa__P();
43 nqp::shift($args);
44 my $rhs := nqp::p6list($args, List, 1.Bool); # XXX this might need to be Seq
45
46 # first pass -- scan lhs containers and pick out
47 # scalar versus list assignment. This also reifies
48 # the rhs values
49 my Mu $lhs := nqp::clone($!storage);
50 my Mu $tv := nqp::list();
51 while ($lhs) {
52 my Mu $x := $lhs.shift;
53 if nqp::iscont($x) {
54 # container: scalar assignment
55 nqp::push($tv, $x);
56 nqp::push($tv, $rhs ?? pir::perl6_decontainerize__PP($rhs.shift) !! Nil);
57 }
58 elsif nqp::istype($x, Whatever) {
59 # Whatever: skip assigning value
60 $rhs.shift;
61 }
62 elsif nqp::istype($x, Parcel) {
63 # Parcel: splice into current lhs
64 nqp::splice($lhs, nqp::getattr($x, Parcel, '$!storage'), 0, 0)
65 }
66 else {
67 # store entire rhs
68 nqp::push($tv, $x);
69 nqp::push($tv, $rhs);
70 $rhs := ().list;
71 }
72 }
73
74 # second pass, perform the assignments
75 while ($tv) { my $x := nqp::shift($tv); $x = nqp::shift($tv); }
76 self
77 }
78
a56af91 @pmichaud Add Nil handling.
pmichaud authored Jun 18, 2011
79 multi method DUMP(Parcel:D:) {
8424798 @pmichaud Fix array assignment and transitive iteration. Add a &DUMP primitive …
pmichaud authored Jun 17, 2011
80 self.DUMP-ID() ~ '(:storage(' ~ DUMP($!storage) ~ '))'
81 }
348b506 @moritz make say() and print() redispatch to the methods on $*OUT
moritz authored Jun 25, 2011
82
83 method ARGLIST_FLATTENABLE() { $!storage }
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 }
348b506 @moritz make say() and print() redispatch to the methods on $*OUT
moritz authored Jun 25, 2011
113
Something went wrong with that request. Please try again.