Skip to content

Commit

Permalink
Make the default parameter type of routines be Any, and the default t…
Browse files Browse the repository at this point in the history
…ype of pointy blocks and others be Object. Resolves RT#63920 and brings us in line with the spec.
  • Loading branch information
jnthn committed May 8, 2009
1 parent a579f31 commit f01d5d6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
19 changes: 17 additions & 2 deletions src/classes/Signature.pir
Expand Up @@ -36,7 +36,7 @@ Again, this probably isn't definitive either, but it'll get us going.
load_bytecode 'PCT.pbc'
.local pmc p6meta
p6meta = get_hll_global ['Perl6Object'], '$!P6META'
p6meta.'new_class'('Signature', 'parent'=>'Any', 'attr'=>'@!params')
p6meta.'new_class'('Signature', 'parent'=>'Any', 'attr'=>'@!params $!default_type')
.end
=head2 Methods
Expand Down Expand Up @@ -126,7 +126,9 @@ the Signature.
all_types = new 'ResizablePMCArray'
unless null type goto have_type
unless null role_type goto simple_role_type
type = get_hll_global 'Any'
type = getattribute self, '$!default_type'
unless null type goto done_role_type
type = get_hll_global 'Object'
goto done_role_type
simple_role_type:
type = role_type
Expand Down Expand Up @@ -155,6 +157,19 @@ the Signature.
.end
=item !set_default_param_type
Sets the default parameter type if none is supplied (since it differs for
blocks and routines).
=cut
.sub '!set_default_param_type' :method
.param pmc type
setattribute self, '$!default_type', type
.end
=item !add_implicit_self
Ensures that if there is no explicit invocant, we add one.
Expand Down
8 changes: 7 additions & 1 deletion src/parser/actions.pm
Expand Up @@ -773,6 +773,7 @@ method routine_def($/) {
}
$block.control(return_handler_past());
block_signature($block);
$block<default_param_type_node>.name('Any');

if $<trait> {
my $loadinit := $block.loadinit();
Expand Down Expand Up @@ -814,6 +815,7 @@ method method_def($/) {

$block.control(return_handler_past());
block_signature($block);
$block<default_param_type_node>.name('Any');
# Ensure there's an invocant in the signature.
$block.loadinit().push(PAST::Op.new(
:pasttype('callmethod'),
Expand Down Expand Up @@ -3007,10 +3009,14 @@ sub set_package_magical() {

sub block_signature($block) {
unless $block<signature> {
$block<default_param_type_node> := PAST::Var.new(
:scope('package'), :name('Object'), :namespace(list()) );
$block.loadinit().push(
PAST::Op.new( :inline(' .local pmc signature',
' signature = new ["Signature"]',
' setprop block, "$!signature", signature')
' setprop block, "$!signature", signature',
' signature."!set_default_param_type"(%0)'),
$block<default_param_type_node>
)
);
$block<signature> := 1;
Expand Down

0 comments on commit f01d5d6

Please sign in to comment.