Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 122 lines (104 sloc) 4.168 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
7d55a9f @pmichaud ?() should return False (jnthn++).
pmichaud authored
6 multi method Bool(Parcel:D:) { nqp::p6bool($!storage) }
120d3be @pmichaud Make sure .Numeric is properly multied.
pmichaud authored
7 multi method Numeric(Parcel:D:) { self.flat.elems }
8 multi method Str(Parcel:D:) { self.flat.Str }
0447cac @moritz implement capitalize
moritz authored
9 # multi method Int(Parcel:D:) { self.flat.elems }
c47b816 @moritz simplistic List.ACCEPTS, fix Array.push to return self
moritz authored
10 multi method ACCEPTS(Parcel:D: $topic) { self.list.ACCEPTS($topic) }
120d3be @pmichaud Make sure .Numeric is properly multied.
pmichaud authored
11
08e1061 @moritz .perl methods for Match and EnumMap
moritz authored
12 method Parcel() { self }
855106b @jnthn Fix Parcel.Capture.
jnthn authored
13 method Capture() {
14 my $cap := nqp::create(Capture);
d032415 @jnthn Improve Parcel.Capture.
jnthn authored
15 my Mu $list := nqp::list();
16 my Mu $hash := nqp::hash();
17 my int $c = nqp::elems($!storage);
18 my int $i = 0;
19 while $i < $c {
20 my $v := nqp::atpos($!storage, $i);
21 nqp::istype($v, Pair) ??
22 nqp::bindkey($hash, nqp::unbox_s($v.key), $v.value) !!
23 nqp::push($list, $v);
24 $i = $i + 1;
25 }
26 nqp::bindattr($cap, Capture, '$!list', $list);
27 nqp::bindattr($cap, Capture, '$!hash', $hash);
855106b @jnthn Fix Parcel.Capture.
jnthn authored
28 $cap
29 }
f5c25da @pmichaud More array-related methods and fixes. This _almost_ gets us
pmichaud authored
30
e80b1b1 @pmichaud Parcel.elems should flatten (per TimToady++ at yapc::na 2012).
pmichaud authored
31 method elems() { self.flat.elems }
32 method item() { my $v = self; }
33 method flat() { nqp::p6list(nqp::clone($!storage), List, Bool::True) }
34 method list() { nqp::p6list(nqp::clone($!storage), List, Mu) }
35 method lol() { nqp::p6list(nqp::clone($!storage), LoL, Mu) }
457b5e7 @pmichaud First cut at zip and cross operators and metaoperators.
pmichaud authored
36
f621500 @pmichaud Refactor handling of dispatch:<hyper> (>>.foo) to preserve structure.
pmichaud authored
37 method at_pos(Parcel:D: \$x) is rw { self.flat.at_pos($x); }
ead83d4 @pmichaud Let Parcels participate in postcircumfix:<[ ]>.
pmichaud authored
38
9070eeb @jnthn Don't strip elements of their containers when indexing into a Parcel.…
jnthn authored
39 proto method postcircumfix:<[ ]>(|$) { * }
40 multi method postcircumfix:<[ ]>() is rw { self.flat }
41 multi method postcircumfix:<[ ]>(Parcel:D: \$x) is rw { self.flat.[$x] }
ead83d4 @pmichaud Let Parcels participate in postcircumfix:<[ ]>.
pmichaud authored
42
ba6af41 @pmichaud First cut at an implementation of 'gist' (from specs commit 669e0dd).
pmichaud authored
43 multi method gist(Parcel:D:) {
0cde9b8 @pmichaud Update gist/.gist/say with latest specifics from TimToady++.
pmichaud authored
44 my Mu $gist := nqp::list();
45 my Mu $iter := nqp::iterator($!storage);
46 nqp::push($gist, nqp::unbox_s(nqp::shift($iter).gist)) while $iter;
47 nqp::p6box_s(nqp::join(' ', $gist))
ba6af41 @pmichaud First cut at an implementation of 'gist' (from specs commit 669e0dd).
pmichaud authored
48 }
49
a4c78fb @pmichaud Use "$()" in Parcel.perl to show when a Parcel is in a scalar container.
pmichaud authored
50 multi method perl(Parcel:D \$self:) {
ab1dda5 @pmichaud Convert some more pir:: opcodes to nqp:: .
pmichaud authored
51 my Mu $rpa := nqp::clone($!storage);
a4c78fb @pmichaud Use "$()" in Parcel.perl to show when a Parcel is in a scalar container.
pmichaud authored
52 my $perl = nqp::iscont($self) ?? '$(' !! '(';
e3fb8b7 @pmichaud Clean up .perl a bit for List/Array/Parcel.
pmichaud authored
53 if $rpa {
b54894d Substitute several more pir ops by their nqp op counterparts.
kristof authored
54 $perl = $perl ~ nqp::shift($rpa).perl;
e3fb8b7 @pmichaud Clean up .perl a bit for List/Array/Parcel.
pmichaud authored
55 if $rpa {
b54894d Substitute several more pir ops by their nqp op counterparts.
kristof authored
56 $perl = $perl ~ ', ' ~ nqp::shift($rpa).perl while $rpa;
e3fb8b7 @pmichaud Clean up .perl a bit for List/Array/Parcel.
pmichaud authored
57 }
58 else {
59 $perl = $perl ~ ',';
60 }
61 }
342f7a5 @pmichaud Improve .perl by making it a multimethod; Mu.perl now produces "Mu" …
pmichaud authored
62 $perl ~ ')';
ac26106 @pmichaud Initial implementation of Array, List, and Parcel.
pmichaud authored
63 }
64
4923896 @pmichaud Re-enable list (Parcel) assignment, although my() declarations still …
pmichaud authored
65 method STORE(|$) {
66 # get the list of rvalues to store and lhs containers
67 my Mu $args := pir::perl6_current_args_rpa__P();
68 nqp::shift($args);
7019642 @pmichaud Convert instances of 1.Bool into Bool::True.
pmichaud authored
69 my $rhs := nqp::p6list($args, List, Bool::True); # XXX this might need to be Seq
4923896 @pmichaud Re-enable list (Parcel) assignment, although my() declarations still …
pmichaud authored
70
71 # first pass -- scan lhs containers and pick out
72 # scalar versus list assignment. This also reifies
73 # the rhs values
74 my Mu $lhs := nqp::clone($!storage);
75 my Mu $tv := nqp::list();
76 while ($lhs) {
1886ee9 @pmichaud Use nqp::shift($rpa) instead of $rpa.shift.
pmichaud authored
77 my Mu $x := nqp::shift($lhs);
4923896 @pmichaud Re-enable list (Parcel) assignment, although my() declarations still …
pmichaud authored
78 if nqp::iscont($x) {
79 # container: scalar assignment
80 nqp::push($tv, $x);
18dea93 @jnthn Add an nqp::p6decont and eliminate pir::perl6_decontainerize in the s…
jnthn authored
81 nqp::push($tv, $rhs.gimme(1) ?? nqp::p6decont($rhs.shift) !! Nil);
4923896 @pmichaud Re-enable list (Parcel) assignment, although my() declarations still …
pmichaud authored
82 }
83 elsif nqp::istype($x, Whatever) {
84 # Whatever: skip assigning value
85 $rhs.shift;
86 }
87 elsif nqp::istype($x, Parcel) {
88 # Parcel: splice into current lhs
89 nqp::splice($lhs, nqp::getattr($x, Parcel, '$!storage'), 0, 0)
90 }
91 else {
92 # store entire rhs
93 nqp::push($tv, $x);
94 nqp::push($tv, $rhs);
95 $rhs := ().list;
96 }
97 }
98
99 # second pass, perform the assignments
100 while ($tv) { my $x := nqp::shift($tv); $x = nqp::shift($tv); }
101 self
102 }
103
a56af91 @pmichaud Add Nil handling.
pmichaud authored
104 multi method DUMP(Parcel:D:) {
8424798 @pmichaud Fix array assignment and transitive iteration. Add a &DUMP primitive…
pmichaud authored
105 self.DUMP-ID() ~ '(:storage(' ~ DUMP($!storage) ~ '))'
106 }
bf8a6af @jnthn Allow | to work on a Parcel.
jnthn authored
107
029c30f @jnthn Refactor of flattening and better handling of duplicate named paramet…
jnthn authored
108 method FLATTENABLE_LIST() { $!storage }
109 method FLATTENABLE_HASH() { nqp::hash() }
ecce797 @moritz Parcel.fmt
moritz authored
110
111 method fmt($format = '%s', $separator = ' ') {
112 self.list.fmt($format, $separator);
113 }
e9d014b @pmichaud Stub in Iterable and Parcel, initial infix:<,> implementation.
pmichaud authored
114 }
115
116
ac26106 @pmichaud Initial implementation of Array, List, and Parcel.
pmichaud authored
117 my sub infix:<,>(|$) {
ab1dda5 @pmichaud Convert some more pir:: opcodes to nqp:: .
pmichaud authored
118 nqp::p6parcel(pir::perl6_current_args_rpa__P(), nqp::null());
e9d014b @pmichaud Stub in Iterable and Parcel, initial infix:<,> implementation.
pmichaud authored
119 }
120
121
Something went wrong with that request. Please try again.