Skip to content

Commit

Permalink
Fix up type captures in signatures, which is one step on the way to g…
Browse files Browse the repository at this point in the history
…etting parametric roles working again.
  • Loading branch information
jnthn committed Jan 11, 2010
1 parent a4d72c7 commit 4639926
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
29 changes: 26 additions & 3 deletions src/Perl6/Actions.pm
Expand Up @@ -967,6 +967,8 @@ method param_var($/) {
}
else {
$*PARAMETER.var_name(~$/);
my @BlOCK;
@BLOCK[0].symbol(~$/, :scope('lexical'));
}
}

Expand All @@ -978,7 +980,10 @@ method named_param($/) {
method type_constraint($/) {
if $<typename> {
if pir::substr(~$<typename>, 0, 2) eq '::' {
$*PARAMETER.type_captures.push(pir::substr(~$<typename>, 2));
my $desigilname := pir::substr(~$<typename>, 2);
$*PARAMETER.type_captures.push($desigilname);
my @BlOCK;
@BLOCK[0].symbol($desigilname, :scope('lexical'));
}
else {
if $*PARAMETER.nom_type {
Expand Down Expand Up @@ -1212,7 +1217,13 @@ method term:sym<name>($/) {
my $ns := Perl6::Grammar::parse_name(~$<longname>);
$ns := pir::clone__PP($ns);
my $name := $ns.pop;
my $var := PAST::Var.new( :name(~$name), :namespace($ns), :scope('package') );
my $var;
if is_lexical(~$<longname>) {
$var := PAST::Var.new( :name(~$<longname>), :scope('lexical') );
}
else {
$var := PAST::Var.new( :name(~$name), :namespace($ns), :scope('package') );
}
my $past := $var;
if $<args> {
$past := $<args>.ast;
Expand Down Expand Up @@ -1595,7 +1606,7 @@ sub add_signature($block, $sig_obj, $lazy) {
my $decls := $sig_obj.get_declarations();
for @($decls) {
$_.isdecl(1);
$block.symbol( $_.name, :scope('lexical') )
$block.symbol( $_.name, :scope('lexical') );
}
$block[0].push($decls);
$block[0].push(PAST::Op.new(
Expand Down Expand Up @@ -1906,3 +1917,15 @@ sub make_attr_init_closure($init_value) {
my $lazy_name := add_signature($block, $sig, 1);
create_code_object(PAST::Op.new( :pirop('newclosure PP'), $block ), 'Method', 0, $lazy_name);
}

# Looks through the lexpads and sees if we recognize the symbol as a lexical.
sub is_lexical($name) {
our @BLOCK;
for @BLOCK {
my %entry := $_.symbol($name);
if %entry && %entry<scope> eq 'lexical' {
return 1;
}
}
return 0;
}
13 changes: 13 additions & 0 deletions src/Perl6/Compiler/Signature.pm
Expand Up @@ -117,6 +117,19 @@ method get_declarations() {
$result.push($var);
}

# If there are captured type variables, need variables for those too.
if $_.type_captures {
for @($_.type_captures) {
my $var := PAST::Var.new(
:name($_),
:scope('lexical'),
:viviself(Perl6::Actions::sigiltype('::'))
);
$var<sigil> := '::';
$result.push($var);
}
}

# Check any sub-signatures.
if pir::defined__IP($_.sub_signature) {
for @($_.sub_signature.get_declarations) {
Expand Down

0 comments on commit 4639926

Please sign in to comment.