5
src/parrot/P6role.pir - methods for the our P6role class
7
=head2 Methods on P6role
9
We also add some methods to P6role.
13
Puns the role to a class and returns that class.
19
self = descalarref self
21
# See if we have already created a punned class; use it if so.
23
pun = getprop '$!pun', self
24
if null pun goto make_pun
28
# Otherwise, need to create a punned class; set a $*SCOPE that is not
29
# 'our' just to ensure that we don't try and associate with a Parrot
33
.local pmc ClassHOW, temp, meta, proto
34
ClassHOW = get_root_global ['perl6'], 'ClassHOW'
35
$P1 = getprop '$!owner', self
36
$P1 = getattribute $P1, '$!shortname'
37
temp = ClassHOW.'new'($P1)
39
meta.'add_composable'(temp, self)
40
proto = meta.'compose'(temp)
42
# Stash it away, and return it.
43
setprop self, '$!pun', proto
52
.sub 'ACCEPTS' :method
55
# First, check if this role is directly done by the topic.
56
$I0 = does topic, self
59
# Otherwise, need to consider subtypes in the parameters.
60
.local pmc all_variants, it, want_rf, our_types, cur_variant
61
self = descalarref self
62
$P0 = getprop '$!owner', self
63
all_variants = getattribute $P0, '$!created'
64
want_rf = getprop '$!orig_role', self
65
our_types = getprop '@!type_args', self
66
it = iter all_variants
68
unless it goto it_loop_end
69
cur_variant = shift it
71
# We can exclude a variant if it wasn't from the same role factory.
72
$P0 = cur_variant['role']
73
$P1 = getprop '$!orig_role', $P0
74
eq_addr $P1, want_rf, same_variant
78
# Also we can exclude it if our topic doens't do it.
80
unless $I0 goto it_loop
82
# If it's from the same variant, check all types of the role we're
83
# considering here are broader-or-equal types.
84
.local pmc check_types
85
check_types = cur_variant['pos_args']
86
$I0 = elements check_types
87
$I1 = elements our_types
88
if $I0 != $I1 goto it_loop
91
if $I0 >= $I1 goto type_loop_end
93
$P1 = check_types[$I0]
94
$I2 = $P0.'ACCEPTS'($P1)
95
unless $I2 goto it_loop
100
# If we get here, we found a role that through the subtypes of its
101
# parameters is applicable.
106
# If we get here, no applicable roles.
115
Role objects serve as type objects and thus should be undefined.
119
.sub 'defined' :method
120
$P0 = get_root_global ['perl6';'Bool'], 'False'
131
self = descalarref self
132
$P0 = getprop '$!owner', self
133
$P0 = getattribute $P0, '$!shortname'
135
$S0 = concat $S0, '['
136
args = getprop '@!type_args', self
139
unless it goto it_loop_end
142
$S0 = concat $S0, $S1
145
$S0 = concat $S0, ']'
154
.sub 'HOW' :method :nsentry
155
self = descalarref self
156
$P0 = getprop 'metaclass', self
176
self = descalarref self
181
=item Str (vtable get_string)
185
.sub 'Str' :method :vtable('get_string')
186
self = descalarref self
187
$P0 = getprop '$!owner', self
193
=item postcircumfix:<[ ]>
197
.sub 'postcircumfix:<[ ]>' :method
209
# vim: expandtab shiftwidth=4 ft=pir: