Skip to content
Browse files

Re-enable list (Parcel) assignment, although my() declarations still …

…have a bug.

Add a LHF for Nil scalar assignment.
  • Loading branch information...
1 parent a7fa958 commit 492389692b42ed3f5ca6a9d436624dd767b61048 @pmichaud pmichaud committed Jun 25, 2011
Showing with 42 additions and 0 deletions.
  1. +3 −0 LHF.markdown
  2. +39 −0 src/core/Parcel.pm
View
3 LHF.markdown
@@ -14,3 +14,6 @@ of the IO class should be do-able.
## Built-ins
Str.chop
+
+## Nil assignment
+my Int $b = 3; $b = Nil;
View
39 src/core/Parcel.pm
@@ -37,6 +37,45 @@ my class Parcel {
method RPA() { $!storage }
+ method STORE(|$) {
+ # get the list of rvalues to store and lhs containers
+ my Mu $args := pir::perl6_current_args_rpa__P();
+ nqp::shift($args);
+ my $rhs := nqp::p6list($args, List, 1.Bool); # XXX this might need to be Seq
+
+ # first pass -- scan lhs containers and pick out
+ # scalar versus list assignment. This also reifies
+ # the rhs values
+ my Mu $lhs := nqp::clone($!storage);
+ my Mu $tv := nqp::list();
+ while ($lhs) {
+ my Mu $x := $lhs.shift;
+ if nqp::iscont($x) {
+ # container: scalar assignment
+ nqp::push($tv, $x);
+ nqp::push($tv, $rhs ?? pir::perl6_decontainerize__PP($rhs.shift) !! Nil);
+ }
+ elsif nqp::istype($x, Whatever) {
+ # Whatever: skip assigning value
+ $rhs.shift;
+ }
+ elsif nqp::istype($x, Parcel) {
+ # Parcel: splice into current lhs
+ nqp::splice($lhs, nqp::getattr($x, Parcel, '$!storage'), 0, 0)
+ }
+ else {
+ # store entire rhs
+ nqp::push($tv, $x);
+ nqp::push($tv, $rhs);
+ $rhs := ().list;
+ }
+ }
+
+ # second pass, perform the assignments
+ while ($tv) { my $x := nqp::shift($tv); $x = nqp::shift($tv); }
+ self
+ }
+
multi method DUMP(Parcel:D:) {
self.DUMP-ID() ~ '(:storage(' ~ DUMP($!storage) ~ '))'
}

0 comments on commit 4923896

Please sign in to comment.
Something went wrong with that request. Please try again.