From f6b45df3b315d44deff756f83d6e97a5de511788 Mon Sep 17 00:00:00 2001 From: Moritz Lenz Date: Thu, 3 Dec 2009 22:44:50 +0100 Subject: [PATCH] infix:, leg, <=> --- src/Perl6/Grammar.pm | 3 +++ src/cheats/relops.pir | 29 ----------------------------- src/core/Any-num.pm | 15 +++++++++++++++ src/core/Any-str.pm | 21 +++++++++++++++++++++ 4 files changed, 39 insertions(+), 29 deletions(-) diff --git a/src/Perl6/Grammar.pm b/src/Perl6/Grammar.pm index 8f3afe0b158..e0e7497dc41 100644 --- a/src/Perl6/Grammar.pm +++ b/src/Perl6/Grammar.pm @@ -1035,6 +1035,9 @@ token infix:sym<^..> { } token infix:sym<..^> { } token infix:sym<^..^> { } +token infix:sym { } +token infix:sym { } + token infix:sym { } token infix:sym { } diff --git a/src/cheats/relops.pir b/src/cheats/relops.pir index 53b75d4a78f..f40e1016347 100644 --- a/src/cheats/relops.pir +++ b/src/cheats/relops.pir @@ -65,25 +65,6 @@ src/cheats/cmp.pir - Perl6 comparison builtins # .tailcall '&prefix:?'($I0) .end - - -.sub '&infix:<<=>>' :multi(_,_) - .param pmc a - .param pmc b - $I0 = cmp_num a, b - if $I0 < 0 goto increase - if $I0 > 0 goto decrease - $P0 = get_hll_global ['Order'], 'Same' - .return ($P0) - increase: - $P0 = get_hll_global ['Order'], 'Increase' - .return ($P0) - decrease: - $P0 = get_hll_global ['Order'], 'Decrease' - .return ($P0) -.end - - .sub '&infix:' :multi(_,_) .param string a .param string b @@ -138,16 +119,6 @@ src/cheats/cmp.pir - Perl6 comparison builtins .end -.sub '&infix:' :multi(_,_) - .param pmc a - .param pmc b - $I0 = cmp a, b - ## Don't use a tailcall here due to RT#56448 - $P0 = '&infix:<<=>>'($I0, 0) - .return ($P0) -.end - - .sub '&infix:<===>' :multi(_,_) .param pmc a .param pmc b diff --git a/src/core/Any-num.pm b/src/core/Any-num.pm index 4de5eecac4d..182670d754d 100644 --- a/src/core/Any-num.pm +++ b/src/core/Any-num.pm @@ -395,4 +395,19 @@ our multi sub roots($x, $n) { $x.Complex.roots($n) } + +our multi sub infix:(Num $a, Num $b) { + # TODO: should be Order::Same, ::Increase, ::Decrease once they work + if $a == $b { + 0; + } else { + $a < $b ?? -1 !! 1; + } +} + +our multi sub infix:«<=>»(Num $a, Num $b) { + +$a cmp $b +} + + # vim: ft=perl6 diff --git a/src/core/Any-str.pm b/src/core/Any-str.pm index d07aad18cae..e3ab102fcbf 100644 --- a/src/core/Any-str.pm +++ b/src/core/Any-str.pm @@ -183,4 +183,25 @@ multi sub infix:($str, $n) { $n > 0 ?? ~(pir::repeat__SSI($str, $n)) !! '' } +our multi sub infix:($a, $b) { + if $a eq $b { + 0; + } else { + $a lt $b ?? -1 !! 1; + } +} + +our multi sub infix:($a, $b) { + ~$a cmp ~$b +} + +our multi sub infix:(Num $a, Num $b) { + if $a == $b { + 0; + } else { + $a < $b ?? -1 !! 1; + } +} + + # vim: ft=perl6