Permalink
Browse files

much improved Mu:D.perl

  • Loading branch information...
moritz committed Oct 17, 2011
1 parent 16a3b95 commit 4e439068d4630debeebde60321caad3f4cd5642d
Showing with 22 additions and 1 deletion.
  1. +3 −0 src/core/Int.pm
  2. +10 −1 src/core/Mu.pm
  3. +9 −0 src/core/Num.pm
View
@@ -1,6 +1,9 @@
my class Rat { ... }
my class Int {
multi method perl(Int:D:) {
self.Str;
}
multi method Bool(Int:D:) {
nqp::p6bool(nqp::isne_i(nqp::unbox_i(self), 0))
}
View
@@ -148,8 +148,17 @@ my class Mu {
multi method gist(Mu:D:) { self.perl }
proto method perl(|$) { * }
multi method perl(Mu:D:) { self.Str }
multi method perl(Mu:U:) { self.HOW.name(self) }
multi method perl(Mu:D:) {
my @attrs;
for self.^attributes().grep: { .has_accessor } -> $attr {
my $name := $attr.Str.substr(2);
@attrs.push: $name
~ ' => '
~ self."$name"().perl
}
self.^name() ~ '.new(' ~ @attrs.join(', ') ~ ')';
}
proto method DUMP(|$) { * }
multi method DUMP(Mu:D:) { self.perl }
View
@@ -13,6 +13,15 @@ my class Num {
nqp::p6box_i(nqp::unbox_n(self));
}
multi method perl(Num:D:) {
my $res = self.Str;
if $res.index('e').defined {
$res;
} else {
$res ~ 'e0';
}
}
method Rat(Num:D: Real $epsilon = 1.0e-6) {
my sub modf($num) { my $q = $num.Int; $num - $q, $q; }

0 comments on commit 4e43906

Please sign in to comment.