Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 108 lines (91 sloc) 3.363 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
475b15f @pmichaud First stage of refactoring List/ListIter. Defines List generation in te...
pmichaud authored
6 method flat() {
ab1dda5 @pmichaud Convert some more pir:: opcodes to nqp:: .
pmichaud authored
7 nqp::p6list(nqp::clone($!storage), List, 1.Bool)
475b15f @pmichaud First stage of refactoring List/ListIter. Defines List generation in te...
pmichaud authored
8 }
9
16c2f0d @pmichaud Clean up for -> map translation, add Parcel.item.
pmichaud authored
10 method item() { my $v = self; }
11
4f8db8f @pmichaud Stub in Seq, add Parcel.list .
pmichaud authored
12 method list() {
ab1dda5 @pmichaud Convert some more pir:: opcodes to nqp:: .
pmichaud authored
13 nqp::p6list(nqp::clone($!storage), List, Mu)
475b15f @pmichaud First stage of refactoring List/ListIter. Defines List generation in te...
pmichaud authored
14 }
15
ead83d4 @pmichaud Let Parcels participate in postcircumfix:<[ ]>.
pmichaud authored
16 method at_pos(Parcel:D: \$x) { self.flat.at_pos($x); }
17
18 multi method postcircumfix:<[ ]>(Parcel:D: \$x) { self.flat.[$x] }
19
ba6af41 @pmichaud First cut at an implementation of 'gist' (from specs commit 669e0dd).
pmichaud authored
20 multi method gist(Parcel:D:) {
0cde9b8 @pmichaud Update gist/.gist/say with latest specifics from TimToady++.
pmichaud authored
21 my Mu $gist := nqp::list();
22 my Mu $iter := nqp::iterator($!storage);
23 nqp::push($gist, nqp::unbox_s(nqp::shift($iter).gist)) while $iter;
24 nqp::p6box_s(nqp::join(' ', $gist))
ba6af41 @pmichaud First cut at an implementation of 'gist' (from specs commit 669e0dd).
pmichaud authored
25 }
26
342f7a5 @pmichaud Improve .perl by making it a multimethod; Mu.perl now produces "Mu" ins...
pmichaud authored
27 multi method perl(Parcel:D:) {
ab1dda5 @pmichaud Convert some more pir:: opcodes to nqp:: .
pmichaud authored
28 my Mu $rpa := nqp::clone($!storage);
475b15f @pmichaud First stage of refactoring List/ListIter. Defines List generation in te...
pmichaud authored
29 my $perl = '(';
e3fb8b7 @pmichaud Clean up .perl a bit for List/Array/Parcel.
pmichaud authored
30 if $rpa {
b54894d Substitute several more pir ops by their nqp op counterparts.
kristof authored
31 $perl = $perl ~ nqp::shift($rpa).perl;
e3fb8b7 @pmichaud Clean up .perl a bit for List/Array/Parcel.
pmichaud authored
32 if $rpa {
b54894d Substitute several more pir ops by their nqp op counterparts.
kristof authored
33 $perl = $perl ~ ', ' ~ nqp::shift($rpa).perl while $rpa;
e3fb8b7 @pmichaud Clean up .perl a bit for List/Array/Parcel.
pmichaud authored
34 }
35 else {
36 $perl = $perl ~ ',';
37 }
38 }
342f7a5 @pmichaud Improve .perl by making it a multimethod; Mu.perl now produces "Mu" ins...
pmichaud authored
39 $perl ~ ')';
ac26106 @pmichaud Initial implementation of Array, List, and Parcel.
pmichaud authored
40 }
41
4923896 @pmichaud Re-enable list (Parcel) assignment, although my() declarations still hav...
pmichaud authored
42 method STORE(|$) {
43 # get the list of rvalues to store and lhs containers
44 my Mu $args := pir::perl6_current_args_rpa__P();
45 nqp::shift($args);
46 my $rhs := nqp::p6list($args, List, 1.Bool); # XXX this might need to be Seq
47
48 # first pass -- scan lhs containers and pick out
49 # scalar versus list assignment. This also reifies
50 # the rhs values
51 my Mu $lhs := nqp::clone($!storage);
52 my Mu $tv := nqp::list();
53 while ($lhs) {
54 my Mu $x := $lhs.shift;
55 if nqp::iscont($x) {
56 # container: scalar assignment
57 nqp::push($tv, $x);
58 nqp::push($tv, $rhs ?? pir::perl6_decontainerize__PP($rhs.shift) !! Nil);
59 }
60 elsif nqp::istype($x, Whatever) {
61 # Whatever: skip assigning value
62 $rhs.shift;
63 }
64 elsif nqp::istype($x, Parcel) {
65 # Parcel: splice into current lhs
66 nqp::splice($lhs, nqp::getattr($x, Parcel, '$!storage'), 0, 0)
67 }
68 else {
69 # store entire rhs
70 nqp::push($tv, $x);
71 nqp::push($tv, $rhs);
72 $rhs := ().list;
73 }
74 }
75
76 # second pass, perform the assignments
77 while ($tv) { my $x := nqp::shift($tv); $x = nqp::shift($tv); }
78 self
79 }
80
a56af91 @pmichaud Add Nil handling.
pmichaud authored
81 multi method DUMP(Parcel:D:) {
8424798 @pmichaud Fix array assignment and transitive iteration. Add a &DUMP primitive fo...
pmichaud authored
82 self.DUMP-ID() ~ '(:storage(' ~ DUMP($!storage) ~ '))'
83 }
e9d014b @pmichaud Stub in Iterable and Parcel, initial infix:<,> implementation.
pmichaud authored
84 }
85
86
ac26106 @pmichaud Initial implementation of Array, List, and Parcel.
pmichaud authored
87 my sub infix:<,>(|$) {
ab1dda5 @pmichaud Convert some more pir:: opcodes to nqp:: .
pmichaud authored
88 nqp::p6parcel(pir::perl6_current_args_rpa__P(), nqp::null());
e9d014b @pmichaud Stub in Iterable and Parcel, initial infix:<,> implementation.
pmichaud authored
89 }
90
91
66fe892 @pmichaud Create box/unbox functions for RPA <-> Parcel. Eventually we may
pmichaud authored
92 # I'm getting tired of building and unpacking Parcel RPAs by hand,
93 # so here are some pir::lookalikes to do it. Eventually we may just
94 # turn these into opcodes, since it's a common and sometimes
95 # speed-critical operation. (I'm leaving &infix:<,> alone above
96 # to avoid the extra subcall as it's very common.)
97 sub pir__perl6_box_rpa__PP(|$) {
98 pir::setattribute__0PPsP(
99 pir::repr_instance_of__PP(Parcel),
100 Parcel,
101 '$!storage',
b54894d Substitute several more pir ops by their nqp op counterparts.
kristof authored
102 nqp::shift(pir::perl6_current_args_rpa__P()))
66fe892 @pmichaud Create box/unbox functions for RPA <-> Parcel. Eventually we may
pmichaud authored
103 }
104
105 sub pir__perl6_unbox_rpa__PP(\$parcel) {
106 pir::getattribute__PPPs($parcel, Parcel, '$!storage')
107 }
Something went wrong with that request. Please try again.