Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Tweak some protos for better Junction failover.
We can make the proto itself be (Any, Any), meaning it fails to bind.
However, this also means that the multi-dispatcher never gets chance
to sneak an entry into the cache for the Junction case, so we have to
go through the slow-path binder to fail over every time, rather than
cheaply identifying we should hit the Junction dispatcher.
  • Loading branch information
jnthn committed Jul 27, 2014
1 parent 67a13da commit 9515bb7
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 38 deletions.
6 changes: 3 additions & 3 deletions src/core/Any.pm
Expand Up @@ -346,17 +346,17 @@ my class Any { # declared in BOOTSTRAP
Metamodel::ClassHOW.exclude_parent(Any);

# builtin ops
proto infix:<===>($?, $?) is pure { * }
proto infix:<===>(Mu $?, Mu $?) is pure { * }
multi infix:<===>($?) { Bool::True }
multi infix:<===>($a, $b) {
nqp::p6bool(nqp::iseq_s(nqp::unbox_s($a.WHICH), nqp::unbox_s($b.WHICH)))
}

proto infix:<before>($, $?) is pure { * }
proto infix:<before>(Mu $, Mu $?) is pure { * }
multi infix:<before>($?) { Bool::True }
multi infix:<before>(\a, \b) { (a cmp b) < 0 }

proto infix:<after>($, $?) is pure { * }
proto infix:<after>(Mu $, Mu $?) is pure { * }
multi infix:<after>($x?) { Bool::True }
multi infix:<after>(\a, \b) { (a cmp b) > 0 }

Expand Down
44 changes: 22 additions & 22 deletions src/core/Numeric.pm
Expand Up @@ -181,109 +181,109 @@ multi sub round($a) { $a.Numeric.round }
multi sub round(Numeric $a) { $a.round }
multi sub round(Numeric $a, $scale) { $a.round($scale) }

proto infix:<+>($?, $?) is pure { * }
proto infix:<+>(Mu $?, Mu $?) is pure { * }
multi infix:<+>($x = 0) { $x.Numeric }
multi infix:<+>(\a, \b) { a.Numeric + b.Numeric }

proto infix:<->($?, $?) is pure { * }
proto infix:<->(Mu $?, Mu $?) is pure { * }
multi infix:<->($x = 0) { $x.Numeric }
multi infix:<->(\a, \b) { a.Numeric - b.Numeric }

proto infix:<*>($?, $?) is pure { * }
proto infix:<*>(Mu $?, Mu $?) is pure { * }
multi infix:<*>($x = 1) { $x.Numeric }
multi infix:<*>(\a, \b) { a.Numeric * b.Numeric }

proto infix:</>($?, $?) { * }
proto infix:</>(Mu $?, Mu $?) { * }
multi infix:</>() { fail "No zero-arg meaning for infix:</>" }
multi infix:</>($x) { $x.Numeric }
multi infix:</>(\a, \b) { a.Numeric / b.Numeric }

proto infix:<div>($?, $?) is pure { * }
proto infix:<div>(Mu $?, Mu $?) is pure { * }
# rest of infix:<div> is in Int.pm

proto infix:<%>($?, $?) is pure { * }
proto infix:<%>(Mu $?, Mu $?) is pure { * }
multi infix:<%>() { fail "No zero-arg meaning for infix:<%>" }
multi infix:<%>($x) { $x }
multi infix:<%>(\a, \b) { a.Real % b.Real }

proto infix:<%%>($?, $?) is pure { * }
proto infix:<%%>(Mu $?, Mu $?) is pure { * }
multi infix:<%%>() { fail "No zero-arg meaning for infix:<%%>" }
multi infix:<%%>($) { Bool::True }
multi infix:<%%>(\a, \b) {
fail X::Numeric::DivideByZero.new(using => 'infix:<%%>') unless b;
a.Real % b.Real == 0;
}

proto infix:<lcm>($?, $?) is pure { * }
proto infix:<lcm>(Mu $?, Mu $?) is pure { * }
multi infix:<lcm>(Int $x = 1) { $x }
multi infix:<lcm>(\a, \b) { a.Int lcm b.Int }

proto infix:<gcd>($?, $?) is pure { * }
proto infix:<gcd>(Mu $?, Mu $?) is pure { * }
multi infix:<gcd>() { fail 'No zero-arg meaning for infix:<gcd>' }
multi infix:<gcd>(Int $x) { $x }
multi infix:<gcd>(\a, \b) { a.Int gcd b.Int }

proto infix:<**>($?, $?) is pure { * }
proto infix:<**>(Mu $?, Mu $?) is pure { * }
multi infix:<**>($x = 1) { $x.Numeric }
multi infix:<**>(\a, \b) { a.Numeric ** b.Numeric }

## relational operators

proto infix:«<=>»($, $?) is pure { * }
proto infix:«<=>»(Mu $, Mu $?) is pure { * }
multi infix:«<=>»(\a, \b) { a.Real <=> b.Real }

proto infix:<==>($?, $?) is pure { * }
proto infix:<==>(Mu $?, Mu $?) is pure { * }
multi infix:<==>($?) { Bool::True }
multi infix:<==>(\a, \b) { a.Numeric == b.Numeric }

proto infix:<!=>(Mu $?, Mu $?) is pure { * }
multi infix:<!=>($?) { Bool::True }
multi infix:<!=>(Mu \a, Mu \b) { not a == b }

proto infix:«<»($?, $?) is pure { * }
proto infix:«<»(Mu $?, Mu $?) is pure { * }
multi infix<»($?) { Bool::True }
multi infix<»(\a, \b) { a.Real < b.Real }

proto infix:«<=»($?, $?) is pure { * }
proto infix:«<=»(Mu $?, Mu $?) is pure { * }
multi infix<=»($?) { Bool::True }
multi infix<=»(\a, \b) { a.Real <= b.Real }

proto infix:«>»($?, $?) is pure { * }
proto infix:«>»(Mu $?, Mu $?) is pure { * }
multi infix>»($?) { Bool::True }
multi infix>»(\a, \b) { a.Real > b.Real }

proto infix:«>=»($?, $?) is pure { * }
proto infix:«>=»(Mu $?, Mu $?) is pure { * }
multi infix>=»($?) { Bool::True }
multi infix>=»(\a, \b) { a.Real >= b.Real }

## bitwise operators

proto infix:<+&>($?, $?) is pure { * }
proto infix:<+&>(Mu $?, Mu $?) is pure { * }
multi infix:<+&>() { +^0 }
multi infix:<+&>($x) { $x }
multi infix:<+&>($x, $y) { $x.Numeric.Int +& $y.Numeric.Int }

proto infix:<+|>($?, $?) is pure { * }
proto infix:<+|>(Mu $?, Mu $?) is pure { * }
multi infix:<+|>() { 0 }
multi infix:<+|>($x) { $x }
multi infix:<+|>($x, $y) { $x.Numeric.Int +| $y.Numeric.Int }

proto infix:<+^>($?, $?) is pure { * }
proto infix:<+^>(Mu $?, Mu $?) is pure { * }
multi infix:<+^>() { 0 }
multi infix:<+^>($x) { $x }
multi infix:<+^>($x, $y) { $x.Numeric.Int +^ $y.Numeric.Int }

proto infix:«+<»($?, $?) is pure { * }
proto infix:«+<»(Mu $?, Mu $?) is pure { * }
multi infix+<»() { fail "No zero-arg meaning for infix:«+<»"; }
multi infix+<»($x) { $x }
multi infix+<»($x,$y) { $x.Numeric.Int +< $y.Numeric.Int }

proto infix:«+>»($?, $?) is pure { * }
proto infix:«+>»(Mu $?, Mu $?) is pure { * }
multi infix+>»() { fail "No zero-arg meaning for infix:«+>»"; }
multi infix+>»($x) { $x }
multi infix+>»($x,$y) { $x.Numeric.Int +> $y.Numeric.Int }

proto prefix:<+^>($?, $?) is pure { * }
proto prefix:<+^>(Mu $?, Mu $?) is pure { * }
multi prefix:<+^>($x) { +^ $x.Numeric.Int }

# vim: ft=perl6 expandtab sw=4
2 changes: 1 addition & 1 deletion src/core/Order.pm
Expand Up @@ -8,7 +8,7 @@ sub ORDER(int $i) {
$i == 0 ?? Same !! $i < 0 ?? Less !! More
}

proto infix:<cmp>($, $) { * }
proto infix:<cmp>(Mu $, Mu $) { * }
multi infix:<cmp>(\a, \b) {
return Order::Less if a === -Inf || b === Inf;
return Order::More if a === Inf || b === -Inf;
Expand Down
24 changes: 12 additions & 12 deletions src/core/Stringy.pm
Expand Up @@ -7,56 +7,56 @@ multi sub infix:<eqv>(Stringy:D $a, Stringy:D $b) {
proto prefix:<~>($) is pure { * }
multi prefix:<~>(\a) { a.Stringy }

proto infix:<~>($?, $?) is pure { * }
proto infix:<~>(Mu $?, Mu $?) is pure { * }
multi infix:<~>($x = '') { $x.Stringy }
multi infix:<~>(\a, \b) { a.Stringy ~ b.Stringy }

proto infix:<x>($?, $?) { * }
proto infix:<x>(Mu $?, Mu $?) { * }
multi infix:<x>() { fail "No zero-arg meaning for infix:<x>" }
multi infix:<x>($x) { $x.Stringy }
multi infix:<x>($s, $n) { $s.Stringy x ($n.Int // 0) }

proto infix:<leg>($?, $?) is pure { * }
proto infix:<leg>(Mu $?, Mu $?) is pure { * }
multi infix:<leg>(\a, \b) { a.Stringy cmp b.Stringy }

proto infix:<eq>($?, $?) is pure { * }
proto infix:<eq>(Mu $?, Mu $?) is pure { * }
multi infix:<eq>($x?) { Bool::True }
multi infix:<eq>(\a, \b) { a.Stringy eq b.Stringy }

proto infix:<ne>(Mu $?, Mu $?) is pure { * }
multi infix:<ne>($x?) { Bool::True }
multi infix:<ne>(Mu \a, Mu \b) { a !eq b }

proto infix:<lt>($?, $?) is pure { * }
proto infix:<lt>(Mu $?, Mu $?) is pure { * }
multi infix:<lt>($x?) { Bool::True }
multi infix:<lt>(\a, \b) { a.Stringy lt b.Stringy }

proto infix:<le>($?, $?) is pure { * }
proto infix:<le>(Mu $?, Mu $?) is pure { * }
multi infix:<le>($x?) { Bool::True }
multi infix:<le>(\a, \b) { a.Stringy le b.Stringy }

proto infix:<gt>($?, $?) is pure { * }
proto infix:<gt>(Mu $?, Mu $?) is pure { * }
multi infix:<gt>($x?) { Bool::True }
multi infix:<gt>(\a, \b) { a.Stringy gt b.Stringy }

proto infix:<ge>($?, $?) is pure { * }
proto infix:<ge>(Mu $?, Mu $?) is pure { * }
multi infix:<ge>($x?) { Bool::True }
multi infix:<ge>(\a, \b) { a.Stringy ge b.Stringy }

proto infix:<~|>($?, $?) is pure { * }
proto infix:<~|>(Mu $?, Mu $?) is pure { * }
multi infix:<~|>($x = '') { $x.Stringy }
multi infix:<~|>(\a, \b) { a.Stringy ~| b.Stringy }

proto infix:<~^>($?, $?) is pure { * }
proto infix:<~^>(Mu $?, Mu $?) is pure { * }
multi infix:<~^>($x = '') { $x.Stringy }
multi infix:<~^>(\a, \b) { a.Stringy ~^ b.Stringy }

proto infix:<~&>($?, $?) is pure { * }
proto infix:<~&>(Mu $?, Mu $?) is pure { * }
multi infix:<~&>() { fail "No zero-arg meaning for infix:<~&>" }
multi infix:<~&>($x) { $x.Stringy }
multi infix:<~&>(\a, \b) { a.Stringy ~& b.Stringy }

proto prefix:<~^>($?, $?) is pure { * }
proto prefix:<~^>(Mu $?, Mu $?) is pure { * }
multi prefix:<~^>(\a) { ~^ a.Stringy }

# vim: ft=perl6 expandtab sw=4

0 comments on commit 9515bb7

Please sign in to comment.