Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

autothread all or none before any or one. #113

Merged
merged 1 commit into from

2 participants

@timo
Collaborator

This branch makes 'all' and 'none' junctions in parameters autothread before 'one' and 'any' junctions even if they are farther to the right.

Fixes a nom regression in S03-junctions/misc.t and a todo test I put into S03-junctions/autothreading.t

It makes no other spectests fail.

@jnthn jnthn merged commit 77335dc into rakudo:nom
@timo timo deleted the unknown repository branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 11, 2013
  1. @timo
This page is out of date. Refresh to see the latest.
Showing with 34 additions and 12 deletions.
  1. +34 −12 src/core/Junction.pm
View
46 src/core/Junction.pm
@@ -67,26 +67,48 @@ sub infix:<&>(**@values) { Junction.new(@values, :type<all>); }
sub infix:<^>(**@values) { Junction.new(@values, :type<one>); }
sub AUTOTHREAD(&call, |args) {
- # Look for a junctional arg in the positionals.
my Mu $pos_rpa := nqp::getattr(nqp::p6decont(args), Capture, '$!list');
+ sub thread_junction(int $i) {
+ my Junction $arg := nqp::atpos($pos_rpa, $i);
+ my Str $type := nqp::getattr(nqp::p6decont($arg), Junction, '$!type');
+ my @states := nqp::getattr(nqp::p6decont($arg), Junction, '$!storage');
+
+ my Mu $res := nqp::list();
+ for @states -> $s {
+ # Next line is Officially Naughty, since captures are meant to be
+ # immutable. But hey, it's our capture to be naughty with...
+ nqp::bindpos($pos_rpa, $i, $s);
+ nqp::push($res, call(|args));
+ Nil;
+ }
+ return Junction.new(nqp::p6parcel($res, Nil), :type($type));
+ }
+
+ # Look for a junctional arg in the positionals.
+
+ # we have to autothread the first all or none junction before
+ # doing any one or any junctions.
+ my int $first_one_any = -1;
loop (my int $i = 0; $i < nqp::elems($pos_rpa); $i = $i + 1) {
# Junctional positional argument?
my Mu $arg := nqp::atpos($pos_rpa, $i);
if nqp::istype($arg, Junction) {
- my @states := nqp::getattr(nqp::p6decont($arg), Junction, '$!storage');
- my $type := nqp::getattr(nqp::p6decont($arg), Junction, '$!type');
- my Mu $res := nqp::list();
- for @states -> $s {
- # Next line is Officially Naughty, since captures are meant to be
- # immutable. But hey, it's our capture to be naughty with...
- nqp::bindpos($pos_rpa, $i, $s);
- nqp::push($res, call(|args));
- Nil;
+ my Str $type := nqp::getattr(nqp::p6decont($arg), Junction, '$!type');
+ if ($type eq "one" || $type eq "any") {
+ if $first_one_any == -1 {
+ # save it for later, first make sure we don't have all or none junctions later.
+ $first_one_any = $i;
+ }
+ } else {
+ return thread_junction($i);
}
- return Junction.new(nqp::p6parcel($res, Nil), :type($type));
}
}
-
+
+ if $first_one_any >= 0 {
+ return thread_junction($first_one_any);
+ }
+
# Otherwise, look for one in the nameds.
for args.hash.kv -> $k, $v {
if nqp::istype($v, Junction) {
Something went wrong with that request. Please try again.