Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixes to make sure type variables can be seen inside the role body.
  • Loading branch information
jnthn committed Jul 9, 2011
1 parent 12e692c commit 8e8d803
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 24 deletions.
3 changes: 2 additions & 1 deletion src/Perl6/Grammar.pm
Expand Up @@ -179,7 +179,8 @@ grammar Perl6::Grammar is HLL::Grammar {
:my $*begin_compunit := 1; # whether we're at start of a compilation unit
:my $*DECLARAND; # the current thingy we're declaring, and subject of traits
:my $*METHODTYPE; # the current type of method we're in, if any

:my $*PKGDECL; # what type of package we're in, if any

# Extras.
:my %*METAOPGEN; # hash of generated metaops
:my $*IMPLICIT; # whether we allow an implicit param
Expand Down
53 changes: 30 additions & 23 deletions src/Perl6/SymbolTable.pm
Expand Up @@ -508,6 +508,7 @@ class Perl6::SymbolTable is HLL::Compiler::SerializationContextBuilder {

# Create code object now.
my $type_obj := self.find_symbol([$type]);
my $code_type := self.find_symbol(['Code']);
my $code := pir::repr_instance_of__PP($type_obj);
my $slot := self.add_object($code);

Expand All @@ -523,49 +524,55 @@ class Perl6::SymbolTable is HLL::Compiler::SerializationContextBuilder {
$precomp := self.compile_in_context($code_past);

# Fix up Code object associations (including nested blocks).
# We un-stub any code objects for already-compiled inner blocks
# to avoid wasting re-compiling them, and also to help make
# parametric role outer chain work out.
my $num_subs := nqp::elems($precomp);
my $i := 0;
while $i < $num_subs {
my $subid := $precomp[$i].get_subid();
if pir::exists(%!sub_id_to_code_object, $subid) {
pir::perl6_associate_sub_code_object__vPP($precomp[$i],
%!sub_id_to_code_object{$subid});
nqp::bindattr(%!sub_id_to_code_object{$subid}, $code_type, '$!do', $precomp[$i]);
}
$i := $i + 1;
}
}
$precomp(|@pos, |%named);
};
pir::set__vPS($stub, $code_past.name);
my $code_type := self.find_symbol(['Code']);
pir::setattribute__vPPsP($code, $code_type, '$!do', $stub);

# Fixup will install the real thing.
$fixups.push(PAST::Stmts.new(
self.set_attribute($code, $code_type, '$!do', PAST::Val.new( :value($code_past) )),
PAST::Op.new(
:pirop('perl6_associate_sub_code_object vPP'),
PAST::Val.new( :value($code_past) ),
self.get_object_sc_ref_past($code)
)));

# If we clone the stub, then we must remember to do a fixup
# of it also.
pir::setprop__vPsP($stub, 'CLONE_CALLBACK', sub ($orig, $clone) {
self.add_object($clone);
# Fixup will install the real thing, unless we're in a role, in
# which case pre-comp will have sorted it out.
unless $*PKGDECL eq 'role' {
$fixups.push(PAST::Stmts.new(
PAST::Op.new( :pasttype('bind'),
PAST::Var.new( :name('$P0'), :scope('register') ),
PAST::Op.new( :pirop('clone PP'), PAST::Val.new( :value($code_past) ) )
),
self.set_attribute($clone, $code_type, '$!do',
PAST::Var.new( :name('$P0'), :scope('register') )),
self.set_attribute($code, $code_type, '$!do', PAST::Val.new( :value($code_past) )),
PAST::Op.new(
:pirop('perl6_associate_sub_code_object vPP'),
PAST::Var.new( :name('$P0'), :scope('register') ),
self.get_object_sc_ref_past($clone)
PAST::Val.new( :value($code_past) ),
self.get_object_sc_ref_past($code)
)));
});

# If we clone the stub, then we must remember to do a fixup
# of it also.
pir::setprop__vPsP($stub, 'CLONE_CALLBACK', sub ($orig, $clone) {
self.add_object($clone);
$fixups.push(PAST::Stmts.new(
PAST::Op.new( :pasttype('bind'),
PAST::Var.new( :name('$P0'), :scope('register') ),
PAST::Op.new( :pirop('clone PP'), PAST::Val.new( :value($code_past) ) )
),
self.set_attribute($clone, $code_type, '$!do',
PAST::Var.new( :name('$P0'), :scope('register') )),
PAST::Op.new(
:pirop('perl6_associate_sub_code_object vPP'),
PAST::Var.new( :name('$P0'), :scope('register') ),
self.get_object_sc_ref_past($clone)
)));
});
}

# Desserialization should do the actual creation and just put the right
# code in there in the first place.
Expand Down

0 comments on commit 8e8d803

Please sign in to comment.