Skip to content

Commit

Permalink
Change prefix:<+> to dispatch to .Numeric for all types which descend…
Browse files Browse the repository at this point in the history
… from Mu. Define Mu.Numeric to return 0, Cool.Numeric to call the pir function to convert to a Num.

Still need to define Numeric.Numeric.
  • Loading branch information
colomon committed Apr 21, 2010
1 parent 483a9da commit 56120b7
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Perl6/Grammar.pm
Expand Up @@ -1603,7 +1603,7 @@ token postfix:sym«->» {

token infix:sym<**> { <sym> <O('%exponentiation')> }

token prefix:sym<+> { <sym> <O('%symbolic_unary, :pirop<set N*>')> }
token prefix:sym<+> { <sym> <O('%symbolic_unary')> }
token prefix:sym<~> { <sym> <O('%symbolic_unary')> }
token prefix:sym<-> { <sym> <![>]> <O('%symbolic_unary')> }
token prefix:sym<?> { <!before '???'> <sym> <O('%symbolic_unary')> }
Expand Down
10 changes: 10 additions & 0 deletions src/cheats/num-ops.pir
Expand Up @@ -34,3 +34,13 @@
.return ($I0)
.end

.sub '&prefix:<+>'
.param pmc x
$I0 = isa x, ['Mu']
if $I0 goto p6_x
$N0 = x
.return ($N0)
p6_x:
$P0 = x.'Numeric'()
.return ($P0)
.end
4 changes: 4 additions & 0 deletions src/core/Cool-num.pm
@@ -1,4 +1,8 @@
augment class Cool {
method Numeric() {
pir::set__NP(self);
}

method abs() {
(+self).abs;
}
Expand Down
4 changes: 4 additions & 0 deletions src/core/Mu.pm
@@ -1,6 +1,10 @@
augment class Mu {
method Bool { $.defined }

method Numeric { 0; } # Not sure if this makes sense or not
# but there are several tests it makes
# pass.

method item {
# This is overridden by non-items.
self;
Expand Down

0 comments on commit 56120b7

Please sign in to comment.