Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

First cut at zip and cross operators and metaoperators.

  • Loading branch information...
commit 457b5e74138d57e7a2538830c5d4b7926ee675c9 1 parent e366355
@pmichaud pmichaud authored
View
15 src/Perl6/Actions.pm
@@ -2111,7 +2111,20 @@ class Perl6::Actions is HLL::Actions {
make $past;
}
- method semiarglist($/) { make $<arglist>.ast; }
+ method semiarglist($/) {
+ if +$<arglist> == 1 {
+ make $<arglist>[0].ast;
+ }
+ else {
+ my $past := PAST::Op.new( :pasttype('call'), :node($/) );
+ for $<arglist> {
+ my $ast := $_.ast;
+ $ast.name('&infix:<,>');
+ $past.push($ast);
+ }
+ make $past;
+ }
+ }
method arglist($/) {
# Build up argument list, hanlding nameds and flattens
View
3  src/Perl6/Grammar.pm
@@ -1449,7 +1449,8 @@ grammar Perl6::Grammar is HLL::Grammar {
}
token semiarglist {
- <arglist>
+ <arglist> ** ';'
+ <.ws>
}
token arglist {
View
74 src/core/LoL.pm
@@ -0,0 +1,74 @@
+class LoL {
+ # declared in BOOTSTRAP:
+ # is List; # parent class
+
+ method new(|$) {
+ my Mu $args := pir::perl6_current_args_rpa__P();
+ nqp::shift($args);
+ nqp::p6list($args, self.WHAT, Mu);
+ }
+
+ method at_pos($pos is copy) {
+ $pos = $pos.Int;
+ self.exists($pos)
+ ?? pir::find_method__PPs(List, 'at_pos')(self, $pos)
+ !! pir::setattribute__0PPsP(my $v, Scalar, '$!whence',
+ -> { pir::find_method__PPs(List, 'STORE_AT_POS')(self, $pos, $v) } )
+ }
+
+ multi method perl(LoL:D \$self:) {
+ self.WHAT.perl ~ '.new(' ~ self.map({.perl}).join(', ') ~ ')'
+ ~ ('.item' if nqp::iscont($self));
+ }
+
+ method REIFY(Parcel \$parcel) {
+ my Mu $rpa := nqp::getattr($parcel, Parcel, '$!storage');
+ my Mu $iter := nqp::iterator($rpa);
+ my $i = 0;
+ while $iter {
+ nqp::bindpos($rpa, nqp::unbox_i($i++), my $v = nqp::shift($iter));
+ }
+ pir::find_method__PPs(List, 'REIFY')(self, $parcel)
+ }
+
+ method STORE_AT_POS(\$pos, Mu $v is copy) {
+ pir::find_method__PPs(List, 'STORE_AT_POS')(self, $pos, $v);
+ }
+
+}
+
+
+sub infix:<X>(**@lol) {
+ my @l;
+ my @v;
+ @l[0] = (@lol[0].flat,).list;
+ my $i = 0;
+ my $n = @lol.elems - 1;
+ gather {
+ while $i >= 0 {
+ if @l[$i] {
+ @v[$i] = @l[$i].shift;
+ if $i >= $n { my @x = @v; take @x.Parcel }
+ else {
+ $i++;
+ @l[$i] = (@lol[$i].flat,).list;
+ }
+ }
+ else { $i--; }
+ }
+ }
+};
+
+sub infix:<Z>(**@lol) {
+ my @l = @lol.map({ (.flat,).list.item });
+ gather {
+ my $loop = 1;
+ while $loop {
+ my $p := @l.map({ $loop = 0 unless $_; .shift }).eager.Parcel;
+ take $p if $loop;
+ }
+ }
+}
+
+my &zip := &infix:<Z>;
+
View
4 src/core/Parcel.pm
@@ -16,6 +16,10 @@ my class Parcel does Positional {
nqp::p6list(nqp::clone($!storage), List, Mu)
}
+ method lol() {
+ nqp::p6list(nqp::clone($!storage), LoL, Mu)
+ }
+
method at_pos(Parcel:D: \$x) { self.flat.at_pos($x); }
multi method postcircumfix:<[ ]>(Parcel:D: \$x) { self.flat.[$x] }
View
34 src/core/metaops.pm
@@ -12,11 +12,41 @@ sub METAOP_REVERSE(\$op) {
}
sub METAOP_CROSS(\$op) {
- fail "X metaoperator NYI";
+ -> **@lol {
+ my $rop = METAOP_REDUCE($op);
+ my @l;
+ my @v;
+ @l[0] = (@lol[0].flat,).list;
+ my $i = 0;
+ my $n = @lol.elems - 1;
+ gather {
+ while $i >= 0 {
+ if @l[$i] {
+ @v[$i] = @l[$i].shift;
+ if $i >= $n { my @x = @v; take $rop(|@x); }
+ else {
+ $i++;
+ @l[$i] = (@lol[$i].flat,).list;
+ }
+ }
+ else { $i--; }
+ }
+ }
+ }
}
sub METAOP_ZIP(\$op) {
- fail "Z metaoperator NYI";
+ -> **@lol {
+ my $rop = METAOP_REDUCE($op);
+ my @l = @lol.map({ (.flat,).list.item });
+ gather {
+ my $loop = 1;
+ while $loop {
+ my @z = @l.map({ $loop = 0 unless $_; .shift });
+ take $rop(|@z) if $loop;
+ }
+ }
+ }
}
sub METAOP_REDUCE(\$op, :$triangle) {
View
1  tools/build/Makefile.in
@@ -145,6 +145,7 @@ CORE_SOURCES = \
src/core/MapIter.pm \
src/core/GatherIter.pm \
src/core/List.pm \
+ src/core/LoL.pm \
src/core/Array.pm \
src/core/Range.pm \
src/core/Enum.pm \
Please sign in to comment.
Something went wrong with that request. Please try again.