Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tag: London
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 116 lines (95 sloc) 3.53 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
my class Parcel does Positional {
    # declared in BOOTSTRAP.pm:
    # is Cool; # parent class
    # has $!storage; # RPA of Parcel's elements

    multi method Bool(Parcel:D:) { nqp::p6bool($!storage) }
    multi method Numeric(Parcel:D:) { self.flat.elems }
    multi method Str(Parcel:D:) { self.flat.Str }
# multi method Int(Parcel:D:) { self.flat.elems }
    multi method ACCEPTS(Parcel:D: $topic) { self.list.ACCEPTS($topic) }

    method Parcel() { self }
    method Capture() {
        my $cap := nqp::create(Capture);
        nqp::bindattr($cap, Capture, '$!list', $!storage);
        $cap
    }

    method flat() {
        nqp::p6list(nqp::clone($!storage), List, Bool::True)
    }

    method item() { my $v = self; }

    method list() {
        nqp::p6list(nqp::clone($!storage), List, Mu)
    }

    method lol() {
        nqp::p6list(nqp::clone($!storage), LoL, Mu)
    }

    method at_pos(Parcel:D: \$x) is rw { self.flat.at_pos($x); }

    method postcircumfix:<[ ]>(Parcel:D: \$x) { self.flat.[$x] }

    multi method gist(Parcel:D:) {
        my Mu $gist := nqp::list();
        my Mu $iter := nqp::iterator($!storage);
        nqp::push($gist, nqp::unbox_s(nqp::shift($iter).gist)) while $iter;
        nqp::p6box_s(nqp::join(' ', $gist))
    }

    multi method perl(Parcel:D:) {
        my Mu $rpa := nqp::clone($!storage);
        my $perl = '(';
        if $rpa {
            $perl = $perl ~ nqp::shift($rpa).perl;
            if $rpa {
                $perl = $perl ~ ', ' ~ nqp::shift($rpa).perl while $rpa;
            }
            else {
                $perl = $perl ~ ',';
            }
        }
        $perl ~ ')';
    }

    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, Bool::True); # 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.gimme(1) ?? nqp::p6decont($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) ~ '))'
    }
    
    method FLATTENABLE_LIST() { $!storage }
    method FLATTENABLE_HASH() { nqp::hash() }

    method fmt($format = '%s', $separator = ' ') {
        self.list.fmt($format, $separator);
    }
}


my sub infix:<,>(|$) {
    nqp::p6parcel(pir::perl6_current_args_rpa__P(), nqp::null());
}


Something went wrong with that request. Please try again.