Skip to content

Commit

Permalink
Turn new into a multi. Add a candidate that dies if you try to give p…
Browse files Browse the repository at this point in the history
…ositional arguments. Update bless so it can take * as an initial parameter and create a candidate; inline this rather than calling .CREATE and use it in .new, thus saving a method invocation per .new call.
  • Loading branch information
jnthn committed Jul 4, 2011
1 parent dff16a7 commit 362947a
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/core/Mu.pm
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,25 @@ my class Mu {
nqp::p6bool(pir::repr_defined__IP(self))
}

method new(*%attrinit) {
self.bless(self.CREATE(), |%attrinit);
proto method new(|$) { * }
multi method new(*%attrinit) {
self.bless(*, |%attrinit);
}
multi method new($, *@) {
die "Default constructor only takes named arguments";
}

method CREATE() {
nqp::create(self)
}

method bless(Mu \$candidate, *%attrinit) {
$candidate
method bless(Mu \$candidate, *@autovivs, *%attrinit) {
# If we were passed *, then need to create a candidate.
my $cand := nqp::istype($candidate, Whatever) ??
nqp::create(self) !!
$candidate;

$cand
}

proto method Numeric(|$) { * }
Expand Down

0 comments on commit 362947a

Please sign in to comment.