Skip to content
Permalink
Browse files

Fewer scalar containers for (.)

  • Loading branch information...
lizmat committed May 9, 2019
1 parent b559512 commit 25fe9b0be9a84920d9f18721187f03338c8f72fb
Showing with 33 additions and 33 deletions.
  1. +33 −33 src/core/set_multiply.pm6
@@ -3,63 +3,63 @@
# ⊍ set multiplication

proto sub infix:<(.)>(|) is pure {*}
multi sub infix:<(.)>() { bag() }
multi sub infix:<(.)>(Setty:D $a) { $a.Baggy }
multi sub infix:<(.)>(Baggy:D $a) { $a } # also Mixy
multi sub infix:<(.)>(Any $a) { $a.Bag }
multi sub infix:<(.)>() { bag() }
multi sub infix:<(.)>(Setty:D \a) { a.Baggy }
multi sub infix:<(.)>(Baggy:D \a) { a } # also Mixy
multi sub infix:<(.)>(Any \a) { a.Bag }

multi sub infix:<(.)>(Setty:D $a, Setty:D $b) {
multi sub infix:<(.)>(Setty:D \a, Setty:D \b) {
nqp::if(
(my $elems := $a.Bag.RAW-HASH) && nqp::elems($elems),
nqp::create($a.WHAT.Baggy).SET-SELF(
Rakudo::QuantHash.MULTIPLY-SET-TO-BAG($elems,$b.RAW-HASH),
(my $elems := a.Bag.RAW-HASH) && nqp::elems($elems),
nqp::create(a.WHAT.Baggy).SET-SELF(
Rakudo::QuantHash.MULTIPLY-SET-TO-BAG($elems,b.RAW-HASH),
),
$a.Baggy
a.Baggy
)
}

multi sub infix:<(.)>(Mixy:D $a, Mixy:D $b) {
multi sub infix:<(.)>(Mixy:D \a, Mixy:D \b) {
nqp::if(
(my $elems := Rakudo::QuantHash.BAGGY-CLONE-RAW($a.RAW-HASH))
(my $elems := Rakudo::QuantHash.BAGGY-CLONE-RAW(a.RAW-HASH))
&& nqp::elems($elems),
nqp::stmts(
Rakudo::QuantHash.MULTIPLY-MIX-TO-MIX($elems,$b.RAW-HASH),
nqp::create($a.WHAT).SET-SELF($elems)
Rakudo::QuantHash.MULTIPLY-MIX-TO-MIX($elems,b.RAW-HASH),
nqp::create(a.WHAT).SET-SELF($elems)
),
$a
a
)
}

multi sub infix:<(.)>(Mixy:D $a, Baggy:D $b) { infix:<(.)>($a, $b.Mix) }
multi sub infix:<(.)>(Mixy:D $a, Any $b) { infix:<(.)>($a, $b.Mix) }
multi sub infix:<(.)>(Setty:D $a, Mixy:D $b) { infix:<(.)>($a.Mixy, $b) }
multi sub infix:<(.)>(Baggy:D $a, Mixy:D $b) { infix:<(.)>($a.Mixy, $b) }
multi sub infix:<(.)>(Any $a, Mixy:D $b) { infix:<(.)>($a.Mix, $b) }
multi sub infix:<(.)>(Baggy:D $a, Baggy:D $b) {
multi sub infix:<(.)>(Mixy:D \a, Baggy:D \b) { infix:<(.)>(a, b.Mix) }
multi sub infix:<(.)>(Mixy:D \a, Any \b) { infix:<(.)>(a, b.Mix) }
multi sub infix:<(.)>(Setty:D \a, Mixy:D \b) { infix:<(.)>(a.Mixy, b) }
multi sub infix:<(.)>(Baggy:D \a, Mixy:D \b) { infix:<(.)>(a.Mixy, b) }
multi sub infix:<(.)>(Any \a, Mixy:D \b) { infix:<(.)>(a.Mix, b) }
multi sub infix:<(.)>(Baggy:D \a, Baggy:D \b) {
nqp::if(
(my $elems := Rakudo::QuantHash.BAGGY-CLONE-RAW($a.RAW-HASH))
(my $elems := Rakudo::QuantHash.BAGGY-CLONE-RAW(a.RAW-HASH))
&& nqp::elems($elems),
nqp::create($a.WHAT).SET-SELF(
Rakudo::QuantHash.MULTIPLY-BAG-TO-BAG($elems,$b.RAW-HASH),
nqp::create(a.WHAT).SET-SELF(
Rakudo::QuantHash.MULTIPLY-BAG-TO-BAG($elems,b.RAW-HASH),
),
$a
a
)
}

multi sub infix:<(.)>(Any $, Failure:D $b) { $b.throw }
multi sub infix:<(.)>(Failure:D $a, Any $) { $a.throw }
multi sub infix:<(.)>(Any $, Failure:D \b) { b.throw }
multi sub infix:<(.)>(Failure:D \a, Any $) { a.throw }

# Note that we cannot create a Setty|Baggy:D,Any candidate because that will
# result in an ambiguous dispatch, so we need to hack a check for Setty|Baggy
# in here.
multi sub infix:<(.)>(Any $a, Any $b) {
multi sub infix:<(.)>(Any \a, Any \b) {
infix:<(.)>(
nqp::isconcrete($a)
?? nqp::istype($a,Setty)
?? $a.Baggy
!! nqp::istype($a,Baggy) ?? $a !! $a.Bag
!! $a.Bag,
$b.Bag
nqp::isconcrete(a)
?? nqp::istype(a,Setty)
?? a.Baggy
!! nqp::istype(a,Baggy) ?? a !! a.Bag
!! a.Bag,
b.Bag
)
}

0 comments on commit 25fe9b0

Please sign in to comment.
You can’t perform that action at this time.