Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix up the signature generator to be handling multiple names for a na…
…med arguments. Start storing type capture names in the signature object. Fix signature generation for named slurpy parameters.
  • Loading branch information
jnthn committed Oct 9, 2009
1 parent 03f82dd commit 837cd09
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/builtins/control.pir
Expand Up @@ -613,6 +613,7 @@ of a hack.
push pos_args, $P0
goto param_loop
named:
names = names[0]
named_args[names] = $P0
goto param_loop
param_done:
Expand Down
2 changes: 1 addition & 1 deletion src/classes/Signature.pir
Expand Up @@ -75,7 +75,7 @@ Returns a C<List> of C<Parameter> descriptors.
named = 0
if null names goto no_names
named = 1
names = 'list'(names)
names = 'list'(names :flat)
goto names_done
no_names:
names = 'list'()
Expand Down
3 changes: 2 additions & 1 deletion src/parser/actions.pm
Expand Up @@ -1056,7 +1056,8 @@ method signature($/, $key) {
:invocant( $invocant ),
:multi_invocant( $multi_inv_suppress ?? 0 !! 1 ),
:nom_type( $var<nom_type> ),
:cons_type( $var<cons_type> )
:cons_type( $var<cons_type> ),
:type_captures( $var<type_binding> ?? list($var<type_binding>.name()) !! list() )
);

## handle end of multi-invocant sequence
Expand Down
21 changes: 17 additions & 4 deletions src/parser/signature.pm
Expand Up @@ -167,18 +167,31 @@ method ast($high_level?) {
$_<cons_type> := $_<cons_type>[0];
}

# Names and type capture lists needs to build a ResizablePMCArray.
my $names := $null_reg;
if !$_<slurpy> && $_<names> && +@($_<names>) {
my $pir := " %r = root_new ['parrot'; 'ResizablePMCArray']\n";
for @($_<names>) { $pir := $pir ~ " push %r, '" ~ ~$_ ~ "'\n"; }
$names := PAST::Op.new( :inline($pir) );
}
my $type_captures := $null_reg;
if $_<type_captures> && +@($_<type_captures>) {
my $pir := " %r = root_new ['parrot'; 'ResizablePMCArray']\n";
for @($_<type_captures>) { $pir := $pir ~ " push %r, '" ~ ~$_ ~ "'\n"; }
$type_captures := PAST::Op.new( :inline($pir) );
}

# Emit op to build signature element.
# XXX Fix nameds to handle multiple names for an argument.
$ast.push(PAST::Op.new(
:pirop('set_signature_elem vPisiPPPP'),
PAST::Var.new( :name('signature'), :scope('register') ),
$i,
~$_<var_name>,
$flags,
$_<nom_type>,
($_<cons_type> ?? $_<cons_type> !! $null_reg),
(+@($_<names>) && !$_<slurpy> ?? $_<names>[0] !! $null_reg),
$null_reg
($_<cons_type> ?? $_<cons_type> !! $null_reg),
$names,
$type_captures
));
$i := $i + 1;
}
Expand Down

0 comments on commit 837cd09

Please sign in to comment.