Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Support SomeType(x) falling back to being a coercion call (x.SomeType…
…). If SomeType already overrides postcircumfix:<( )> then we call that directly, just as before.
  • Loading branch information
jnthn committed Feb 18, 2012
1 parent 1e966bb commit 76e282a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Perl6/Grammar.pm
Expand Up @@ -1864,7 +1864,7 @@ grammar Perl6::Grammar is HLL::Grammar {
token term:sym<!!!> { <sym> <args> }

token term:sym<identifier> {
<identifier> <?[(]> <args>
<identifier> <!{ $*W.is_type([~$<identifier>]) }> <?[(]> <args>
}

token term:sym<name> {
Expand Down
16 changes: 12 additions & 4 deletions src/Perl6/Metamodel/BOOTSTRAP.pm
Expand Up @@ -786,10 +786,18 @@ Perl6::Metamodel::ClassHOW.add_stash(ObjAt);
# to postcircumfix:<( )>.
my $invoke_forwarder :=
sub ($self, *@pos, *%named) {
my $c := nqp::create(Capture);
nqp::bindattr($c, Capture, '$!list', @pos);
nqp::bindattr($c, Capture, '$!hash', %named);
$self.postcircumfix:<( )>($c);
if !nqp::isconcrete($self) && !pir::can__IPs($self, 'postcircumfix:<( )>') {
my $coercer_name := $self.HOW.name($self);
+@pos == 1 ??
@pos[0]."$coercer_name"() !!
@pos # (should be marshalled to a Parcel by the binder...)
}
else {
my $c := nqp::create(Capture);
nqp::bindattr($c, Capture, '$!list', @pos);
nqp::bindattr($c, Capture, '$!hash', %named);
$self.postcircumfix:<( )>($c);
}
}
Perl6::Metamodel::ClassHOW.set_invoke_forwarder($invoke_forwarder);
Mu.HOW.add_parrot_vtable_mapping(Mu, 'invoke', $invoke_forwarder);
Expand Down
10 changes: 10 additions & 0 deletions src/Perl6/World.pm
Expand Up @@ -1604,6 +1604,16 @@ class Perl6::World is HLL::World {
$is_name
}

# Checks if a given symbol is declared and a type object.
method is_type(@name) {
my $is_name := 0;
try {
# This throws if it's not a known name.
$is_name := !nqp::isconcrete(self.find_symbol(@name))
}
$is_name
}

# Checks if a symbol has already been declared in the current
# scope, and thus may not be redeclared.
method already_declared($scope, $curpackage, $curpad, @name) {
Expand Down

0 comments on commit 76e282a

Please sign in to comment.