Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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