Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 116 lines (95 sloc) 3.53 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);
15 nqp::bindattr($cap, Capture, '$!list', $!storage);
16 $cap
17 }
f5c25da Patrick R. Michaud More array-related methods and fixes. This _almost_ gets us
pmichaud authored
18
475b15f Patrick R. Michaud First stage of refactoring List/ListIter. Defines List generation in te...
pmichaud authored
19 method flat() {
7019642 Patrick R. Michaud Convert instances of 1.Bool into Bool::True.
pmichaud authored
20 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
21 }
22
16c2f0d Patrick R. Michaud Clean up for -> map translation, add Parcel.item.
pmichaud authored
23 method item() { my $v = self; }
24
4f8db8f Patrick R. Michaud Stub in Seq, add Parcel.list .
pmichaud authored
25 method list() {
ab1dda5 Patrick R. Michaud Convert some more pir:: opcodes to nqp:: .
pmichaud authored
26 nqp::p6list(nqp::clone($!storage), List, Mu)
475b15f Patrick R. Michaud First stage of refactoring List/ListIter. Defines List generation in te...
pmichaud authored
27 }
28
457b5e7 Patrick R. Michaud First cut at zip and cross operators and metaoperators.
pmichaud authored
29 method lol() {
30 nqp::p6list(nqp::clone($!storage), LoL, Mu)
31 }
32
f621500 Patrick R. Michaud Refactor handling of dispatch:<hyper> (>>.foo) to preserve structure.
pmichaud authored
33 method at_pos(Parcel:D: \$x) is rw { self.flat.at_pos($x); }
ead83d4 Patrick R. Michaud Let Parcels participate in postcircumfix:<[ ]>.
pmichaud authored
34
8d597c2 Patrick R. Michaud Add infix:<=:=>, a major cheat for Parcel.Capture(), and three more spec...
pmichaud authored
35 method postcircumfix:<[ ]>(Parcel:D: \$x) { self.flat.[$x] }
ead83d4 Patrick R. Michaud Let Parcels participate in postcircumfix:<[ ]>.
pmichaud authored
36
ba6af41 Patrick R. Michaud First cut at an implementation of 'gist' (from specs commit 669e0dd).
pmichaud authored
37 multi method gist(Parcel:D:) {
0cde9b8 Patrick R. Michaud Update gist/.gist/say with latest specifics from TimToady++.
pmichaud authored
38 my Mu $gist := nqp::list();
39 my Mu $iter := nqp::iterator($!storage);
40 nqp::push($gist, nqp::unbox_s(nqp::shift($iter).gist)) while $iter;
41 nqp::p6box_s(nqp::join(' ', $gist))
ba6af41 Patrick R. Michaud First cut at an implementation of 'gist' (from specs commit 669e0dd).
pmichaud authored
42 }
43
342f7a5 Patrick R. Michaud Improve .perl by making it a multimethod; Mu.perl now produces "Mu" ins...
pmichaud authored
44 multi method perl(Parcel:D:) {
ab1dda5 Patrick R. Michaud Convert some more pir:: opcodes to nqp:: .
pmichaud authored
45 my Mu $rpa := nqp::clone($!storage);
475b15f Patrick R. Michaud First stage of refactoring List/ListIter. Defines List generation in te...
pmichaud authored
46 my $perl = '(';
e3fb8b7 Patrick R. Michaud Clean up .perl a bit for List/Array/Parcel.
pmichaud authored
47 if $rpa {
b54894d Substitute several more pir ops by their nqp op counterparts.
kristof authored
48 $perl = $perl ~ nqp::shift($rpa).perl;
e3fb8b7 Patrick R. Michaud Clean up .perl a bit for List/Array/Parcel.
pmichaud authored
49 if $rpa {
b54894d Substitute several more pir ops by their nqp op counterparts.
kristof authored
50 $perl = $perl ~ ', ' ~ nqp::shift($rpa).perl while $rpa;
e3fb8b7 Patrick R. Michaud Clean up .perl a bit for List/Array/Parcel.
pmichaud authored
51 }
52 else {
53 $perl = $perl ~ ',';
54 }
55 }
342f7a5 Patrick R. Michaud Improve .perl by making it a multimethod; Mu.perl now produces "Mu" ins...
pmichaud authored
56 $perl ~ ')';
ac26106 Patrick R. Michaud Initial implementation of Array, List, and Parcel.
pmichaud authored
57 }
58
4923896 Patrick R. Michaud Re-enable list (Parcel) assignment, although my() declarations still hav...
pmichaud authored
59 method STORE(|$) {
60 # get the list of rvalues to store and lhs containers
61 my Mu $args := pir::perl6_current_args_rpa__P();
62 nqp::shift($args);
7019642 Patrick R. Michaud Convert instances of 1.Bool into Bool::True.
pmichaud authored
63 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
64
65 # first pass -- scan lhs containers and pick out
66 # scalar versus list assignment. This also reifies
67 # the rhs values
68 my Mu $lhs := nqp::clone($!storage);
69 my Mu $tv := nqp::list();
70 while ($lhs) {
71 my Mu $x := $lhs.shift;
72 if nqp::iscont($x) {
73 # container: scalar assignment
74 nqp::push($tv, $x);
18dea93 Jonathan Worthington Add an nqp::p6decont and eliminate pir::perl6_decontainerize in the sett...
jnthn authored
75 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
76 }
77 elsif nqp::istype($x, Whatever) {
78 # Whatever: skip assigning value
79 $rhs.shift;
80 }
81 elsif nqp::istype($x, Parcel) {
82 # Parcel: splice into current lhs
83 nqp::splice($lhs, nqp::getattr($x, Parcel, '$!storage'), 0, 0)
84 }
85 else {
86 # store entire rhs
87 nqp::push($tv, $x);
88 nqp::push($tv, $rhs);
89 $rhs := ().list;
90 }
91 }
92
93 # second pass, perform the assignments
94 while ($tv) { my $x := nqp::shift($tv); $x = nqp::shift($tv); }
95 self
96 }
97
a56af91 Patrick R. Michaud Add Nil handling.
pmichaud authored
98 multi method DUMP(Parcel:D:) {
8424798 Patrick R. Michaud Fix array assignment and transitive iteration. Add a &DUMP primitive fo...
pmichaud authored
99 self.DUMP-ID() ~ '(:storage(' ~ DUMP($!storage) ~ '))'
100 }
bf8a6af Jonathan Worthington Allow | to work on a Parcel.
jnthn authored
101
029c30f Jonathan Worthington Refactor of flattening and better handling of duplicate named parameters...
jnthn authored
102 method FLATTENABLE_LIST() { $!storage }
103 method FLATTENABLE_HASH() { nqp::hash() }
ecce797 Moritz Lenz Parcel.fmt
moritz authored
104
105 method fmt($format = '%s', $separator = ' ') {
106 self.list.fmt($format, $separator);
107 }
e9d014b Patrick R. Michaud Stub in Iterable and Parcel, initial infix:<,> implementation.
pmichaud authored
108 }
109
110
ac26106 Patrick R. Michaud Initial implementation of Array, List, and Parcel.
pmichaud authored
111 my sub infix:<,>(|$) {
ab1dda5 Patrick R. Michaud Convert some more pir:: opcodes to nqp:: .
pmichaud authored
112 nqp::p6parcel(pir::perl6_current_args_rpa__P(), nqp::null());
e9d014b Patrick R. Michaud Stub in Iterable and Parcel, initial infix:<,> implementation.
pmichaud authored
113 }
114
115
Something went wrong with that request. Please try again.