Skip to content

Commit

Permalink
When you pun a role, instances of the class should have a .WHAT that …
Browse files Browse the repository at this point in the history
…stringifies to the class name. This patch also attaches the parameters a role was instantiated with to the role.
  • Loading branch information
jnthn committed Apr 18, 2009
1 parent 341f449 commit cdd84c6
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/classes/Role.pir
Expand Up @@ -101,7 +101,8 @@ Selects a variant of the role to do based upon the supplied parameters.
.return (result)
it_loop_end:

# First time we've had these parameters, so need to instantiate them.
# First time we've had these parameters, so need to create the role
# taking them.
select_role:
.local pmc selector
selector = getattribute self, '$!selector'
Expand All @@ -110,6 +111,11 @@ Selects a variant of the role to do based upon the supplied parameters.
ins_hash["pos_args"] = pos_args
ins_hash["role"] = result
push created_list, ins_hash

# Also need to annotate that role with its parameters and the "factory"
# that generated it.
setprop result, "$!owner", self
setprop result, "@!type_args", pos_args
.return (result)
.end

Expand Down Expand Up @@ -245,6 +251,12 @@ Puns the role to a class and returns that class.
# I/someone has the energy for it.
'!compose_role_attributes'(metaclass, self)
proto = p6meta.'register'(metaclass, 'parent'=>'Any')
# Set name (don't use name=>... in register so we don't make a
# namespace entry though).
$P0 = self.'Str'()
$P1 = proto.'HOW'()
setattribute $P1, 'shortname', $P0
# Stash it away, then instantiate it.
setprop self, '$!pun', proto
Expand Down Expand Up @@ -288,8 +300,9 @@ Puns the role to a class and returns that class.
=cut
.sub 'Str' :method :vtable('get_string')
$P0 = getprop '$!shortname', self
.return ($P0)
$P0 = getprop '$!owner', self
$S0 = $P0
.return ($S0)
.end
=back
Expand Down

0 comments on commit cdd84c6

Please sign in to comment.