Skip to content

Commit

Permalink
Bunch of fixes to get parametric roles just about working again.
Browse files Browse the repository at this point in the history
  • Loading branch information
jnthn committed Jan 12, 2010
1 parent 393c457 commit f9001fa
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 16 deletions.
4 changes: 3 additions & 1 deletion src/Perl6/Actions.pm
Expand Up @@ -569,12 +569,14 @@ method package_def($/, $key?) {
if $<def_module_name> {
my $name := ~$<def_module_name>[0]<longname>;
if $name ne '::' {
$package.name($name);
$/.CURSOR.add_name($name);
$package.name($name);
}
if $<def_module_name>[0]<signature> {
$package.signature($<def_module_name>[0]<signature>[0].ast);
$package.signature_text(~$<def_module_name>[0]<signature>[0]);
}

}

# Add traits.
Expand Down
11 changes: 10 additions & 1 deletion src/Perl6/Compiler/Role.pm
Expand Up @@ -3,12 +3,21 @@ class Perl6::Compiler::Role is Perl6::Compiler::Package;
# Holds the signautre for this parametric role, if any.
has $!signature;

# Textual representation of the signature, for constructing the long package name.
has $!signature_text;

# Accessor for signature.
method signature($signature?) {
if pir::defined__IP($signature) { $!signature := $signature }
$!signature
}

# Accessor for signature text.
method signature_text($signature_text?) {
if pir::defined__IP($signature_text) { $!signature_text := $signature_text }
pir::isnull__IP($!signature_text) ?? '' !! $!signature_text
}

# Do the code generation for the parametric role.
method finish($block) {
my $decl := PAST::Stmts.new();
Expand Down Expand Up @@ -119,7 +128,7 @@ method finish($block) {

# Set namespace and install in package, if our scoped.
if $!scope eq 'our' {
my @ns := Perl6::Grammar::parse_name($name);
my @ns := Perl6::Grammar::parse_name($name ~ '[' ~ self.signature_text ~ ']');
$block.namespace(@ns);
my @PACKAGE := Q:PIR { %r = get_hll_global ['Perl6'; 'Actions'], '@PACKAGE' };
@PACKAGE[0].block.loadinit().push(PAST::Op.new(
Expand Down
1 change: 0 additions & 1 deletion src/builtins/Role.pir
Expand Up @@ -24,7 +24,6 @@ short name for a particular set of parameters.
.local pmc p6meta, roleproto
p6meta = get_hll_global ['Mu'], '$!P6META'
roleproto = p6meta.'new_class'('Perl6Role', 'parent'=>'Any', 'name'=>'Role', 'attr'=>'$!selector $!created $!shortname')
p6meta.'register'('P6role', 'proto'=>'roleproto')
.end


Expand Down
1 change: 1 addition & 0 deletions src/cheats/parrot/P6role.pir
Expand Up @@ -172,6 +172,7 @@ XXX TODO: Needs a complete re-write for ng.
=cut

.sub 'HOW' :method
self = descalarref self
$P0 = getprop 'metaclass', self
.return ($P0)
.end
Expand Down
2 changes: 1 addition & 1 deletion src/core/traits.pm
Expand Up @@ -13,7 +13,7 @@ our multi trait_mod:<of>(ContainerDeclarand $cont, Mu \$type) {
}
}

our multi trait_mod:<does>(Mu $target, Role $r) {
our multi trait_mod:<does>(Mu $target, Mu $r) {
$target.add_composable($target, $r);
}

Expand Down
1 change: 1 addition & 0 deletions src/glue/role.pir
Expand Up @@ -19,6 +19,7 @@ Creates a master-role object, containing all the various role variants.
.sub '!create_master_role'
.param pmc shortname
.param pmc existing
if null existing goto need_new
$I0 = isa existing, 'Perl6Role'
unless $I0 goto need_new
.return (existing)
Expand Down
15 changes: 3 additions & 12 deletions src/metamodel/RoleHOW.pir
Expand Up @@ -39,18 +39,9 @@ Creates a new instance of the meta-class.

.sub 'new' :method
.param pmc name :optional
.local pmc how, p6role, nsarray, ns
if null name goto anon_role

# Named role - associate with Parrot namespace.
$P0 = get_hll_global [ 'Perl6';'Grammar' ], 'parse_name'
nsarray = $P0(name)
ns = get_hll_namespace nsarray
p6role = new ['P6role'], ns
goto have_p6role

# Anonymous class - just create a new Parrot class and we're done.
anon_role:
.local pmc how, p6role

# Create P6role object, which is what we will install in the namespace.
p6role = new ['P6role']

# Stash in metaclass instance, init a couple of other fields,
Expand Down

0 comments on commit f9001fa

Please sign in to comment.