Skip to content

Commit

Permalink
infix:<cmp>, leg, <=>
Browse files Browse the repository at this point in the history
  • Loading branch information
moritz committed Dec 3, 2009
1 parent 69ce77b commit f6b45df
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 29 deletions.
3 changes: 3 additions & 0 deletions src/Perl6/Grammar.pm
Expand Up @@ -1035,6 +1035,9 @@ token infix:sym<^..> { <sym> <O('%structural')> }
token infix:sym<..^> { <sym> <O('%structural')> }
token infix:sym<^..^> { <sym> <O('%structural')> }

token infix:sym<leg> { <sym> <O('%structural')> }
token infix:sym<cmp> { <sym> <O('%structural')> }

token infix:sym<but> { <sym> <O('%structural')> }
token infix:sym<does> { <sym> <O('%structural')> }

Expand Down
29 changes: 0 additions & 29 deletions src/cheats/relops.pir
Expand Up @@ -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:<eq>' :multi(_,_)
.param string a
.param string b
Expand Down Expand Up @@ -138,16 +119,6 @@ src/cheats/cmp.pir - Perl6 comparison builtins
.end


.sub '&infix:<cmp>' :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
Expand Down
15 changes: 15 additions & 0 deletions src/core/Any-num.pm
Expand Up @@ -395,4 +395,19 @@ our multi sub roots($x, $n) {
$x.Complex.roots($n)
}


our multi sub infix:<cmp>(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
21 changes: 21 additions & 0 deletions src/core/Any-str.pm
Expand Up @@ -183,4 +183,25 @@ multi sub infix:<x>($str, $n) {
$n > 0 ?? ~(pir::repeat__SSI($str, $n)) !! ''
}

our multi sub infix:<cmp>($a, $b) {
if $a eq $b {
0;
} else {
$a lt $b ?? -1 !! 1;
}
}

our multi sub infix:<leg>($a, $b) {
~$a cmp ~$b
}

our multi sub infix:<cmp>(Num $a, Num $b) {
if $a == $b {
0;
} else {
$a < $b ?? -1 !! 1;
}
}


# vim: ft=perl6

0 comments on commit f6b45df

Please sign in to comment.