Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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